|
1 | | -import {async, ComponentFixture, TestBed} from '@angular/core/testing'; |
| 1 | +import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
2 | 2 | import {Component, ViewChild} from '@angular/core'; |
3 | 3 | import {WizardNavigationBarComponent} from './wizard-navigation-bar.component'; |
4 | 4 | import {WizardComponent} from './wizard.component'; |
@@ -88,11 +88,12 @@ describe('WizardNavigationBarComponent', () => { |
88 | 88 | expect(navigableLi.length).toBe(0); |
89 | 89 | }); |
90 | 90 |
|
91 | | - it('should show the second step correctly', () => { |
| 91 | + it('should show the second step correctly', fakeAsync(() => { |
92 | 92 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
93 | 93 |
|
94 | 94 | // go to second step |
95 | 95 | navigationMode.goToNextStep(); |
| 96 | + tick(); |
96 | 97 | wizardTestFixture.detectChanges(); |
97 | 98 |
|
98 | 99 | const allLi = navBar.queryAll(By.css('li')); |
@@ -124,15 +125,19 @@ describe('WizardNavigationBarComponent', () => { |
124 | 125 |
|
125 | 126 | expect(navigableLi.length).toBe(1); |
126 | 127 | expect(navigableLi[0]).toBe(allLi[0]); |
127 | | - }); |
| 128 | + })); |
128 | 129 |
|
129 | | - it('should show the third step correctly', () => { |
| 130 | + it('should show the third step correctly', fakeAsync(() => { |
130 | 131 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
131 | 132 |
|
132 | 133 | // go to second step |
133 | 134 | navigationMode.goToNextStep(); |
| 135 | + tick(); |
| 136 | + wizardTestFixture.detectChanges(); |
| 137 | + |
134 | 138 | // go to third step |
135 | 139 | navigationMode.goToNextStep(); |
| 140 | + tick(); |
136 | 141 | wizardTestFixture.detectChanges(); |
137 | 142 |
|
138 | 143 | const allLi = navBar.queryAll(By.css('li')); |
@@ -165,13 +170,14 @@ describe('WizardNavigationBarComponent', () => { |
165 | 170 | expect(doneLi.length).toBe(2); |
166 | 171 | expect(navigableLi[0]).toBe(allLi[0]); |
167 | 172 | expect(navigableLi[1]).toBe(allLi[1]); |
168 | | - }); |
| 173 | + })); |
169 | 174 |
|
170 | | - it('should show the third step correctly, after jump from first to third step', () => { |
| 175 | + it('should show the third step correctly, after jump from first to third step', fakeAsync(() => { |
171 | 176 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
172 | 177 |
|
173 | 178 | // go to third step and jump over the optional second step |
174 | 179 | navigationMode.goToStep(2); |
| 180 | + tick(); |
175 | 181 | wizardTestFixture.detectChanges(); |
176 | 182 |
|
177 | 183 | const allLi = navBar.queryAll(By.css('li')); |
@@ -204,15 +210,19 @@ describe('WizardNavigationBarComponent', () => { |
204 | 210 | expect(navigableLi.length).toBe(2); |
205 | 211 | expect(navigableLi[0]).toBe(allLi[0]); |
206 | 212 | expect(navigableLi[1]).toBe(allLi[1]); |
207 | | - }); |
| 213 | + })); |
208 | 214 |
|
209 | | - it('should show the first step correctly, after going back from the second step to the first step', () => { |
| 215 | + it('should show the first step correctly, after going back from the second step to the first step', fakeAsync(() => { |
210 | 216 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
211 | 217 |
|
212 | 218 | // go to second step |
213 | 219 | navigationMode.goToNextStep(); |
| 220 | + tick(); |
| 221 | + wizardTestFixture.detectChanges(); |
| 222 | + |
214 | 223 | // go back to first step |
215 | 224 | navigationMode.goToPreviousStep(); |
| 225 | + tick(); |
216 | 226 | wizardTestFixture.detectChanges(); |
217 | 227 |
|
218 | 228 | const allLi = navBar.queryAll(By.css('li')); |
@@ -243,16 +253,20 @@ describe('WizardNavigationBarComponent', () => { |
243 | 253 | expect(defaultLi[0]).toBe(allLi[2]); |
244 | 254 |
|
245 | 255 | expect(navigableLi.length).toBe(0); |
246 | | - }); |
| 256 | + })); |
247 | 257 |
|
248 | 258 | it('should show the first step correctly, after first jumping from the first to the third step ' + |
249 | | - 'and then back from the third step to the first step', () => { |
| 259 | + 'and then back from the third step to the first step', fakeAsync(() => { |
250 | 260 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
251 | 261 |
|
252 | 262 | // go to third step, by jumping over the optional step |
253 | 263 | navigationMode.goToStep(2); |
| 264 | + tick(); |
| 265 | + wizardTestFixture.detectChanges(); |
| 266 | + |
254 | 267 | // go back to first step |
255 | 268 | navigationMode.goToStep(0); |
| 269 | + tick(); |
256 | 270 | wizardTestFixture.detectChanges(); |
257 | 271 |
|
258 | 272 | const allLi = navBar.queryAll(By.css('li')); |
@@ -283,16 +297,20 @@ describe('WizardNavigationBarComponent', () => { |
283 | 297 | expect(defaultLi[0]).toBe(allLi[2]); |
284 | 298 |
|
285 | 299 | expect(navigableLi.length).toBe(0); |
286 | | - }); |
| 300 | + })); |
287 | 301 |
|
288 | 302 | it('should show the second step correctly, after first jumping from the first to the third step ' + |
289 | | - 'and then back from the third step to the second step', () => { |
| 303 | + 'and then back from the third step to the second step', fakeAsync(() => { |
290 | 304 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
291 | 305 |
|
292 | 306 | // go to third step, by jumping over the optional step |
293 | 307 | navigationMode.goToStep(2); |
| 308 | + tick(); |
| 309 | + wizardTestFixture.detectChanges(); |
| 310 | + |
294 | 311 | // go back to second step |
295 | 312 | navigationMode.goToPreviousStep(); |
| 313 | + tick(); |
296 | 314 | wizardTestFixture.detectChanges(); |
297 | 315 |
|
298 | 316 | const allLi = navBar.queryAll(By.css('li')); |
@@ -324,14 +342,16 @@ describe('WizardNavigationBarComponent', () => { |
324 | 342 |
|
325 | 343 | expect(navigableLi.length).toBe(1); |
326 | 344 | expect(navigableLi[0]).toBe(allLi[0]); |
327 | | - }); |
| 345 | + })); |
328 | 346 |
|
329 | | - it('should disable navigation through the navigation bar correctly', () => { |
| 347 | + it('should disable navigation through the navigation bar correctly', fakeAsync(() => { |
330 | 348 | const navBar = wizardTestFixture.debugElement.query(By.css('wizard-navigation-bar')); |
331 | 349 |
|
332 | 350 | wizardState.disableNavigationBar = true; |
| 351 | + |
333 | 352 | // go to third step and jump over the optional second step |
334 | 353 | navigationMode.goToStep(2); |
| 354 | + tick(); |
335 | 355 | wizardTestFixture.detectChanges(); |
336 | 356 |
|
337 | 357 | const allLi = navBar.queryAll(By.css('li')); |
@@ -362,55 +382,67 @@ describe('WizardNavigationBarComponent', () => { |
362 | 382 | expect(defaultLi.length).toBe(0); |
363 | 383 |
|
364 | 384 | expect(navigableLi.length).toBe(0); |
365 | | - }); |
| 385 | + })); |
366 | 386 |
|
367 | | - it('should move back to the first step from the second step, after clicking on the corresponding link', () => { |
| 387 | + it('should move back to the first step from the second step, after clicking on the corresponding link', fakeAsync(() => { |
368 | 388 | const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) a')).nativeElement; |
369 | 389 |
|
370 | 390 | expect(wizardState.currentStepIndex).toBe(0); |
371 | 391 |
|
372 | 392 | // go to the second step |
373 | 393 | navigationMode.goToNextStep(); |
| 394 | + tick(); |
| 395 | + wizardTestFixture.detectChanges(); |
| 396 | + |
374 | 397 | expect(wizardState.currentStepIndex).toBe(1); |
375 | 398 |
|
376 | 399 | // go back to the first step |
377 | 400 | goToFirstStepLink.click(); |
| 401 | + tick(); |
378 | 402 | wizardTestFixture.detectChanges(); |
379 | 403 |
|
380 | 404 | expect(wizardState.currentStepIndex).toBe(0); |
381 | | - }); |
| 405 | + })); |
382 | 406 |
|
383 | | - it('should move back to the first step from the third step, after clicking on the corresponding link', () => { |
| 407 | + it('should move back to the first step from the third step, after clicking on the corresponding link', fakeAsync(() => { |
384 | 408 | const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) a')).nativeElement; |
385 | 409 |
|
386 | 410 | expect(wizardState.currentStepIndex).toBe(0); |
387 | 411 |
|
388 | 412 | // go to the second step |
389 | 413 | navigationMode.goToStep(2); |
| 414 | + tick(); |
| 415 | + wizardTestFixture.detectChanges(); |
| 416 | + |
390 | 417 | expect(wizardState.currentStepIndex).toBe(2); |
391 | 418 |
|
392 | 419 | // go back to the first step |
393 | 420 | goToFirstStepLink.click(); |
| 421 | + tick(); |
394 | 422 | wizardTestFixture.detectChanges(); |
395 | 423 |
|
396 | 424 | expect(wizardState.currentStepIndex).toBe(0); |
397 | | - }); |
| 425 | + })); |
398 | 426 |
|
399 | | - it('should move back to the second step from the third step, after clicking on the corresponding link', () => { |
| 427 | + it('should move back to the second step from the third step, after clicking on the corresponding link', fakeAsync(() => { |
400 | 428 | const goToSecondStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(2) a')).nativeElement; |
401 | 429 |
|
402 | 430 | expect(wizardState.currentStepIndex).toBe(0); |
403 | 431 |
|
404 | 432 | // go to the second step |
405 | 433 | navigationMode.goToStep(2); |
| 434 | + tick(); |
| 435 | + wizardTestFixture.detectChanges(); |
| 436 | + |
406 | 437 | expect(wizardState.currentStepIndex).toBe(2); |
407 | 438 |
|
408 | 439 | // go back to the first step |
409 | 440 | goToSecondStepLink.click(); |
| 441 | + tick(); |
410 | 442 | wizardTestFixture.detectChanges(); |
411 | 443 |
|
412 | 444 | expect(wizardState.currentStepIndex).toBe(1); |
413 | | - }); |
| 445 | + })); |
414 | 446 |
|
415 | 447 | it('should not move to the second step from the first step, after clicking on the corresponding link', () => { |
416 | 448 | const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1)')); |
|
0 commit comments