Commit ad92917af77a3937a520d6638e79913b12315d77
1 parent
96006ac8
Exists in
master
and in
34 other branches
New navbars tests
Showing
1 changed file
with
81 additions
and
47 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
... | ... | @@ -18,54 +18,55 @@ import { |
18 | 18 | provide |
19 | 19 | } from "ng-forward"; |
20 | 20 | |
21 | +import {Session, AuthService, AuthController, IAuthEvents} from "./../auth"; | |
21 | 22 | |
22 | 23 | describe("Components", () => { |
23 | 24 | |
24 | - | |
25 | 25 | describe("Navbar Component", () => { |
26 | 26 | |
27 | - let $rootScope: ng.IRootScopeService; | |
28 | - let user = <User>{ | |
29 | - id: 1, | |
30 | - login: "user" | |
31 | - }; | |
32 | - | |
27 | + let $rootScope: ng.IRootScopeService; | |
28 | + | |
29 | + let user = <User>{ | |
30 | + id: 1, | |
31 | + login: "user" | |
32 | + }; | |
33 | + | |
34 | + let scope = { | |
35 | + eventCalledHook: () => { }, | |
36 | + $on: (eventName: string, func: Function) => { | |
37 | + this.eventCalledHook = func; | |
38 | + } | |
39 | + } | |
33 | 40 | |
34 | - let scope = { | |
35 | - eventCalledHook: () => { }, | |
36 | - $on: (eventName: string, func: Function) => { | |
37 | - this.eventCalledHook = func; | |
41 | + let modalInstance = { | |
42 | + close: () => { } | |
38 | 43 | } |
39 | - } | |
40 | 44 | |
41 | - let modalInstance = { | |
42 | - close: () => { } | |
43 | - } | |
45 | + let $modal = { | |
46 | + open: (args: {}) => { | |
47 | + return modalInstance; | |
48 | + } | |
49 | + } | |
44 | 50 | |
45 | - let $modal = { | |
46 | - open: (args: {}) => { | |
47 | - return modalInstance; | |
51 | + let authService = { | |
52 | + logout: () => { } | |
48 | 53 | } |
49 | - } | |
50 | - | |
51 | - let authService = { | |
52 | - logout: () => { } | |
53 | - } | |
54 | - | |
55 | - let stateService = jasmine.createSpyObj("$state", ["go"]); | |
56 | - let providers = [ | |
57 | - new Provider('moment', { useValue: {} }), | |
58 | - new Provider('$modal', { useValue: $modal }), | |
59 | - new Provider('AuthService', { useValue: authService }), | |
60 | - new Provider('Session', { | |
61 | - useValue: { | |
62 | - currentUser: () => { return user } | |
63 | - } | |
64 | - }), | |
65 | - new Provider('$scope', { useValue: scope }), | |
66 | - new Provider('$state', { useValue: stateService }), | |
67 | - new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
68 | - ]; | |
54 | + | |
55 | + let stateService = jasmine.createSpyObj("$state", ["go"]); | |
56 | + let providers = [ | |
57 | + new Provider('moment', { useValue: {} }), | |
58 | + new Provider('$modal', { useValue: $modal }), | |
59 | + new Provider('AuthService', { useValue: authService }), | |
60 | + new Provider('Session', { | |
61 | + useValue: { | |
62 | + currentUser: () => { return user } | |
63 | + } | |
64 | + }), | |
65 | + new Provider('$scope', { useValue: scope }), | |
66 | + new Provider('$state', { useValue: stateService }), | |
67 | + new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
68 | + ]; | |
69 | + | |
69 | 70 | |
70 | 71 | beforeEach(angular.mock.module("templates")); |
71 | 72 | |
... | ... | @@ -76,7 +77,6 @@ describe("Components", () => { |
76 | 77 | it('should get the loggedIn user', (done: Function) => { |
77 | 78 | |
78 | 79 | let scope = jasmine.createSpyObj("scope", ["$on"]); |
79 | - | |
80 | 80 | let providers = [ |
81 | 81 | provideEmptyObjects('moment', '$modal', 'AuthService', '$state'), |
82 | 82 | new Provider('Session', { |
... | ... | @@ -108,7 +108,8 @@ describe("Components", () => { |
108 | 108 | }); |
109 | 109 | }); |
110 | 110 | |
111 | - it('It should open on click', (done: Function) => { | |
111 | + it('should open on click', (done: Function) => { | |
112 | + | |
112 | 113 | quickCreateComponent({ |
113 | 114 | providers: providers, |
114 | 115 | template: "<acme-navbar></acme-navbar>", |
... | ... | @@ -119,17 +120,18 @@ describe("Components", () => { |
119 | 120 | spyOn($modal, "open"); |
120 | 121 | navbarComp.openLogin(); |
121 | 122 | expect($modal.open).toHaveBeenCalled(); |
122 | - // expect($modal.open).toHaveBeenCalledWith({ | |
123 | - // templateUrl: 'app/components/auth/login.html', | |
124 | - // controller: 'AuthController', | |
125 | - // controllerAs: 'vm', | |
126 | - // bindToController: true | |
127 | - // }) | |
123 | + expect($modal.open).toHaveBeenCalledWith({ | |
124 | + templateUrl: 'app/components/auth/login.html', | |
125 | + controller: AuthController, | |
126 | + controllerAs: 'vm', | |
127 | + bindToController: true | |
128 | + }) | |
128 | 129 | done(); |
129 | 130 | }) |
130 | 131 | }); |
131 | 132 | |
132 | - it('It should logout', (done: Function) => { | |
133 | + it('should logout', (done: Function) => { | |
134 | + | |
133 | 135 | quickCreateComponent({ |
134 | 136 | providers: providers, |
135 | 137 | template: "<acme-navbar></acme-navbar>", |
... | ... | @@ -145,6 +147,38 @@ describe("Components", () => { |
145 | 147 | }); |
146 | 148 | |
147 | 149 | |
150 | + it('should not activate user when logged in', (done: Function) => { | |
151 | + quickCreateComponent({ | |
152 | + providers: providers, | |
153 | + template: "<acme-navbar></acme-navbar>", | |
154 | + directives: [Navbar] | |
155 | + }) | |
156 | + .then(fixture => { | |
157 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
158 | + spyOn(navbarComp, "openLogin"); | |
159 | + navbarComp.activate(); | |
160 | + expect(navbarComp.openLogin.calls.count()).toBe(0); | |
161 | + done(); | |
162 | + }) | |
163 | + | |
164 | + }); | |
165 | + | |
166 | + it('should activate when user not logged in', (done: Function) => { | |
167 | + user = null; | |
168 | + quickCreateComponent({ | |
169 | + providers: providers, | |
170 | + template: "<acme-navbar></acme-navbar>", | |
171 | + directives: [Navbar] | |
172 | + }) | |
173 | + .then(fixture => { | |
174 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
175 | + spyOn(navbarComp, "openLogin"); | |
176 | + navbarComp.activate(); | |
177 | + expect(navbarComp.openLogin).toHaveBeenCalled(); | |
178 | + done(); | |
179 | + }) | |
180 | + }); | |
181 | + | |
148 | 182 | |
149 | 183 | // it('closes the modal the login', (done: Function) => { |
150 | 184 | // let scope = { | ... | ... |