profile-home.component.spec.ts
2.45 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
import {quickCreateComponent} from "../../spec/helpers";
import {ProfileHomeComponent} from "./profile-home.component";
describe("Components", () => {
describe("Profile Home Component", () => {
let $rootScope: ng.IRootScopeService;
let $q: ng.IQService;
let homePageResponse: ng.IDeferred<any>;
let profileServiceMock: any;
let $state: any;
beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
$rootScope = _$rootScope_;
$q = _$q_;
}));
beforeEach(() => {
$state = jasmine.createSpyObj("$state", ["transitionTo"]);
profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile", "getHomePage"]);
let currentProfileResponse = $q.defer();
currentProfileResponse.resolve({ identifier: "profile" });
homePageResponse = $q.defer();
profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(currentProfileResponse.promise);
profileServiceMock.getHomePage = jasmine.createSpy("getHomePage").and.returnValue(homePageResponse.promise);
});
it("transition to profile homepage when there is a homepage setted", done => {
homePageResponse.resolve({ data: { article: { path: "something" } } });
let component: ProfileHomeComponent = new ProfileHomeComponent(profileServiceMock, $state);
$rootScope.$apply();
expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
expect(profileServiceMock.getHomePage).toHaveBeenCalled();
expect($state.transitionTo).
toHaveBeenCalledWith("main.profile.page",
{ page: "something", profile: "profile" }, { location: false });
done();
});
it("transition to profile info page when there is no homepage setted", done => {
homePageResponse.resolve({ data: {} });
let component: ProfileHomeComponent = new ProfileHomeComponent(profileServiceMock, $state);
$rootScope.$apply();
expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
expect(profileServiceMock.getHomePage).toHaveBeenCalled();
expect($state.transitionTo).
toHaveBeenCalledWith("main.profile.info",
{ profile: "profile" }, { location: false });
done();
});
});
});