Commit 2e0755c9a5e1afdc8f082678ffee4c2effd76e18

Authored by Ábner Oliveira
1 parent 97702802
Exists in helpers-evolution

ll

src/app/components/navbar/navbar.spec.ts
  1 +<<<<<<< Updated upstream
1 2 import {
2 3 createComponentFromClass,
3 4 quickCreateComponent,
4 5 provideEmptyObjects
5 6 } from "./../../../spec/helpers";
  7 +=======
  8 +import * as helpers from "./../../../spec/helpers";
  9 +>>>>>>> Stashed changes
6 10 import {
7 11 Navbar
8 12 } from "./navbar";
... ... @@ -18,6 +22,15 @@ import {
18 22 provide
19 23 } from "ng-forward";
20 24  
  25 +<<<<<<< Updated upstream
  26 +=======
  27 +import {
  28 +Session,
  29 +AuthService,
  30 +AuthController,
  31 +IAuthEvents
  32 +} from "./../auth";
  33 +>>>>>>> Stashed changes
21 34  
22 35 describe("Components", () => {
23 36  
... ... @@ -36,35 +49,51 @@ describe(&quot;Components&quot;, () =&gt; {
36 49 $on: (eventName: string, func: Function) => {
37 50 this.eventCalledHook = func;
38 51 }
39   - }
  52 + };
40 53  
41 54 let modalInstance = {
42 55 close: () => { }
43   - }
  56 + };
44 57  
45 58 let $modal = {
46 59 open: (args: {}) => {
47 60 return modalInstance;
48 61 }
49   - }
  62 + };
50 63  
51 64 let authService = {
52 65 logout: () => { }
53   - }
  66 + };
54 67  
55 68 let stateService = jasmine.createSpyObj("$state", ["go"]);
56 69 let providers = [
57   - new Provider('moment', { useValue: {} }),
58   - new Provider('$modal', { useValue: $modal }),
59   - new Provider('AuthService', { useValue: authService }),
  70 + new Provider('moment', {
  71 + useValue: {}
  72 + }),
  73 + new Provider('$modal', {
  74 + useValue: $modal
  75 + }),
  76 + new Provider('AuthService', {
  77 + useValue: authService
  78 + }),
60 79 new Provider('Session', {
61 80 useValue: {
62   - currentUser: () => { return user }
  81 + currentUser: () => {
  82 + return user;
  83 + }
63 84 }
64 85 }),
65   - new Provider('$scope', { useValue: scope }),
66   - new Provider('$state', { useValue: stateService }),
67   - new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } })
  86 + new Provider('$scope', {
  87 + useValue: scope
  88 + }),
  89 + new Provider('$state', {
  90 + useValue: stateService
  91 + }),
  92 + new Provider('AUTH_EVENTS', {
  93 + useValue: {
  94 + AUTH_EVENTS
  95 + }
  96 + })
68 97 ];
69 98  
70 99 beforeEach(angular.mock.module("templates"));
... ... @@ -78,7 +107,7 @@ describe(&quot;Components&quot;, () =&gt; {
78 107 let scope = jasmine.createSpyObj("scope", ["$on"]);
79 108  
80 109 let providers = [
81   - provideEmptyObjects('moment', '$modal', 'AuthService', '$state'),
  110 + helpers.provideEmptyObjects('moment', '$modal', 'AuthService', '$state'),
82 111 new Provider('Session', {
83 112 useValue: {
84 113 currentUser: () => {
... ... @@ -96,20 +125,22 @@ describe(&quot;Components&quot;, () =&gt; {
96 125 })
97 126 ];
98 127  
99   - quickCreateComponent({
  128 + helpers.quickCreateComponent({
100 129 providers: providers,
101 130 template: "<acme-navbar></acme-navbar>",
102 131 directives: [Navbar]
103 132 }).then(fixture => {
104 133 let navbarInstance: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
105 134 expect(navbarInstance).toBeDefined();
106   - expect(navbarInstance["currentUser"]).toEqual(user)
  135 + expect(navbarInstance["currentUser"]).toEqual(user);
107 136 done();
108 137 });
109 138 });
110 139  
111   - it('It should open on click', (done: Function) => {
112   - quickCreateComponent({
  140 +
  141 + it('should open on click', (done: Function) => {
  142 +
  143 + helpers.quickCreateComponent({
113 144 providers: providers,
114 145 template: "<acme-navbar></acme-navbar>",
115 146 directives: [Navbar]
... ... @@ -126,11 +157,12 @@ describe(&quot;Components&quot;, () =&gt; {
126 157 bindToController: true
127 158 })
128 159 done();
129   - })
  160 + });
130 161 });
131 162  
132   - it('It should logout', (done: Function) => {
133   - quickCreateComponent({
  163 + it('should logout', (done: Function) => {
  164 +
  165 + helpers.quickCreateComponent({
134 166 providers: providers,
135 167 template: "<acme-navbar></acme-navbar>",
136 168 directives: [Navbar]
... ... @@ -141,64 +173,99 @@ describe(&quot;Components&quot;, () =&gt; {
141 173 navbarComp.logout();
142 174 expect(authService.logout).toHaveBeenCalled();
143 175 done();
144   - })
  176 + });
  177 + });
  178 + it('should not activate user when logged in', (done: Function) => {
  179 + helpers.quickCreateComponent({
  180 + providers: providers,
  181 + template: "<acme-navbar></acme-navbar>",
  182 + directives: [Navbar]
  183 + })
  184 + .then(fixture => {
  185 + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
  186 + spyOn(navbarComp, "openLogin");
  187 + navbarComp.activate();
  188 + expect((<any>navbarComp.openLogin).calls.count()).toBe(0);
  189 + done();
  190 + });
  191 +
  192 + });
  193 +
  194 + it('should activate when user not logged in', (done: Function) => {
  195 + user = null;
  196 + helpers.quickCreateComponent({
  197 + providers: providers,
  198 + template: "<acme-navbar></acme-navbar>",
  199 + directives: [Navbar]
  200 + })
  201 + .then(fixture => {
  202 + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
  203 + spyOn(navbarComp, "openLogin");
  204 + navbarComp.activate();
  205 + expect(navbarComp.openLogin).toHaveBeenCalled();
  206 + done();
  207 + });
145 208 });
146 209  
  210 + it('closes the modal the login', (done: Function) => {
  211 + let scope = {
  212 + $on: (eventName: string, func: Function) => {
  213 + console.log("ON Called!");
  214 + }
  215 + };
  216 +
  217 + let modalInstance = {
  218 + close: () => {
  219 + console.log("CLOSE Called!");
  220 + }
  221 + };
  222 +
  223 + let $modal = {
  224 + open: (args: {}) => {
  225 + return modalInstance;
  226 + }
  227 + };
  228 +
  229 +
  230 +
  231 + let stateService = jasmine.createSpyObj("$state", ["go"]);
  232 + let providers = [
  233 + new Provider('moment', { useValue: {} }),
  234 + new Provider('$modal', { useValue: $modal }),
  235 + new Provider('AuthService', { useValue: {} }),
  236 + new Provider('Session', {
  237 + useValue: {
  238 + currentUser: () => { return user; }
  239 + }
  240 + }),
  241 + new Provider('$scope', { useValue: scope }),
  242 + new Provider('$state', { useValue: stateService }),
  243 + new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } })
  244 + ];
  245 + spyOn(modalInstance, "close");
  246 +
  247 + helpers.quickCreateComponent({
  248 + providers: providers,
  249 + template: "<acme-navbar></acme-navbar>",
  250 + directives: [Navbar]
  251 + })
  252 + .then(fixture => {
  253 + let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
  254 +
  255 + spyOn($modal, 'open');
  256 + navbarComp.activate();
  257 + navbarComp.openLogin();
147 258  
  259 + let openArgs = { templateUrl: 'app/components/auth/login.html', controller: Function, controllerAs: 'vm', bindToController: true };
148 260  
149   - // it('closes the modal the login', (done: Function) => {
150   - // let scope = {
151   - // eventCalledHook: () => { },
152   - // $on: (eventName: string, func: Function) => {
153   - // console.log("ON Called!");
154   - // this.eventCalledHook = func;
155   - // }
156   - // }
157   - //
158   - // let modalInstance = {
159   - // close: () => {
160   - // console.log("CLOSE Called!");
161   - // }
162   - // }
163   - //
164   - // let $modal = {
165   - // $open: (args: {}) => {
166   - // return modalInstance;
167   - // }
168   - // }
169   - //
170   - // let stateService = jasmine.createSpyObj("$state", ["go"]);
171   - // let providers = [
172   - // new Provider('moment', { useValue: {} }),
173   - // new Provider('$modal', { useValue: $modal }),
174   - // new Provider('AuthService', { useValue: {} }),
175   - // new Provider('Session', {
176   - // useValue: {
177   - // currentUser: () => { return user }
178   - // }
179   - // }),
180   - // new Provider('$scope', { useValue: scope }),
181   - // new Provider('$state', { useValue: stateService }),
182   - // new Provider('AUTH_EVENTS', { useValue: { AUTH_EVENTS } })
183   - // ];
184   - // spyOn(modalInstance, "close");
185   - //
186   - // quickCreateComponent({
187   - // providers: providers,
188   - // template: "<acme-navbar></acme-navbar>",
189   - // directives: [Navbar]
190   - // })
191   - // .then(fixture => {
192   - // let navbarComp: Navbar = <Navbar>fixture.debugElement.componentViewChildren[0].componentInstance;
193   - // navbarComp.activate();
194   - // navbarComp.openLogin
195   - //
196   - // expect($modal.open).toHaveBeenCalledWith({})
197   - // scope.eventCalledHook();
198   - // expect(modalInstance.close).toHaveBeenCalled();
199   - // done();
200   - // })
201   - // //done();
202   - // });
  261 +
  262 + expect($modal.open).toHaveBeenCalled();
  263 + scope.eventCalledHook();
  264 + expect(modalInstance.close).toHaveBeenCalled();
  265 + done();
  266 + });
  267 + // done();
  268 + });
  269 +>>>>>>> Stashed changes
203 270 });
204 271 });
... ...
src/app/components/navbar/navbar.ts
... ... @@ -29,6 +29,7 @@ export class Navbar {
29 29 this.currentUser = session.currentUser();
30 30  
31 31 $scope.$on(AUTH_EVENTS.loginSuccess, () => {
  32 + console.log("HEREERERERERERERERERRE");
32 33 if (this.modalInstance) {
33 34 this.modalInstance.close();
34 35 this.modalInstance = null;
... ... @@ -44,6 +45,7 @@ export class Navbar {
44 45 }
45 46  
46 47 openLogin() {
  48 + console.log('OPENLOGIN', this.$modal);
47 49 this.modalInstance = this.$modal.open({
48 50 templateUrl: 'app/components/auth/login.html',
49 51 controller: AuthController,
... ...
src/spec/helpers.ts
... ... @@ -60,12 +60,20 @@ class AngularServiceHookComponent {
60 60 }
61 61 }
62 62  
  63 +/**
  64 + * This helper class allows get angular services to be used in integration tests
  65 + * i.e: '$http', '$q', '$location', etc...
  66 + */
63 67 class AngularServiceFactory {
  68 +<<<<<<< Updated upstream
64 69 fixtureComponentHookPoint: ComponentFixture;
65 70 tcb: TestComponentBuilder = new TestComponentBuilder();
66 71  
67 72 constructor() {
68 73 this.fixtureComponentHookPoint = (<any>this.tcb)["create"](AngularServiceHookComponent);
  74 +=======
  75 + constructor(private fixtureComponentHookPoint: ComponentFixture) {
  76 +>>>>>>> Stashed changes
69 77 }
70 78  
71 79 getAngularService<T>(angularService: string) {
... ... @@ -81,6 +89,7 @@ class AngularServiceFactory {
81 89 }
82 90 }
83 91  
  92 +<<<<<<< Updated upstream
84 93 export var angularServiceFactory = new AngularServiceFactory();
85 94 /**
86 95 * This help function allows get angular services to be used in integration tests
... ... @@ -97,6 +106,13 @@ export function getQService(): ng.IQService {
97 106 export function getHttpBackendService(): ng.IHttpBackendService {
98 107 return angularServiceFactory.getHttpBackendService();
99 108 }
  109 +=======
  110 +export function getAngularServiceFactory(fixture: ComponentFixture) {
  111 + return new AngularServiceFactory(fixture);
  112 +}
  113 +
  114 +
  115 +>>>>>>> Stashed changes
100 116  
101 117 // export function getResolvablePromise() {
102 118 // let $q = getQService();
... ...