-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstepper.spec.ts
More file actions
1462 lines (1138 loc) · 46 KB
/
stepper.spec.ts
File metadata and controls
1462 lines (1138 loc) · 46 KB
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { elementUpdated, expect } from '@open-wc/testing';
import { spy } from 'sinon';
import { defineComponents } from '../../index.js';
import IgcStepComponent from './step.js';
import {
PARTS,
SLOTS,
StepperTestFunctions,
linearModeStepper,
simpleStepper,
stepperActiveDisabledSteps,
} from './stepper-utils.spec.js';
import IgcStepperComponent from './stepper.js';
describe('Stepper', () => {
before(() => {
defineComponents(IgcStepperComponent);
});
let stepper: IgcStepperComponent;
let eventSpy: any;
describe('Basic', async () => {
beforeEach(async () => {
stepper = await StepperTestFunctions.createStepperElement(simpleStepper);
});
it('Should render a horizontal stepper containing a sequence of steps', async () => {
// stepper.steps should return all steps
expect(stepper.steps.length).to.equal(5);
expect(stepper).to.contain('igc-step');
expect(stepper.getAttribute('orientation')).to.not.be.null;
expect(stepper.getAttribute('orientation')).to.equal('horizontal');
// Verify step slots are rendered successfully and elements are correctly displayed.
stepper.steps.forEach((step, index) => {
const indicatorSlot = StepperTestFunctions.getSlot(
step,
SLOTS.indicator
);
expect(indicatorSlot).not.to.be.null;
const titleSlot = StepperTestFunctions.getSlot(step, SLOTS.title);
expect(titleSlot).not.to.be.null;
// the last slot is unnamed and is where the step content is rendered
const slots = step.shadowRoot!.querySelectorAll('slot');
const childrenSlot = Array.from(slots).filter(
(s) => s.name === ''
)[0] as HTMLSlotElement;
expect(childrenSlot).not.to.be.null;
expect(childrenSlot.assignedElements()[0].textContent).to.equal(
`STEP ${index + 1} CONTENT`
);
});
});
it('Should expand a step through API by activating it', async () => {
const step = stepper.steps[1];
stepper.navigateTo(1);
await elementUpdated(stepper);
expect(step.active).to.be.true;
expect(step).to.have.attribute('active');
});
it('Should expand a step through UI by activating it', async () => {
const step = stepper.steps[1];
const stepHeader = step.shadowRoot!.querySelector(
PARTS.header
) as HTMLElement;
stepHeader?.dispatchEvent(new MouseEvent('click'));
await elementUpdated(stepper);
expect(step.active).to.be.true;
expect(step).to.have.attribute('active');
});
it('Should not allow activating a step with the next/prev methods when disabled is set to true', async () => {
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
step1.disabled = true;
await elementUpdated(stepper);
expect(step1).to.have.attribute('disabled');
stepper.next();
expect(step1.active).to.be.false;
expect(step2.active).to.be.true;
stepper.prev();
expect(step1.active).to.be.false;
expect(step0.active).to.be.true;
});
it('Should do nothing when all steps are not accessible and next/prev methods are called', async () => {
stepper.steps[1].active = true;
stepper.steps.forEach((step) => {
step.disabled = true;
});
await elementUpdated(stepper);
stepper.next();
await elementUpdated(stepper);
expect(stepper.steps[1].active).to.be.true;
stepper.prev();
await elementUpdated(stepper);
expect(stepper.steps[1].active).to.be.true;
});
it('Should not allow activating more than one step at a time', async () => {
stepper = await StepperTestFunctions.createStepperElement(
stepperActiveDisabledSteps
);
// the first two steps are set to be active initially
// should be activated only the last one
expect(stepper.steps[0].active).to.be.false;
expect(stepper.steps[1].active).to.be.true;
});
it('Should not change the active step when the navigateTo method is called with a mismatched index', async () => {
stepper.navigateTo(999);
await elementUpdated(stepper);
expect(stepper.steps[0].active).to.be.true;
expect(stepper.steps[0]).to.have.attribute('active');
});
it('Should properly set the active state of the steps when the active step is removed dynamically', async () => {
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
expect(step0.active).to.be.true;
stepper.removeChild(step0);
await elementUpdated(stepper);
expect(step1.active).to.be.true;
});
it('Should activate a step when it is set to be active and disabled initially', async () => {
stepper = await StepperTestFunctions.createStepperElement(
stepperActiveDisabledSteps
);
// the step at index 1 is set to be disabled and active initially
expect(stepper.steps[1].disabled).to.be.true;
expect(stepper.steps[1].active).to.be.true;
});
it('Should properly set the active step of the stepper when an active step is added dynamically', async () => {
// initially the step at index 0 is the active step
expect(stepper.steps[0].active).to.be.true;
const newStepAtIndex0 = document.createElement(IgcStepComponent.tagName);
newStepAtIndex0.active = true;
// add an active step before the currently active step in the stepper
stepper.prepend(newStepAtIndex0);
await elementUpdated(stepper);
// the newly added step shouldn't be the active step of the stepper
expect(newStepAtIndex0.active).to.be.false;
expect(newStepAtIndex0.visited).to.be.false;
expect(stepper.steps[1].active).to.be.true;
const newStepAtIndex2 = document.createElement(IgcStepComponent.tagName);
newStepAtIndex2.active = true;
// add an active step after the currently active step in the stepper
stepper.insertBefore(newStepAtIndex2, stepper.steps[2]);
await elementUpdated(stepper);
// the newly added step should be the active step of the stepper
expect(newStepAtIndex2.active).to.be.true;
expect(newStepAtIndex2.visited).to.be.true;
expect(stepper.steps[1].active).to.be.false;
});
it('Should emit ing and ed events when a step is activated through UI', async () => {
eventSpy = spy(stepper, 'emitEvent');
await elementUpdated(stepper);
const argsIng = {
detail: {
owner: stepper,
oldIndex: 0,
newIndex: 1,
},
cancelable: true,
};
const argsEd = {
detail: {
owner: stepper,
index: 1,
},
};
const stepHeader = stepper.steps[1].shadowRoot!.querySelector(
PARTS.header
) as HTMLElement;
stepHeader?.dispatchEvent(new MouseEvent('click'));
await elementUpdated(stepper);
expect(eventSpy.callCount).to.equal(2);
expect(eventSpy.firstCall).calledWith('igcActiveStepChanging', argsIng);
expect(eventSpy.secondCall).calledWith('igcActiveStepChanged', argsEd);
});
it('Should not emit events when a step is activated through API', async () => {
eventSpy = spy(stepper, 'emitEvent');
await elementUpdated(stepper);
expect(stepper.steps[0].active).to.be.true;
stepper.next();
await elementUpdated(stepper);
expect(stepper.steps[1].active).to.be.true;
expect(eventSpy.callCount).to.equal(0);
stepper.prev();
await elementUpdated(stepper);
expect(stepper.steps[0].active).to.be.true;
expect(eventSpy.callCount).to.equal(0);
stepper.navigateTo(2);
await elementUpdated(stepper);
expect(stepper.steps[2].active).to.be.true;
expect(eventSpy.callCount).to.equal(0);
});
it('Should be able to cancel the igcActiveStepChanging event', async () => {
stepper.addEventListener('igcActiveStepChanging', (event) => {
event.preventDefault();
});
const stepHeader = stepper.steps[1].shadowRoot!.querySelector(
PARTS.header
) as HTMLElement;
stepHeader?.dispatchEvent(new MouseEvent('click'));
await elementUpdated(stepper);
expect(stepper.steps[1].active).to.be.false;
expect(stepper.steps[0].active).to.be.true;
});
it('Should not mark a step as visited if it has not been activated before', async () => {
stepper = await StepperTestFunctions.createStepperElement(
stepperActiveDisabledSteps
);
// two steps are set to be active initially
expect(stepper.steps[0].visited).to.be.false;
expect(stepper.steps[1].visited).to.be.true;
stepper.steps[3].active = true;
await elementUpdated(stepper);
// the step at index 2 has not been activated before
expect(stepper.steps[2].visited).to.be.false;
const newStep = document.createElement(IgcStepComponent.tagName);
stepper.insertBefore(newStep, stepper.steps[3]);
await elementUpdated(stepper);
// the newly added step is inserted before the active step and has not been activated yet
expect(newStep.visited).to.be.false;
});
it('Should determine the steps that are marked as visited based on the active step in linear mode', async () => {
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
const step4 = stepper.steps[4];
step4.active = true;
await elementUpdated(stepper);
expect(step4.visited).to.be.true;
step2.active = true;
await elementUpdated(stepper);
// when linear mode is enabled all steps before the active one should be marked as visited
// and all steps after that as not visited
stepper.linear = true;
await elementUpdated(stepper);
expect(step4.visited).to.be.false;
expect(step1.visited).to.be.true;
});
it('Should activate the first accessible step and clear the visited steps collection when the stepper is reset', async () => {
// "visit" some steps
for (const step of stepper.steps) {
step.active = true;
await elementUpdated(stepper);
expect(step.visited).to.be.true;
}
stepper.reset();
await elementUpdated(stepper);
expect(stepper.steps[0].active).to.be.true;
expect(stepper.steps[0].visited).to.be.true;
expect(stepper.steps[1].visited).to.be.false;
expect(stepper.steps[2].visited).to.be.false;
});
it('Should determine the steps that are disabled in linear mode based on the validity of the active step', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
// the optional state is set to true initially
step0.optional = false;
await elementUpdated(stepper);
for (let i = 1; i < stepper.steps.length; i++) {
expect(stepper.steps[i].isAccessible).to.be.false;
}
step0.invalid = false;
await elementUpdated(stepper);
expect(step1.isAccessible).to.be.true;
expect(step2.isAccessible).to.be.false;
step1.invalid = false;
await elementUpdated(stepper);
expect(step2.isAccessible).to.be.true;
});
it('Should not allow moving forward to the next step in linear mode if the previous step is invalid', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
// the optional state is set to true initially
step0.optional = false;
await elementUpdated(stepper);
expect(step0.invalid).to.be.true;
expect(step0).to.have.attribute('invalid');
stepper.next();
await elementUpdated(stepper);
expect(step1.active).to.be.false;
expect(step0.active).to.be.true;
expect(step1.linearDisabled).to.be.true;
expect(step2.linearDisabled).to.be.true;
});
it('Should set a step to be accessible in linear mode if the previous accessible step is being disabled', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
stepper.steps[0].invalid = false;
await elementUpdated(stepper);
expect(stepper.steps[1].isAccessible).to.be.true;
expect(stepper.steps[2].isAccessible).to.be.false;
stepper.steps[1].disabled = true;
await elementUpdated(stepper);
expect(stepper.steps[2].isAccessible).to.be.true;
});
it('Should set a step to be not accessible in linear mode if before it is inserted a new invalid step', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
step0.invalid = false;
await elementUpdated(stepper);
expect(step1.isAccessible).to.be.true;
const newStep = document.createElement(IgcStepComponent.tagName);
newStep.invalid = true;
await elementUpdated(stepper);
stepper.insertBefore(newStep, step1);
await elementUpdated(stepper);
expect(newStep.isAccessible).to.be.true;
expect(step1.isAccessible).to.be.false;
});
it('Should properly set the linear disabled steps when the active step is removed from the DOM', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
step0.invalid = false;
step1.active = true;
await elementUpdated(stepper);
expect(step2.isAccessible).to.be.false;
stepper.removeChild(step1);
await elementUpdated(stepper);
expect(step0.active).to.be.true;
expect(step2.isAccessible).to.be.true;
});
it('Should set a step to be accessible if the previous one is being removed from the DOM and was accessible before that', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
step0.invalid = false;
await elementUpdated(stepper);
expect(step1.isAccessible).to.be.true;
expect(step2.isAccessible).to.be.false;
stepper.removeChild(step1);
await elementUpdated(stepper);
expect(step2.isAccessible).to.be.true;
});
it('Should set a newly added step to be accessible if is inserted before the active step', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
const newStep = document.createElement(IgcStepComponent.tagName);
await elementUpdated(stepper);
stepper.prepend(newStep);
expect(newStep.isAccessible).to.be.true;
});
it("Should not set previous steps to be accessible if a linear disabled step's invalid or disabled states are changed through API", async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
// the optional state is set to true initially
stepper.steps[0].optional = false;
await elementUpdated(stepper);
stepper.navigateTo(2);
await elementUpdated(stepper);
// the step at index 1 should not be accessible because the previous one is required and invalid
expect(stepper.steps[1].isAccessible).to.be.false;
stepper.steps[2].disabled = true;
await elementUpdated(stepper);
expect(stepper.steps[1].isAccessible).to.be.false;
stepper.steps[2].invalid = true;
await elementUpdated(stepper);
expect(stepper.steps[1].isAccessible).to.be.false;
});
it('Should set a step to be accessible in linear mode if the previous one is accessible and optional', async () => {
stepper =
await StepperTestFunctions.createStepperElement(linearModeStepper);
// the step at index 0 is set to be invalid and optional initially
expect(stepper.steps[1].isAccessible).to.be.true;
// test whether a step will become accessible when the previous step is invalid but is accessible and optional
stepper.steps[1].optional = true;
await elementUpdated(stepper);
expect(stepper.steps[2].isAccessible).to.be.true;
});
});
describe('Appearance', async () => {
beforeEach(async () => {
stepper = await StepperTestFunctions.createStepperElement(simpleStepper);
});
it('Should apply the appropriate attribute to a stepper in a horizontal and vertical orientation', async () => {
expect(stepper.orientation).to.equal('horizontal');
stepper.orientation = 'vertical';
await elementUpdated(stepper);
expect(stepper.attributes.getNamedItem('orientation')?.value).to.equal(
'vertical'
);
stepper.orientation = 'horizontal';
await elementUpdated(stepper);
expect(stepper.attributes.getNamedItem('orientation')?.value).to.equal(
'horizontal'
);
});
it("Should properly render the step's layout", () => {
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
const stepHeader = StepperTestFunctions.getElementByPart(
step,
PARTS.header
) as HTMLElement;
const stepBody = StepperTestFunctions.getElementByPart(
step,
PARTS.body
) as HTMLElement;
expect(stepHeaderContainer).not.to.be.null;
expect(stepHeader).not.to.be.null;
expect(stepBody).not.to.be.null;
}
});
it('Should apply the appropriate part to the header container of a step that is disabled or linear disabled', async () => {
stepper.steps[0].disabled = true;
await elementUpdated(stepper);
const step0HeaderContainer = StepperTestFunctions.getElementByPart(
stepper.steps[0],
PARTS.headerContainer
) as HTMLElement;
expect(step0HeaderContainer.part.contains('disabled')).to.be.true;
stepper.linear = true;
await elementUpdated(stepper);
stepper.steps[1].invalid = true;
await elementUpdated(stepper);
const step2HeaderContainer = StepperTestFunctions.getElementByPart(
stepper.steps[2],
PARTS.headerContainer
) as HTMLElement;
expect(step2HeaderContainer.part.contains('disabled')).to.be.true;
});
it('Should indicate that a step is completed', async () => {
expect(stepper.steps[0].complete).to.be.false;
expect(stepper.steps[0]).to.not.have.attribute('complete');
stepper.steps[0].complete = true;
await elementUpdated(stepper);
expect(stepper.steps[0]).to.have.attribute('complete');
stepper.steps[1].complete = true;
await elementUpdated(stepper);
expect(stepper.steps[1]).to.have.attribute('complete');
});
it('Should properly indicate where a completed step starts and ends', async () => {
const step0 = stepper.steps[0];
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
const step0HeaderContainer = StepperTestFunctions.getElementByPart(
step0,
PARTS.headerContainer
) as HTMLElement;
const step1HeaderContainer = StepperTestFunctions.getElementByPart(
step1,
PARTS.headerContainer
) as HTMLElement;
const step2HeaderContainer = StepperTestFunctions.getElementByPart(
step2,
PARTS.headerContainer
) as HTMLElement;
step0.complete = true;
step1.complete = true;
await elementUpdated(stepper);
expect(step0).to.have.attribute('complete');
expect(step1).to.have.attribute('complete');
expect(step0HeaderContainer.part.contains('complete-start')).to.be.true;
expect(step0HeaderContainer.part.contains('complete-end')).to.be.false;
expect(step1HeaderContainer.part.contains('complete-start')).to.be.true;
expect(step1HeaderContainer.part.contains('complete-end')).to.be.true;
expect(step2HeaderContainer.part.contains('complete-end')).to.be.true;
expect(step2HeaderContainer.part.contains('complete-start')).to.be.false;
step2.complete = true;
await elementUpdated(stepper);
expect(step2HeaderContainer.part.contains('complete-start')).to.be.true;
expect(step2HeaderContainer.part.contains('complete-end')).to.be.true;
// should properly indicate whether the previous step of a newly added step is completed
const newStep = document.createElement(IgcStepComponent.tagName);
stepper.append(newStep);
await elementUpdated(stepper);
const step3HeaderContainer = StepperTestFunctions.getElementByPart(
stepper.steps[3],
PARTS.headerContainer
) as HTMLElement;
expect(step3HeaderContainer.part.contains('complete-end')).to.be.true;
step2.complete = false;
await elementUpdated(stepper);
expect(step3HeaderContainer.part.contains('complete-end')).to.be.false;
// should indicate the complete state of the previous step when the step between them is removed from the DOM
stepper.removeChild(step2);
await elementUpdated(stepper);
expect(step3HeaderContainer.part.contains('complete-end')).to.be.true;
});
it('Should apply the appropriate part to the header container of an optional step', async () => {
stepper.steps[0].optional = true;
await elementUpdated(stepper);
const step0HeaderContainer = StepperTestFunctions.getElementByPart(
stepper.steps[0],
PARTS.headerContainer
) as HTMLElement;
expect(step0HeaderContainer.part.contains('optional')).to.be.true;
});
it('Should indicate that a step is invalid', async () => {
expect(stepper.steps[0].invalid).to.be.false;
expect(stepper.steps[0]).to.not.have.attribute('invalid');
stepper.steps[0].invalid = true;
await elementUpdated(stepper);
expect(stepper.steps[0]).to.have.attribute('invalid');
stepper.steps[1].invalid = true;
await elementUpdated(stepper);
expect(stepper.steps[0]).to.have.attribute('invalid');
});
it('Should apply the appropriate part to the header container of an invalid step', async () => {
const step1 = stepper.steps[1];
const step1HeaderContainer = StepperTestFunctions.getElementByPart(
step1,
PARTS.headerContainer
) as HTMLElement;
step1.invalid = true;
await elementUpdated(stepper);
// the step at index 1 is accessible but its invalid state is set to false
expect(step1.isAccessible).to.be.true;
expect(step1HeaderContainer.part.contains('invalid')).to.be.false;
// the invalid state is set to true but the step is not visited yet
expect(step1HeaderContainer.part.contains('invalid')).to.be.false;
step1.active = true;
await elementUpdated(stepper);
// the step is visited but is the currently active step
expect(step1HeaderContainer.part.contains('invalid')).to.be.false;
stepper.steps[2].active = true;
await elementUpdated(stepper);
// the step is accessible, invalid, visited and is not the currently active step
expect(step1HeaderContainer.part.contains('invalid')).to.be.true;
});
it('Should apply the appropriate part to the header container of a step that has no title and subtitle', async () => {
stepper = await StepperTestFunctions.createStepperElement(
stepperActiveDisabledSteps
);
stepper.stepType = 'indicator';
await elementUpdated(stepper);
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const stepHeaderTitleAndSubtitleWrapper =
StepperTestFunctions.getElementByPart(
step,
PARTS.text
) as HTMLElement;
expect(stepHeaderTitleAndSubtitleWrapper.part.contains('empty')).to.be
.true;
}
stepper.stepType = 'full';
await elementUpdated(stepper);
// the step at index 2 has not title and subtitle
const step2 = stepper.steps[2];
const step2HeaderTitleAndSubtitleWrapper =
StepperTestFunctions.getElementByPart(step2, PARTS.text) as HTMLElement;
expect(step2HeaderTitleAndSubtitleWrapper.part.contains('empty')).to.be
.true;
});
it('Should indicate which is the currently active step', async () => {
const step1 = stepper.steps[1];
const step2 = stepper.steps[2];
step1.active = true;
await elementUpdated(stepper);
expect(step1).to.have.attribute('active');
step2.active = true;
await elementUpdated(stepper);
expect(step1).to.have.not.attribute('active');
expect(step2).to.have.attribute('active');
});
it('Should place the title in the step element according to the specified titlePosition when stepType is set to "full"', async () => {
// test default title positions
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('auto');
expect(stepHeaderContainer.part.contains('bottom')).to.be.true;
}
const positions = ['bottom', 'top', 'end', 'start'];
for (const pos of positions) {
stepper.titlePosition = pos as any;
await elementUpdated(stepper);
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal(pos);
expect(stepHeaderContainer.part.contains(pos)).to.be.true;
}
}
stepper.orientation = 'vertical';
stepper.titlePosition = 'auto';
await elementUpdated(stepper);
// test default title positions
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('auto');
expect(stepHeaderContainer.part.contains('end')).to.be.true;
}
for (const pos of positions) {
stepper.titlePosition = pos as any;
await elementUpdated(stepper);
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal(pos);
expect(stepHeaderContainer.part.contains(pos)).to.be.true;
}
}
stepper.orientation = 'horizontal';
stepper.titlePosition = 'top';
await elementUpdated(stepper);
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('top');
expect(stepHeaderContainer.part.contains('top')).to.be.true;
}
stepper.orientation = 'vertical';
await elementUpdated(stepper);
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('top');
expect(stepHeaderContainer.part.contains('top')).to.be.true;
}
// set to the default title position
stepper.orientation = 'horizontal';
stepper.titlePosition = 'auto';
await elementUpdated(stepper);
// test default title positions
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('auto');
expect(stepHeaderContainer.part.contains('bottom')).to.be.true;
}
stepper.orientation = 'vertical';
await elementUpdated(stepper);
// test default title positions
for (const step of stepper.steps) {
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
expect(step.titlePosition).to.equal('auto');
expect(stepHeaderContainer.part.contains('end')).to.be.true;
}
});
it('Should render the visual step element according to the specified stepType', async () => {
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const indicator = StepperTestFunctions.getElementByPart(
step,
PARTS.indicator
) as HTMLElement;
const textWrapper = StepperTestFunctions.getElementByPart(
step,
PARTS.text
) as HTMLElement;
expect(indicator).not.to.be.null;
expect(textWrapper.part.contains('empty')).to.be.false;
}
stepper.stepType = 'indicator';
await elementUpdated(stepper);
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const indicator = StepperTestFunctions.getElementByPart(
step,
PARTS.indicator
) as HTMLElement;
const textWrapper = StepperTestFunctions.getElementByPart(
step,
PARTS.text
) as HTMLElement;
expect(indicator).not.to.be.null;
expect(textWrapper.part.contains('empty')).to.be.true;
}
stepper.stepType = 'title';
await elementUpdated(stepper);
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const indicator = StepperTestFunctions.getElementByPart(
step,
PARTS.indicator
) as HTMLElement;
const textWrapper = StepperTestFunctions.getElementByPart(
step,
PARTS.text
) as HTMLElement;
expect(indicator).to.be.null;
expect(textWrapper.part.contains('empty')).to.be.false;
}
});
it("Should indicate each step with a corresponding number when the steps' indicators are not specified and stepType is either “indicator” or “full”", async () => {
const step3 = stepper.steps[2];
let step3IndicatorElement = StepperTestFunctions.getElementByPart(
step3,
PARTS.indicator
) as HTMLElement;
expect(step3IndicatorElement).not.be.null;
expect(
step3IndicatorElement.children[0].children[0].textContent
).to.equal((step3.index + 1).toString());
stepper.stepType = 'indicator';
await elementUpdated(stepper);
step3IndicatorElement = StepperTestFunctions.getElementByPart(
step3,
PARTS.indicator
) as HTMLElement;
expect(step3IndicatorElement).not.be.null;
expect(
step3IndicatorElement.children[0].children[0].textContent
).to.equal((step3.index + 1).toString());
});
it("Should be able to display the steps' content above the steps headers when the stepper is horizontally orientated", async () => {
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
const stepBody = StepperTestFunctions.getElementByPart(
step,
PARTS.body
) as HTMLElement;
const stepHeaderContainerIndex = Array.from(
step.shadowRoot!.children
).indexOf(stepHeaderContainer);
const stepBodyIndex = Array.from(step.shadowRoot!.children).indexOf(
stepBody
);
expect(stepHeaderContainerIndex).to.be.lessThan(stepBodyIndex);
}
stepper.contentTop = true;
await elementUpdated(stepper);
for (let i = 0; i < stepper.steps.length; i++) {
const step = stepper.steps[i];
const stepHeaderContainer = StepperTestFunctions.getElementByPart(
step,
PARTS.headerContainer
) as HTMLElement;
const stepBody = StepperTestFunctions.getElementByPart(
step,
PARTS.body
) as HTMLElement;
const stepHeaderContainerIndex = Array.from(
step.shadowRoot!.children
).indexOf(stepHeaderContainer);
const stepBodyIndex = Array.from(step.shadowRoot!.children).indexOf(
stepBody
);
expect(stepHeaderContainerIndex).to.be.greaterThan(stepBodyIndex);
}
});
it("Should properly render the step's content in a vertical orientation when contentTop is set to true", async () => {
stepper.orientation = 'vertical';
await elementUpdated(stepper);