Commit 3d642749a248d0ff775adef7930a651a43eab230

Authored by ABNER SILVA DE OLIVEIRA
1 parent 3f5ff960
Exists in master and in 1 other branch dev-fixes

changes on navbar spec. adding a test to complete 100% coverage

Showing 1 changed file with 20 additions and 10 deletions   Show diff stats
src/app/components/navbar/navbar.spec.ts
... ... @@ -21,7 +21,7 @@ describe("Components", () => {
21 21 let $modal: any;
22 22 let authService: any;
23 23 let stateService: any;
24   - let sessionService: any;
  24 + let sessionService: Session;
25 25  
26 26 let provideFunc = provide;
27 27  
... ... @@ -36,7 +36,7 @@ describe("Components", () => {
36 36 $modal = helpers.mocks.$modal;
37 37 authService = helpers.mocks.authService;
38 38 stateService = jasmine.createSpyObj("$state", ["go"]);
39   - sessionService = helpers.mocks.sessionWithCurrentUser(user);
  39 + sessionService = <any>helpers.mocks.sessionWithCurrentUser(user);
40 40 });
41 41  
42 42  
... ... @@ -155,18 +155,28 @@ describe(&quot;Components&quot;, () =&gt; {
155 155 let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
156 156 let localScope: ng.IScope = navbarComp["$scope"];
157 157  
158   -
159 158 navbarComp.openLogin();
160   -
161   - localScope.$on(AUTH_EVENTS.loginSuccess, () => {
162   - expect(modalInstance.close).toHaveBeenCalled();
163   - done();
164   - });
165   -
166 159 localScope.$emit(AUTH_EVENTS.loginSuccess);
167   - fixture.detectChanges();
  160 + expect(modalInstance.close).toHaveBeenCalled();
  161 + done();
  162 + });
  163 + });
  164 +
  165 + it('updates current user on logout', (done: Function) => {
  166 + buildComponent().then((fixture: ComponentFixture) => {
  167 + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
  168 + let localScope: ng.IScope = navbarComp["$scope"];
168 169  
  170 + // init navbar currentUser with some user
  171 + navbarComp["currentUser"] = user;
169 172  
  173 + // changes the current User to return null,
  174 + // and emmit the 'logoutSuccess' event
  175 + // just what happens when user logsout
  176 + sessionService.currentUser = () => { return null; };
  177 + localScope.$emit(AUTH_EVENTS.logoutSuccess);
  178 + expect(navbarComp["currentUser"]).toBeNull();
  179 + done();
170 180 });
171 181 });
172 182  
... ...