Commit b81d0f8a019f1df270fa99ce7798ed85bab71d3a
Exists in
master
and in
1 other branch
Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward
Showing
1 changed file
with
53 additions
and
35 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
| ... | ... | @@ -30,6 +30,43 @@ describe("Components", () => { |
| 30 | 30 | login: "user" |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | + | |
| 34 | + let scope = { | |
| 35 | + eventCalledHook: () => { }, | |
| 36 | + $on: (eventName: string, func: Function) => { | |
| 37 | + this.eventCalledHook = func; | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | + let modalInstance = { | |
| 42 | + close: () => { } | |
| 43 | + } | |
| 44 | + | |
| 45 | + let $modal = { | |
| 46 | + open: (args: {}) => { | |
| 47 | + return modalInstance; | |
| 48 | + } | |
| 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 | + ]; | |
| 69 | + | |
| 33 | 70 | beforeEach(angular.mock.module("templates")); |
| 34 | 71 | |
| 35 | 72 | // beforeEach(inject((_$rootScope_: ng.IRootScopeService) => { |
| ... | ... | @@ -72,41 +109,6 @@ describe("Components", () => { |
| 72 | 109 | }); |
| 73 | 110 | |
| 74 | 111 | it('It should open on click', (done: Function) => { |
| 75 | - | |
| 76 | - let scope = { | |
| 77 | - eventCalledHook: () => { }, | |
| 78 | - $on: (eventName: string, func: Function) => { | |
| 79 | - console.log("ON Called!"); | |
| 80 | - this.eventCalledHook = func; | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | - let modalInstance = { | |
| 85 | - close: () => { | |
| 86 | - console.log("CLOSE Called!"); | |
| 87 | - } | |
| 88 | - } | |
| 89 | - | |
| 90 | - let $modal = { | |
| 91 | - open: (args: {}) => { | |
| 92 | - return modalInstance; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - let stateService = jasmine.createSpyObj("$state", ["go"]); | |
| 97 | - let providers = [ | |
| 98 | - new Provider('moment', { useValue: {} }), | |
| 99 | - new Provider('$modal', { useValue: $modal }), | |
| 100 | - new Provider('AuthService', { useValue: {} }), | |
| 101 | - new Provider('Session', { | |
| 102 | - useValue: { | |
| 103 | - currentUser: () => { return user } | |
| 104 | - } | |
| 105 | - }), | |
| 106 | - new Provider('$scope', { useValue: scope }), | |
| 107 | - new Provider('$state', { useValue: stateService }), | |
| 108 | - new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | |
| 109 | - ]; | |
| 110 | 112 | quickCreateComponent({ |
| 111 | 113 | providers: providers, |
| 112 | 114 | template: "<acme-navbar></acme-navbar>", |
| ... | ... | @@ -127,6 +129,22 @@ describe("Components", () => { |
| 127 | 129 | }) |
| 128 | 130 | }); |
| 129 | 131 | |
| 132 | + it('It should logout', (done: Function) => { | |
| 133 | + quickCreateComponent({ | |
| 134 | + providers: providers, | |
| 135 | + template: "<acme-navbar></acme-navbar>", | |
| 136 | + directives: [Navbar] | |
| 137 | + }) | |
| 138 | + .then(fixture => { | |
| 139 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | |
| 140 | + spyOn(authService, "logout"); | |
| 141 | + navbarComp.logout(); | |
| 142 | + expect(authService.logout).toHaveBeenCalled(); | |
| 143 | + done(); | |
| 144 | + }) | |
| 145 | + }); | |
| 146 | + | |
| 147 | + | |
| 130 | 148 | |
| 131 | 149 | // it('closes the modal the login', (done: Function) => { |
| 132 | 150 | // let scope = { | ... | ... |