Commit 2e0755c9a5e1afdc8f082678ffee4c2effd76e18
1 parent
97702802
Exists in
helpers-evolution
ll
Showing
3 changed files
with
159 additions
and
74 deletions
Show diff stats
src/app/components/navbar/navbar.spec.ts
| 1 | +<<<<<<< Updated upstream | ||
| 1 | import { | 2 | import { |
| 2 | createComponentFromClass, | 3 | createComponentFromClass, |
| 3 | quickCreateComponent, | 4 | quickCreateComponent, |
| 4 | provideEmptyObjects | 5 | provideEmptyObjects |
| 5 | } from "./../../../spec/helpers"; | 6 | } from "./../../../spec/helpers"; |
| 7 | +======= | ||
| 8 | +import * as helpers from "./../../../spec/helpers"; | ||
| 9 | +>>>>>>> Stashed changes | ||
| 6 | import { | 10 | import { |
| 7 | Navbar | 11 | Navbar |
| 8 | } from "./navbar"; | 12 | } from "./navbar"; |
| @@ -18,6 +22,15 @@ import { | @@ -18,6 +22,15 @@ import { | ||
| 18 | provide | 22 | provide |
| 19 | } from "ng-forward"; | 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 | describe("Components", () => { | 35 | describe("Components", () => { |
| 23 | 36 | ||
| @@ -36,35 +49,51 @@ describe("Components", () => { | @@ -36,35 +49,51 @@ describe("Components", () => { | ||
| 36 | $on: (eventName: string, func: Function) => { | 49 | $on: (eventName: string, func: Function) => { |
| 37 | this.eventCalledHook = func; | 50 | this.eventCalledHook = func; |
| 38 | } | 51 | } |
| 39 | - } | 52 | + }; |
| 40 | 53 | ||
| 41 | let modalInstance = { | 54 | let modalInstance = { |
| 42 | close: () => { } | 55 | close: () => { } |
| 43 | - } | 56 | + }; |
| 44 | 57 | ||
| 45 | let $modal = { | 58 | let $modal = { |
| 46 | open: (args: {}) => { | 59 | open: (args: {}) => { |
| 47 | return modalInstance; | 60 | return modalInstance; |
| 48 | } | 61 | } |
| 49 | - } | 62 | + }; |
| 50 | 63 | ||
| 51 | let authService = { | 64 | let authService = { |
| 52 | logout: () => { } | 65 | logout: () => { } |
| 53 | - } | 66 | + }; |
| 54 | 67 | ||
| 55 | let stateService = jasmine.createSpyObj("$state", ["go"]); | 68 | let stateService = jasmine.createSpyObj("$state", ["go"]); |
| 56 | let providers = [ | 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 | new Provider('Session', { | 79 | new Provider('Session', { |
| 61 | useValue: { | 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 | beforeEach(angular.mock.module("templates")); | 99 | beforeEach(angular.mock.module("templates")); |
| @@ -78,7 +107,7 @@ describe("Components", () => { | @@ -78,7 +107,7 @@ describe("Components", () => { | ||
| 78 | let scope = jasmine.createSpyObj("scope", ["$on"]); | 107 | let scope = jasmine.createSpyObj("scope", ["$on"]); |
| 79 | 108 | ||
| 80 | let providers = [ | 109 | let providers = [ |
| 81 | - provideEmptyObjects('moment', '$modal', 'AuthService', '$state'), | 110 | + helpers.provideEmptyObjects('moment', '$modal', 'AuthService', '$state'), |
| 82 | new Provider('Session', { | 111 | new Provider('Session', { |
| 83 | useValue: { | 112 | useValue: { |
| 84 | currentUser: () => { | 113 | currentUser: () => { |
| @@ -96,20 +125,22 @@ describe("Components", () => { | @@ -96,20 +125,22 @@ describe("Components", () => { | ||
| 96 | }) | 125 | }) |
| 97 | ]; | 126 | ]; |
| 98 | 127 | ||
| 99 | - quickCreateComponent({ | 128 | + helpers.quickCreateComponent({ |
| 100 | providers: providers, | 129 | providers: providers, |
| 101 | template: "<acme-navbar></acme-navbar>", | 130 | template: "<acme-navbar></acme-navbar>", |
| 102 | directives: [Navbar] | 131 | directives: [Navbar] |
| 103 | }).then(fixture => { | 132 | }).then(fixture => { |
| 104 | let navbarInstance: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance; | 133 | let navbarInstance: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance; |
| 105 | expect(navbarInstance).toBeDefined(); | 134 | expect(navbarInstance).toBeDefined(); |
| 106 | - expect(navbarInstance["currentUser"]).toEqual(user) | 135 | + expect(navbarInstance["currentUser"]).toEqual(user); |
| 107 | done(); | 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 | providers: providers, | 144 | providers: providers, |
| 114 | template: "<acme-navbar></acme-navbar>", | 145 | template: "<acme-navbar></acme-navbar>", |
| 115 | directives: [Navbar] | 146 | directives: [Navbar] |
| @@ -126,11 +157,12 @@ describe("Components", () => { | @@ -126,11 +157,12 @@ describe("Components", () => { | ||
| 126 | bindToController: true | 157 | bindToController: true |
| 127 | }) | 158 | }) |
| 128 | done(); | 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 | providers: providers, | 166 | providers: providers, |
| 135 | template: "<acme-navbar></acme-navbar>", | 167 | template: "<acme-navbar></acme-navbar>", |
| 136 | directives: [Navbar] | 168 | directives: [Navbar] |
| @@ -141,64 +173,99 @@ describe("Components", () => { | @@ -141,64 +173,99 @@ describe("Components", () => { | ||
| 141 | navbarComp.logout(); | 173 | navbarComp.logout(); |
| 142 | expect(authService.logout).toHaveBeenCalled(); | 174 | expect(authService.logout).toHaveBeenCalled(); |
| 143 | done(); | 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,6 +29,7 @@ export class Navbar { | ||
| 29 | this.currentUser = session.currentUser(); | 29 | this.currentUser = session.currentUser(); |
| 30 | 30 | ||
| 31 | $scope.$on(AUTH_EVENTS.loginSuccess, () => { | 31 | $scope.$on(AUTH_EVENTS.loginSuccess, () => { |
| 32 | + console.log("HEREERERERERERERERERRE"); | ||
| 32 | if (this.modalInstance) { | 33 | if (this.modalInstance) { |
| 33 | this.modalInstance.close(); | 34 | this.modalInstance.close(); |
| 34 | this.modalInstance = null; | 35 | this.modalInstance = null; |
| @@ -44,6 +45,7 @@ export class Navbar { | @@ -44,6 +45,7 @@ export class Navbar { | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | openLogin() { | 47 | openLogin() { |
| 48 | + console.log('OPENLOGIN', this.$modal); | ||
| 47 | this.modalInstance = this.$modal.open({ | 49 | this.modalInstance = this.$modal.open({ |
| 48 | templateUrl: 'app/components/auth/login.html', | 50 | templateUrl: 'app/components/auth/login.html', |
| 49 | controller: AuthController, | 51 | controller: AuthController, |
src/spec/helpers.ts
| @@ -60,12 +60,20 @@ class AngularServiceHookComponent { | @@ -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 | class AngularServiceFactory { | 67 | class AngularServiceFactory { |
| 68 | +<<<<<<< Updated upstream | ||
| 64 | fixtureComponentHookPoint: ComponentFixture; | 69 | fixtureComponentHookPoint: ComponentFixture; |
| 65 | tcb: TestComponentBuilder = new TestComponentBuilder(); | 70 | tcb: TestComponentBuilder = new TestComponentBuilder(); |
| 66 | 71 | ||
| 67 | constructor() { | 72 | constructor() { |
| 68 | this.fixtureComponentHookPoint = (<any>this.tcb)["create"](AngularServiceHookComponent); | 73 | this.fixtureComponentHookPoint = (<any>this.tcb)["create"](AngularServiceHookComponent); |
| 74 | +======= | ||
| 75 | + constructor(private fixtureComponentHookPoint: ComponentFixture) { | ||
| 76 | +>>>>>>> Stashed changes | ||
| 69 | } | 77 | } |
| 70 | 78 | ||
| 71 | getAngularService<T>(angularService: string) { | 79 | getAngularService<T>(angularService: string) { |
| @@ -81,6 +89,7 @@ class AngularServiceFactory { | @@ -81,6 +89,7 @@ class AngularServiceFactory { | ||
| 81 | } | 89 | } |
| 82 | } | 90 | } |
| 83 | 91 | ||
| 92 | +<<<<<<< Updated upstream | ||
| 84 | export var angularServiceFactory = new AngularServiceFactory(); | 93 | export var angularServiceFactory = new AngularServiceFactory(); |
| 85 | /** | 94 | /** |
| 86 | * This help function allows get angular services to be used in integration tests | 95 | * This help function allows get angular services to be used in integration tests |
| @@ -97,6 +106,13 @@ export function getQService(): ng.IQService { | @@ -97,6 +106,13 @@ export function getQService(): ng.IQService { | ||
| 97 | export function getHttpBackendService(): ng.IHttpBackendService { | 106 | export function getHttpBackendService(): ng.IHttpBackendService { |
| 98 | return angularServiceFactory.getHttpBackendService(); | 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 | // export function getResolvablePromise() { | 117 | // export function getResolvablePromise() { |
| 102 | // let $q = getQService(); | 118 | // let $q = getQService(); |