Skip to content

Commit

Permalink
reFactroring Group Module Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit authored and ankit committed Mar 8, 2017
1 parent 4e1c13c commit 8556a08
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions Slack.Automation/Promact.Erp.Web/Promact.Erp.Web.csproj
Expand Up @@ -1249,6 +1249,7 @@
<TypeScriptCompile Include="app\shared\MailSetting\mailsetting.service.ts" />
<TypeScriptCompile Include="app\shared\MailSetting\mailsettingAC.model.ts" />
<TypeScriptCompile Include="app\shared\MailSetting\project.model.ts" />
<TypeScriptCompile Include="app\shared\mock\mock.error.model.ts" />
<TypeScriptCompile Include="app\shared\mock\mock.activatedroute.ts" />
<TypeScriptCompile Include="app\shared\mock\mock.appcomponent.service.ts" />
<TypeScriptCompile Include="app\shared\emailHashCode.ts" />
Expand Down
Expand Up @@ -17,7 +17,7 @@ export class GroupAddComponent implements OnInit {

constructor(private router: Router, private stringConstant: StringConstant, private loader: LoaderService, private groupService: GroupService, private toast: Md2Toast) {
this.groupModel = new GroupModel();
this.validPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
this.validPattern = this.stringConstant.emailValidPattern;
this.isExistsGroupName = false;
}

Expand Down
Expand Up @@ -52,11 +52,10 @@ describe('Group Edit Component Test', () => {
it("ng OnInit Error", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupEditComponent);
let activatedRoute = fixture.debugElement.injector.get(ActivatedRoute);
activatedRoute.testParams = { id: stringConstant.id };
let toast = fixture.debugElement.injector.get(Md2Toast);
activatedRoute.testParams = { id: 2 };
let groupEditComponent = fixture.componentInstance;
let name = stringConstant.groupName;
let groupService = fixture.debugElement.injector.get(GroupService);
spyOn(groupService, "getGroupbyId").and.returnValue(Promise.reject(""));
groupEditComponent.ngOnInit();
tick();
expect(name).toBe(stringConstant.groupName);
Expand Down
Expand Up @@ -17,7 +17,7 @@ export class GroupEditComponent implements OnInit {
listOfActiveEmail: Array<string>;

constructor(private router: Router, private route: ActivatedRoute, private stringConstant: StringConstant, private loader: LoaderService, private groupService: GroupService, private toast: Md2Toast) {
this.validPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
this.validPattern = this.stringConstant.emailValidPattern;
this.groupModel = new GroupModel();
this.isExistsGroupName = false;
}
Expand All @@ -31,6 +31,10 @@ export class GroupEditComponent implements OnInit {
this.groupModel = result
this.loader.loader = false;
}, err => {
if (err.status === 400) {
this.toast.show('Group not found.');
}
this.loader.loader = false;
});
});
}
Expand All @@ -49,7 +53,6 @@ export class GroupEditComponent implements OnInit {
this.backToGroupList();
this.toast.show('Group updated successfully. ');
this.loader.loader = false;

}, err => {
});
}
Expand Down
Expand Up @@ -51,11 +51,10 @@ describe('Group List Component Test', () => {
let fixture = TestBed.createComponent(GroupListComponent); //Create instance of component
let groupListComponent = fixture.componentInstance;
let groupService = fixture.debugElement.injector.get(GroupService);
let name = stringConstant.groupName;
spyOn(groupService, "getListOfGroup").and.returnValue(Promise.reject(""));
groupListComponent.ngOnInit();
tick();
expect(name).toBe(stringConstant.groupName);
expect(groupListComponent.groupList).not.toBeNull();
}));

it("add New", () => {
Expand Down Expand Up @@ -87,22 +86,24 @@ describe('Group List Component Test', () => {

}));

it("delete Group", () => {
it("delete Group", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupListComponent); //Create instance of component
let groupListComponent = fixture.componentInstance;
let popup = fixture.debugElement.injector.get(Md2Dialog);
groupListComponent.deleteGroup(popup);
expect(groupListComponent.groupList).toEqual(undefined);
});
tick();
expect(groupListComponent.groupList).not.toBeNull();
}));

it("delete Group", () => {
it("delete Group Error", () => {
let fixture = TestBed.createComponent(GroupListComponent); //Create instance of component
let groupListComponent = fixture.componentInstance;
let popup = fixture.debugElement.injector.get(Md2Dialog);
let groupService = fixture.debugElement.injector.get(GroupService);
let groupName = stringConstant.groupName;
spyOn(groupService, "deleteGroupById").and.returnValue(Promise.reject(""));
groupListComponent.deleteGroup(popup);
expect(groupListComponent.groupList).toEqual(undefined);
expect(stringConstant.groupName).toEqual(groupName);
});

it("closeDelete Popup", () => {
Expand Down
@@ -0,0 +1,5 @@
export class ErrorModel {
status: number;
errorMessage: string;
statusText: string;
}
Expand Up @@ -2,6 +2,7 @@
import { ResponseOptions, Response } from "@angular/http";
import { GroupModel } from '../../Group/group.model';
import { StringConstant } from '../../shared/stringConstant';
import { ErrorModel } from "../../shared/mock/mock.error.model";

let stringConstant = new StringConstant();

Expand Down Expand Up @@ -41,8 +42,12 @@ export class MockGroupService {
mockGroup.Emails = emails;
mockGroup.Name = stringConstant.testGroupName;
mockGroup.Type = 2;
return Promise.resolve(mockGroup);
}
else {
let error = new MockError(404);
return Promise.reject(error);
}
return Promise.resolve(mockGroup);
}

/*This service used for update group*
Expand Down Expand Up @@ -70,6 +75,7 @@ export class MockGroupService {
* @param id
*/
deleteGroupById(id: number) {

return Promise.resolve(true);
}

Expand All @@ -88,4 +94,12 @@ class MockGroup extends GroupModel {
this.Id = id;
}

}

class MockError extends ErrorModel {

constructor(status: number) {
super();
this.status = status;
}
}
Expand Up @@ -73,7 +73,7 @@ export class StringConstant {
leaveDate = "1/1/16";
module = "module";
scrumName = "scrumName";

groupUrl = "api/group";
staticGroup = "StaticGroup";
groupName = "name";
Expand All @@ -89,4 +89,5 @@ export class StringConstant {
getProjectByIdAndModule = "getProjectByIdAndModule";
testGroupList = ["hello"];
Date = 'date';
emailValidPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
}

0 comments on commit 8556a08

Please sign in to comment.