From ad92917af77a3937a520d6638e79913b12315d77 Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Tue, 8 Mar 2016 16:57:15 -0300 Subject: [PATCH] New navbars tests --- src/app/components/navbar/navbar.spec.ts | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/src/app/components/navbar/navbar.spec.ts b/src/app/components/navbar/navbar.spec.ts index 8d51997..5af559b 100644 --- a/src/app/components/navbar/navbar.spec.ts +++ b/src/app/components/navbar/navbar.spec.ts @@ -18,54 +18,55 @@ import { provide } from "ng-forward"; +import {Session, AuthService, AuthController, IAuthEvents} from "./../auth"; describe("Components", () => { - describe("Navbar Component", () => { - let $rootScope: ng.IRootScopeService; - let user = { - id: 1, - login: "user" - }; - + let $rootScope: ng.IRootScopeService; + + let user = { + id: 1, + login: "user" + }; + + let scope = { + eventCalledHook: () => { }, + $on: (eventName: string, func: Function) => { + this.eventCalledHook = func; + } + } - let scope = { - eventCalledHook: () => { }, - $on: (eventName: string, func: Function) => { - this.eventCalledHook = func; + let modalInstance = { + close: () => { } } - } - let modalInstance = { - close: () => { } - } + let $modal = { + open: (args: {}) => { + return modalInstance; + } + } - let $modal = { - open: (args: {}) => { - return modalInstance; + let authService = { + logout: () => { } } - } - - let authService = { - logout: () => { } - } - - let stateService = jasmine.createSpyObj("$state", ["go"]); - let providers = [ - new Provider('moment', { useValue: {} }), - new Provider('$modal', { useValue: $modal }), - new Provider('AuthService', { useValue: authService }), - new Provider('Session', { - useValue: { - currentUser: () => { return user } - } - }), - new Provider('$scope', { useValue: scope }), - new Provider('$state', { useValue: stateService }), - new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) - ]; + + let stateService = jasmine.createSpyObj("$state", ["go"]); + let providers = [ + new Provider('moment', { useValue: {} }), + new Provider('$modal', { useValue: $modal }), + new Provider('AuthService', { useValue: authService }), + new Provider('Session', { + useValue: { + currentUser: () => { return user } + } + }), + new Provider('$scope', { useValue: scope }), + new Provider('$state', { useValue: stateService }), + new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) + ]; + beforeEach(angular.mock.module("templates")); @@ -76,7 +77,6 @@ describe("Components", () => { it('should get the loggedIn user', (done: Function) => { let scope = jasmine.createSpyObj("scope", ["$on"]); - let providers = [ provideEmptyObjects('moment', '$modal', 'AuthService', '$state'), new Provider('Session', { @@ -108,7 +108,8 @@ describe("Components", () => { }); }); - it('It should open on click', (done: Function) => { + it('should open on click', (done: Function) => { + quickCreateComponent({ providers: providers, template: "", @@ -119,17 +120,18 @@ describe("Components", () => { spyOn($modal, "open"); navbarComp.openLogin(); expect($modal.open).toHaveBeenCalled(); - // expect($modal.open).toHaveBeenCalledWith({ - // templateUrl: 'app/components/auth/login.html', - // controller: 'AuthController', - // controllerAs: 'vm', - // bindToController: true - // }) + expect($modal.open).toHaveBeenCalledWith({ + templateUrl: 'app/components/auth/login.html', + controller: AuthController, + controllerAs: 'vm', + bindToController: true + }) done(); }) }); - it('It should logout', (done: Function) => { + it('should logout', (done: Function) => { + quickCreateComponent({ providers: providers, template: "", @@ -145,6 +147,38 @@ describe("Components", () => { }); + it('should not activate user when logged in', (done: Function) => { + quickCreateComponent({ + providers: providers, + template: "", + directives: [Navbar] + }) + .then(fixture => { + let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance; + spyOn(navbarComp, "openLogin"); + navbarComp.activate(); + expect(navbarComp.openLogin.calls.count()).toBe(0); + done(); + }) + + }); + + it('should activate when user not logged in', (done: Function) => { + user = null; + quickCreateComponent({ + providers: providers, + template: "", + directives: [Navbar] + }) + .then(fixture => { + let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance; + spyOn(navbarComp, "openLogin"); + navbarComp.activate(); + expect(navbarComp.openLogin).toHaveBeenCalled(); + done(); + }) + }); + // it('closes the modal the login', (done: Function) => { // let scope = { -- libgit2 0.21.2