-
Notifications
You must be signed in to change notification settings - Fork 98
/
wizard-navigation-bar.component.spec.ts
571 lines (431 loc) · 20.8 KB
/
wizard-navigation-bar.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {Component, DebugElement, ViewChild} from '@angular/core';
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
import {WizardComponent} from './wizard.component';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {NavigationMode} from '../navigation/navigation-mode.interface';
import {WizardState} from '../navigation/wizard-state.model';
@Component({
selector: 'aw-test-wizard',
template: `
<aw-wizard>
<aw-wizard-step stepTitle='Steptitle 1' [stepId]="firstStepId">Step 1</aw-wizard-step>
<aw-wizard-step stepTitle='Steptitle 2' awOptionalStep>Step 2</aw-wizard-step>
<aw-wizard-step stepTitle='Steptitle 3'>Step 3</aw-wizard-step>
</aw-wizard>
`
})
class WizardTestComponent {
public firstStepId = 'step1';
@ViewChild(WizardComponent)
public wizard: WizardComponent;
}
describe('WizardNavigationBarComponent', () => {
let wizardTest: WizardTestComponent;
let wizardTestFixture: ComponentFixture<WizardTestComponent>;
let wizardState: WizardState;
let navigationMode: NavigationMode;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [WizardTestComponent],
imports: [ArchwizardModule]
}).compileComponents();
}));
beforeEach(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();
wizardTest = wizardTestFixture.componentInstance;
wizardState = wizardTestFixture.debugElement.query(By.css('aw-wizard')).injector.get(WizardState);
navigationMode = wizardState.navigationMode;
});
it('should create', () => {
expect(wizardTest).toBeTruthy();
expect(wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'))).toBeTruthy();
});
it('should create only one navigation bar', () => {
expect(wizardTest).toBeTruthy();
expect(wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar')).length).toBe(1);
});
it('should show the initial step correctly', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the first step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[0]);
// no step is currently marked as done
expect(doneLi.length).toBe(0);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// only the second step is marked as optional
expect(optionalLi.length).toBe(1);
expect(optionalLi[0]).toBe(allLi[1]);
// the second and third step is marked as default (neither done or current)
expect(defaultLi.length).toBe(1);
expect(defaultLi[0]).toBe(allLi[2]);
expect(navigableLi.length).toBe(0);
});
it('should show the second step correctly', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to second step
navigationMode.goToNextStep();
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the second step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[1]);
// the first step should be marked as done
expect(doneLi.length).toBe(1);
expect(doneLi[0]).toBe(allLi[0]);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// no step is marked as optional, because the optional step is the current step
expect(optionalLi.length).toBe(0);
// only the third step is marked as default (neither done or current)
expect(defaultLi.length).toBe(1);
expect(defaultLi[0]).toBe(allLi[2]);
expect(navigableLi.length).toBe(1);
expect(navigableLi[0]).toBe(allLi[0]);
}));
it('should show the third step correctly', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to second step
navigationMode.goToNextStep();
tick();
wizardTestFixture.detectChanges();
// go to third step
navigationMode.goToNextStep();
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the third step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[2]);
// the first and second step should be marked as done
expect(doneLi.length).toBe(2);
expect(doneLi[0]).toBe(allLi[0]);
expect(doneLi[1]).toBe(allLi[1]);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// no step is marked as optional, because the optional step is a "done" step
expect(optionalLi.length).toBe(0);
// no step is marked as default (neither done, current or optional)
expect(defaultLi.length).toBe(0);
expect(doneLi.length).toBe(2);
expect(navigableLi[0]).toBe(allLi[0]);
expect(navigableLi[1]).toBe(allLi[1]);
}));
it('should show the third step correctly, after jump from first to third step', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to third step and jump over the optional second step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the third step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[2]);
// the first step should be marked as done
expect(doneLi.length).toBe(1);
expect(doneLi[0]).toBe(allLi[0]);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// the second step is marked as optional, because we jumped over it
expect(optionalLi.length).toBe(1);
expect(optionalLi[0]).toBe(allLi[1]);
// the second step is marked as default (neither done nor current)
expect(defaultLi.length).toBe(0);
expect(navigableLi.length).toBe(2);
expect(navigableLi[0]).toBe(allLi[0]);
expect(navigableLi[1]).toBe(allLi[1]);
}));
it('should show the first step correctly, after going back from the second step to the first step', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to second step
navigationMode.goToNextStep();
tick();
wizardTestFixture.detectChanges();
// go back to first step
navigationMode.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// no step is the current step
expect(currentLi.length).toBe(0);
// no step should be marked as done
expect(doneLi.length).toBe(0);
// the first step is marked as editing
expect(editingLi.length).toBe(1);
expect(editingLi[0]).toBe(allLi[0]);
// the second step is marked as optional
expect(optionalLi.length).toBe(1);
expect(optionalLi[0]).toBe(allLi[1]);
// the second and third step is marked as default (neither done or current)
expect(defaultLi.length).toBe(1);
expect(defaultLi[0]).toBe(allLi[2]);
expect(navigableLi.length).toBe(0);
}));
it('should show the first step correctly, after first jumping from the first to the third step ' +
'and then back from the third step to the first step', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to third step, by jumping over the optional step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
// go back to first step
navigationMode.goToStep(0);
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// no step is the current step
expect(currentLi.length).toBe(0);
// no step should be marked as done
expect(doneLi.length).toBe(0);
// the first step is marked as editing
expect(editingLi.length).toBe(1);
expect(editingLi[0]).toBe(allLi[0]);
// the second step is marked as optional
expect(optionalLi.length).toBe(1);
expect(optionalLi[0]).toBe(allLi[1]);
// the second and third step is marked as default (neither done or current)
expect(defaultLi.length).toBe(1);
expect(defaultLi[0]).toBe(allLi[2]);
expect(navigableLi.length).toBe(0);
}));
it('should show the second step correctly, after first jumping from the first to the third step ' +
'and then back from the third step to the second step', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
// go to third step, by jumping over the optional step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
// go back to second step
navigationMode.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the second step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[1]);
// the first step should be marked as done
expect(doneLi.length).toBe(1);
expect(doneLi[0]).toBe(allLi[0]);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// no step is marked as optional, because the optional step is the current step
expect(optionalLi.length).toBe(0);
// the third step is marked as default (neither done or current)
expect(defaultLi.length).toBe(1);
expect(defaultLi[0]).toBe(allLi[2]);
expect(navigableLi.length).toBe(1);
expect(navigableLi[0]).toBe(allLi[0]);
}));
it('should disable navigation through the navigation bar correctly', fakeAsync(() => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardState.disableNavigationBar = true;
// go to third step and jump over the optional second step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
const allLi = navBar.queryAll(By.css('li'));
const currentLi = navBar.queryAll(By.css('li.current'));
const doneLi = navBar.queryAll(By.css('li.done'));
const editingLi = navBar.queryAll(By.css('li.editing'));
const optionalLi = navBar.queryAll(By.css('li.optional'));
const defaultLi = navBar.queryAll(By.css('li.default'));
const navigableLi = navBar.queryAll(By.css('li.navigable'));
// the third step is the current step
expect(currentLi.length).toBe(1);
expect(currentLi[0]).toBe(allLi[2]);
// the first step should be marked as done
expect(doneLi.length).toBe(1);
expect(doneLi[0]).toBe(allLi[0]);
// no step is marked as editing
expect(editingLi.length).toBe(0);
// the second step is marked as optional, because we jumped over it
expect(optionalLi.length).toBe(1);
expect(optionalLi[0]).toBe(allLi[1]);
// the second step is marked as default (neither done nor current)
expect(defaultLi.length).toBe(0);
expect(navigableLi.length).toBe(0);
}));
it('should move back to the first step from the second step, after clicking on the corresponding link', fakeAsync(() => {
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) a')).nativeElement;
expect(wizardState.currentStepIndex).toBe(0);
// go to the second step
navigationMode.goToNextStep();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(1);
// go back to the first step
goToFirstStepLink.click();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(0);
}));
it('should move back to the first step from the third step, after clicking on the corresponding link', fakeAsync(() => {
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) a')).nativeElement;
expect(wizardState.currentStepIndex).toBe(0);
// go to the second step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(2);
// go back to the first step
goToFirstStepLink.click();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(0);
}));
it('should move back to the second step from the third step, after clicking on the corresponding link', fakeAsync(() => {
const goToSecondStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(2) a')).nativeElement;
expect(wizardState.currentStepIndex).toBe(0);
// go to the second step
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(2);
// go back to the first step
goToSecondStepLink.click();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(1);
}));
it('should not move to the second step from the first step, after clicking on the corresponding link', () => {
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1)'));
const goToSecondStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(2)'));
const goToThirdStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(3)'));
expect(wizardState.currentStepIndex).toBe(0);
// links contain a class that is not clickable (contains "pointer-events: none;")
expect(goToFirstStepLink.classes.hasOwnProperty('current')).toBeTruthy('First step label is clickable');
expect(goToSecondStepLink.classes.hasOwnProperty('default')).toBeTruthy('Second step label is clickable');
expect(goToThirdStepLink.classes.hasOwnProperty('default')).toBeTruthy('Third step label is clickable');
});
it('should use the \"small\" layout when no navigation bar layout is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': true,
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
});
});
it('should use the \"small\" layout when it is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardTest.wizard.navBarLayout = 'small';
wizardTestFixture.detectChanges();
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': true,
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
});
});
it('should use the \"large-filled\" layout when it is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardTest.wizard.navBarLayout = 'large-filled';
wizardTestFixture.detectChanges();
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': false,
'large-filled': true, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
});
});
it('should use the \"large-empty\" layout when it is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardTest.wizard.navBarLayout = 'large-empty';
wizardTestFixture.detectChanges();
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': false,
'large-filled': false, 'large-filled-symbols': false, 'large-empty': true, 'large-empty-symbols': false
});
});
it('should use the \"large-filled-symbols\" layout when it is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardTest.wizard.navBarLayout = 'large-filled-symbols';
wizardTestFixture.detectChanges();
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': false,
'large-filled': false, 'large-filled-symbols': true, 'large-empty': false, 'large-empty-symbols': false
});
});
it('should use the \"large-empty-symbols\" layout when it is specified', () => {
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
wizardTest.wizard.navBarLayout = 'large-empty-symbols';
wizardTestFixture.detectChanges();
expect(navBar.classes).toEqual({
'horizontal': true, 'vertical': false, 'small': false,
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': true
});
});
it('should show the correct step titles', () => {
let navigationLinks = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li a'));
expect(navigationLinks.length).toBe(3);
expect(navigationLinks[0].nativeElement.innerText).toBe('STEPTITLE 1');
expect(navigationLinks[1].nativeElement.innerText).toBe('STEPTITLE 2');
expect(navigationLinks[2].nativeElement.innerText).toBe('STEPTITLE 3');
});
it('should show the correct reversed step titles', () => {
wizardTest.wizard.navBarDirection = 'right-to-left';
wizardTestFixture.detectChanges();
let navigationLinks = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li a'));
expect(navigationLinks.length).toBe(3);
expect(navigationLinks[0].nativeElement.innerText).toBe('STEPTITLE 3');
expect(navigationLinks[1].nativeElement.innerText).toBe('STEPTITLE 2');
expect(navigationLinks[2].nativeElement.innerText).toBe('STEPTITLE 1');
});
it('should have the correct stepId', () => {
const navigationLiElements = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li'));
expect(navigationLiElements.length).toBe(3);
expect(navigationLiElements[0].nativeElement.id).toBe('step1');
expect(navigationLiElements[1].nativeElement.id).toBe('');
expect(navigationLiElements[2].nativeElement.id).toBe('');
});
it('should change the stepId correctly', () => {
wizardTest.firstStepId = null;
wizardTestFixture.detectChanges();
const navigationLiElements = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li'));
expect(navigationLiElements.length).toBe(3);
expect(navigationLiElements[0].nativeElement.id).toBe('');
expect(navigationLiElements[1].nativeElement.id).toBe('');
expect(navigationLiElements[2].nativeElement.id).toBe('');
});
});