profile.component.spec.ts
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {quickCreateComponent} from "../../spec/helpers";
import {ProfileComponent} from "./profile.component";
describe("Components", () => {
describe("Profile Component", () => {
let $rootScope: ng.IRootScopeService;
let $q: ng.IQService;
let profileServiceMock: any;
let notificationMock: any;
let $stateParams: any;
let $state: any;
beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
$rootScope = _$rootScope_;
$q = _$q_;
}));
beforeEach(() => {
$state = jasmine.createSpyObj("$state", ["transitionTo"]);
$stateParams = jasmine.createSpyObj("$stateParams", ["profile"]);
profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["setCurrentProfileByIdentifier", "getBoxes"]);
notificationMock = jasmine.createSpyObj("notificationMock", ["error"]);
let profileResponse = $q.defer();
profileResponse.resolve({ id: 1 });
let getBoxesResponse = $q.defer();
getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } });
profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise);
profileServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise);
});
it("get the profile and store in profile service", done => {
let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled();
expect(component.profile).toEqual({ id: 1 });
done();
});
it("get the profile boxes", done => {
let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.getBoxes).toHaveBeenCalled();
expect(component.boxes).toEqual([{ id: 2 }]);
done();
});
it("display notification error when the profile wasn't found", done => {
let profileResponse = $q.defer();
profileResponse.reject();
profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise);
let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled();
expect(notificationMock.error).toHaveBeenCalled();
expect(component.profile).toBeUndefined();
done();
});
});
});