Skip to content

Commit 894f859

Browse files
author
ddaribo
committed
feat(stepper): test animations with other values
1 parent f8f98d3 commit 894f859

File tree

1 file changed

+68
-57
lines changed

1 file changed

+68
-57
lines changed

projects/igniteui-angular/src/lib/stepper/stepper.component.spec.ts

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ const getStepperPositions = (): string[] => {
4848
return positions;
4949
};
5050

51+
const testAnimationBehvior = (
52+
val: any,
53+
fix: ComponentFixture<IgxStepperSampleTestComponent>,
54+
isHorAnimTypeInvalidTest: boolean
55+
): void => {
56+
const stepper = fix.componentInstance.stepper;
57+
stepper.steps[0].active = true;
58+
fix.detectChanges();
59+
const previousActiveStep = stepper.steps[0];
60+
const activeChangeSpy = spyOn(previousActiveStep.activeChange, 'emit');
61+
activeChangeSpy.calls.reset();
62+
stepper.next();
63+
fix.detectChanges();
64+
tick(1000);
65+
if (!isHorAnimTypeInvalidTest) {
66+
expect(previousActiveStep.activeChange.emit).withContext(val).toHaveBeenCalledOnceWith(false);
67+
} else {
68+
expect(previousActiveStep.activeChange.emit).withContext(val).not.toHaveBeenCalled();
69+
}
70+
activeChangeSpy.calls.reset();
71+
};
72+
5173
describe('Rendering Tests', () => {
5274
configureTestSuite();
5375
let fix: ComponentFixture<IgxStepperSampleTestComponent>;
@@ -205,7 +227,7 @@ describe('Rendering Tests', () => {
205227

206228
const testValues = [null, undefined, [], {}, 'sampleString'];
207229

208-
for(const val of testValues){
230+
for (const val of testValues) {
209231
stepper.navigateTo(val as any);
210232
fix.detectChanges();
211233
expect(changingSpy).not.toHaveBeenCalled();
@@ -421,7 +443,7 @@ describe('Rendering Tests', () => {
421443
fix.detectChanges();
422444

423445
let positions = getStepperPositions();
424-
positions.forEach((pos: string) => {
446+
positions.forEach((pos: IgxStepperTitlePosition) => {
425447
stepper.horizontalTitlePosition = pos;
426448
fix.detectChanges();
427449

@@ -434,7 +456,7 @@ describe('Rendering Tests', () => {
434456
fix.detectChanges();
435457

436458
positions = getStepperPositions();
437-
positions.forEach((pos: string) => {
459+
positions.forEach((pos: IgxStepperTitlePosition) => {
438460
stepper.verticalTitlePosition = pos;
439461
fix.detectChanges();
440462

@@ -514,59 +536,57 @@ describe('Rendering Tests', () => {
514536
expect(stepper.nativeElement.children[1]).toHaveClass(STEPPER_HEADER);
515537
});
516538

517-
it('should allow modifying animationSettings that are used for transitioning between steps ', () => {
518-
stepper.orientation = IgxStepperOrientation.Horizontal;
519-
fix.detectChanges();
520-
521-
expect(stepper.animationDuration).toBe(fix.componentInstance.animationDuration);
522-
fix.componentInstance.animationDuration = 1000;
523-
fix.detectChanges();
524-
525-
expect(stepper.animationDuration).toBe(1000);
526-
527-
fix.componentInstance.animationDuration = null;
528-
fix.detectChanges();
539+
it('should allow modifying animationSettings that are used for transitioning between steps ', fakeAsync(() => {
540+
const numericTestValues = [100, 1000];
529541

530-
expect(stepper.animationDuration).toBe((stepper as any)._defaultAnimationDuration);
542+
for (const val of numericTestValues) {
543+
fix.componentInstance.animationDuration = val as any;
544+
testAnimationBehvior(val, fix, false);
545+
}
531546

532-
fix.componentInstance.animationDuration = undefined;
533-
fix.detectChanges();
547+
const dummyTestValues = [-1, 'sampleString', [], {}];
534548

535-
expect(stepper.animationDuration).toBe((stepper as any)._defaultAnimationDuration);
549+
for (const val of dummyTestValues) {
550+
expect(() => {
551+
fix.componentInstance.animationDuration = val as any;
552+
testAnimationBehvior(val, fix, false);
553+
}).toThrow();
554+
}
536555

537-
expect(stepper.horizontalAnimationType).toBe(fix.componentInstance.horizontalAnimationType);
538-
expect(stepper.horizontalAnimationType).toBe('slide');
556+
const fallbackToDefaultValues = [0, null];
557+
for (const val of fallbackToDefaultValues) {
558+
fix.componentInstance.animationDuration = val as any;
559+
fix.detectChanges();
560+
expect(stepper.animationDuration).withContext('Set 0/null animation duration and verify default value')
561+
.toBe((stepper as any)._defaultAnimationDuration);
562+
testAnimationBehvior(val, fix, false);
563+
}
539564

540-
fix.componentInstance.horizontalAnimationType = 'fade';
565+
fix.componentInstance.animationDuration = 300;
566+
stepper.orientation = IgxStepperOrientation.Horizontal;
541567
fix.detectChanges();
542568

543-
expect(stepper.horizontalAnimationType).toBe(fix.componentInstance.horizontalAnimationType);
544-
expect(stepper.horizontalAnimationType).toBe('fade');
545-
546-
fix.componentInstance.horizontalAnimationType = 'none';
547-
fix.detectChanges();
569+
const horAnimTypeValidValues = ['slide', 'fade', 'none'];
570+
for (const val of horAnimTypeValidValues) {
571+
fix.componentInstance.horizontalAnimationType = val as any;
572+
testAnimationBehvior(val, fix, false);
573+
}
548574

549-
expect(stepper.horizontalAnimationType).toBe(fix.componentInstance.horizontalAnimationType);
550-
expect(stepper.horizontalAnimationType).toBe('none');
575+
const horAnimTypeTestValues = ['sampleString', null, undefined, 0, [], {}];
576+
for (const val of horAnimTypeTestValues) {
577+
fix.componentInstance.horizontalAnimationType = val as any;
578+
testAnimationBehvior(val, fix, true);
579+
}
551580

552581
stepper.orientation = IgxStepperOrientation.Vertical;
553582
fix.detectChanges();
554583

555-
expect(stepper.verticalAnimationType).toBe(fix.componentInstance.verticalAnimationType);
556-
fix.componentInstance.verticalAnimationType = 'grow';
557-
558-
fix.componentInstance.verticalAnimationType = 'fade';
559-
fix.detectChanges();
560-
561-
expect(stepper.verticalAnimationType).toBe(fix.componentInstance.verticalAnimationType);
562-
expect(stepper.verticalAnimationType).toBe('fade');
563-
564-
fix.componentInstance.verticalAnimationType = 'none';
565-
fix.detectChanges();
566-
567-
expect(stepper.verticalAnimationType).toBe(fix.componentInstance.verticalAnimationType);
568-
expect(stepper.verticalAnimationType).toBe('none');
569-
});
584+
const vertAnimTypeTestValues = ['fade', 'grow', 'none', 'sampleString', null, undefined, 0, [], {}];
585+
for (const val of vertAnimTypeTestValues) {
586+
fix.componentInstance.verticalAnimationType = val as any;
587+
testAnimationBehvior(val, fix, false);
588+
}
589+
}));
570590

571591
it('should render dynamically added step and properly set the linear disabled steps with its addition', fakeAsync(() => {
572592
const stepsLength = stepper.steps.length;
@@ -670,14 +690,7 @@ describe('Rendering Tests', () => {
670690
it('should properly collapse the previously active step in horizontal orientation and animation type \'fade\'', fakeAsync(() => {
671691
stepper.orientation = IgxStepperOrientation.Horizontal;
672692
stepper.horizontalAnimationType = 'fade';
673-
stepper.steps[0].active = true;
674-
fix.detectChanges();
675-
676-
const previousActiveStep = stepper.steps[0];
677-
spyOn(previousActiveStep.activeChange, 'emit');
678-
679-
stepper.next();
680-
expect(previousActiveStep.activeChange.emit).toHaveBeenCalledOnceWith(false);
693+
testAnimationBehvior('fade', fix, false);
681694
}));
682695
});
683696

@@ -1011,7 +1024,7 @@ describe('Stepper service unit tests', () => {
10111024

10121025
const testValues = [null, undefined, [], {}, 'sampleString'];
10131026

1014-
for(const val of testValues){
1027+
for (const val of testValues) {
10151028
expect(() => {
10161029
stepperService.expand(val as any);
10171030
}).toThrow();
@@ -1048,7 +1061,7 @@ describe('Stepper service unit tests', () => {
10481061

10491062
const testValues = [null, undefined, [], {}, 'sampleString'];
10501063

1051-
for(const val of testValues){
1064+
for (const val of testValues) {
10521065
expect(() => {
10531066
stepperService.expandThroughApi(val as any);
10541067
}).toThrow();
@@ -1101,7 +1114,7 @@ describe('Stepper service unit tests', () => {
11011114

11021115
const testValues = [null, undefined, [], {}, 'sampleString'];
11031116

1104-
for(const val of testValues){
1117+
for (const val of testValues) {
11051118
expect(() => {
11061119
stepperService.collapse(val as any);
11071120
}).toThrow();
@@ -1297,5 +1310,3 @@ export class IgxStepperSampleTestComponent {
12971310
public displayHiddenStep = false;
12981311

12991312
}
1300-
1301-

0 commit comments

Comments
 (0)