Commit c87b1f47f5996f0212ae56c72e8cf300ad991740
1 parent
dacb4561
Exists in
master
and in
1 other branch
Login modal test for navbar
Showing
2 changed files
with
124 additions
and
12 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
1 | import { | 1 | import { |
2 | -createComponentFromClass, | ||
3 | -quickCreateComponent, | ||
4 | -provideEmptyObjects | 2 | + createComponentFromClass, |
3 | + quickCreateComponent, | ||
4 | + provideEmptyObjects | ||
5 | } from "./../../../spec/helpers"; | 5 | } from "./../../../spec/helpers"; |
6 | import { | 6 | import { |
7 | -Navbar | 7 | + Navbar |
8 | } from "./navbar"; | 8 | } from "./navbar"; |
9 | import { | 9 | import { |
10 | -AUTH_EVENTS | 10 | + AUTH_EVENTS |
11 | } from "./../auth"; | 11 | } from "./../auth"; |
12 | import { | 12 | import { |
13 | -User | 13 | + User |
14 | } from "./../../models/interfaces"; | 14 | } from "./../../models/interfaces"; |
15 | import { | 15 | import { |
16 | -Injectable, | ||
17 | -Provider, | ||
18 | -provide | 16 | + Injectable, |
17 | + Provider, | ||
18 | + provide | ||
19 | } from "ng-forward"; | 19 | } from "ng-forward"; |
20 | 20 | ||
21 | 21 | ||
@@ -59,7 +59,6 @@ describe("Components", () => { | @@ -59,7 +59,6 @@ describe("Components", () => { | ||
59 | }) | 59 | }) |
60 | ]; | 60 | ]; |
61 | 61 | ||
62 | - | ||
63 | quickCreateComponent({ | 62 | quickCreateComponent({ |
64 | providers: providers, | 63 | providers: providers, |
65 | template: "<acme-navbar></acme-navbar>", | 64 | template: "<acme-navbar></acme-navbar>", |
@@ -72,5 +71,118 @@ describe("Components", () => { | @@ -72,5 +71,118 @@ describe("Components", () => { | ||
72 | }); | 71 | }); |
73 | }); | 72 | }); |
74 | 73 | ||
74 | + 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 | + quickCreateComponent({ | ||
111 | + providers: providers, | ||
112 | + template: "<acme-navbar></acme-navbar>", | ||
113 | + directives: [Navbar] | ||
114 | + }) | ||
115 | + .then(fixture => { | ||
116 | + console.log("entrou no .then") | ||
117 | + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | ||
118 | + spyOn($modal, "open"); | ||
119 | + //navbarComp.activate(); | ||
120 | + navbarComp.openLogin(); | ||
121 | + 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 | + }) | ||
128 | + done(); | ||
129 | + }) | ||
130 | + }); | ||
131 | + | ||
132 | + | ||
133 | + // it('closes the modal the login', (done: Function) => { | ||
134 | + // let scope = { | ||
135 | + // eventCalledHook: () => { }, | ||
136 | + // $on: (eventName: string, func: Function) => { | ||
137 | + // console.log("ON Called!"); | ||
138 | + // this.eventCalledHook = func; | ||
139 | + // } | ||
140 | + // } | ||
141 | + // | ||
142 | + // let modalInstance = { | ||
143 | + // close: () => { | ||
144 | + // console.log("CLOSE Called!"); | ||
145 | + // } | ||
146 | + // } | ||
147 | + // | ||
148 | + // let $modal = { | ||
149 | + // $open: (args: {}) => { | ||
150 | + // return modalInstance; | ||
151 | + // } | ||
152 | + // } | ||
153 | + // | ||
154 | + // let stateService = jasmine.createSpyObj("$state", ["go"]); | ||
155 | + // let providers = [ | ||
156 | + // new Provider('moment', { useValue: {} }), | ||
157 | + // new Provider('$modal', { useValue: $modal }), | ||
158 | + // new Provider('AuthService', { useValue: {} }), | ||
159 | + // new Provider('Session', { | ||
160 | + // useValue: { | ||
161 | + // currentUser: () => { return user } | ||
162 | + // } | ||
163 | + // }), | ||
164 | + // new Provider('$scope', { useValue: scope }), | ||
165 | + // new Provider('$state', { useValue: stateService }), | ||
166 | + // new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } }) | ||
167 | + // ]; | ||
168 | + // spyOn(modalInstance, "close"); | ||
169 | + // | ||
170 | + // quickCreateComponent({ | ||
171 | + // providers: providers, | ||
172 | + // template: "<acme-navbar></acme-navbar>", | ||
173 | + // directives: [Navbar] | ||
174 | + // }) | ||
175 | + // .then(fixture => { | ||
176 | + // let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance; | ||
177 | + // navbarComp.activate(); | ||
178 | + // navbarComp.openLogin | ||
179 | + // | ||
180 | + // expect($modal.open).toHaveBeenCalledWith({}) | ||
181 | + // scope.eventCalledHook(); | ||
182 | + // expect(modalInstance.close).toHaveBeenCalled(); | ||
183 | + // done(); | ||
184 | + // }) | ||
185 | + // //done(); | ||
186 | + // }); | ||
75 | }); | 187 | }); |
76 | -}); | ||
77 | \ No newline at end of file | 188 | \ No newline at end of file |
189 | +}); |