Skip to content

Commit f8f98d3

Browse files
author
ddaribo
committed
feat(stepper): add additional expectations
1 parent 89af402 commit f8f98d3

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

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

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,40 +203,16 @@ describe('Rendering Tests', () => {
203203
owner: stepper,
204204
};
205205

206-
stepper.navigateTo(null);
207-
fix.detectChanges();
208-
expect(changingSpy).not.toHaveBeenCalled();
209-
expect(changedSpy).not.toHaveBeenCalled();
210-
expect(serviceExpandSpy).not.toHaveBeenCalled();
211-
expect(serviceCollapseSpy).not.toHaveBeenCalled();
212-
213-
stepper.navigateTo(undefined);
214-
fix.detectChanges();
215-
expect(changingSpy).not.toHaveBeenCalled();
216-
expect(changedSpy).not.toHaveBeenCalled();
217-
expect(serviceExpandSpy).not.toHaveBeenCalled();
218-
expect(serviceCollapseSpy).not.toHaveBeenCalled();
219-
220-
stepper.navigateTo([] as any);
221-
fix.detectChanges();
222-
expect(changingSpy).not.toHaveBeenCalled();
223-
expect(changedSpy).not.toHaveBeenCalled();
224-
expect(serviceExpandSpy).not.toHaveBeenCalled();
225-
expect(serviceCollapseSpy).not.toHaveBeenCalled();
226-
227-
stepper.navigateTo({} as any);
228-
fix.detectChanges();
229-
expect(changingSpy).not.toHaveBeenCalled();
230-
expect(changedSpy).not.toHaveBeenCalled();
231-
expect(serviceExpandSpy).not.toHaveBeenCalled();
232-
expect(serviceCollapseSpy).not.toHaveBeenCalled();
206+
const testValues = [null, undefined, [], {}, 'sampleString'];
233207

234-
stepper.navigateTo('sampleString' as any);
235-
fix.detectChanges();
236-
expect(changingSpy).not.toHaveBeenCalled();
237-
expect(changedSpy).not.toHaveBeenCalled();
238-
expect(serviceExpandSpy).not.toHaveBeenCalled();
239-
expect(serviceCollapseSpy).not.toHaveBeenCalled();
208+
for(const val of testValues){
209+
stepper.navigateTo(val as any);
210+
fix.detectChanges();
211+
expect(changingSpy).not.toHaveBeenCalled();
212+
expect(changedSpy).not.toHaveBeenCalled();
213+
expect(serviceExpandSpy).not.toHaveBeenCalled();
214+
expect(serviceCollapseSpy).not.toHaveBeenCalled();
215+
}
240216

241217
stepper.navigateTo(1);
242218
fix.detectChanges();
@@ -548,6 +524,16 @@ describe('Rendering Tests', () => {
548524

549525
expect(stepper.animationDuration).toBe(1000);
550526

527+
fix.componentInstance.animationDuration = null;
528+
fix.detectChanges();
529+
530+
expect(stepper.animationDuration).toBe((stepper as any)._defaultAnimationDuration);
531+
532+
fix.componentInstance.animationDuration = undefined;
533+
fix.detectChanges();
534+
535+
expect(stepper.animationDuration).toBe((stepper as any)._defaultAnimationDuration);
536+
551537
expect(stepper.horizontalAnimationType).toBe(fix.componentInstance.horizontalAnimationType);
552538
expect(stepper.horizontalAnimationType).toBe('slide');
553539

@@ -643,7 +629,7 @@ describe('Rendering Tests', () => {
643629
fix.detectChanges();
644630

645631
// if the dynamically added step's position is after the active step in linear mode,
646-
// and this step is not valid, the added step should be linear disabled
632+
// and the latter is not valid, the added step should be linear disabled
647633
stepper.steps[0].isValid = true;
648634
stepper.steps[1].isValid = false;
649635
stepper.steps[1].active = true;
@@ -1022,6 +1008,14 @@ describe('Stepper service unit tests', () => {
10221008
expect(stepperService.activeStep).toBe(steps[0]);
10231009
expect(steps[0].activeChange.emit).toHaveBeenCalledTimes(1);
10241010
expect(steps[0].activeChange.emit).toHaveBeenCalledWith(true);
1011+
1012+
const testValues = [null, undefined, [], {}, 'sampleString'];
1013+
1014+
for(const val of testValues){
1015+
expect(() => {
1016+
stepperService.expand(val as any);
1017+
}).toThrow();
1018+
}
10251019
});
10261020

10271021
it('should expand a step through API by activating it and firing the step\'s activeChange event', () => {
@@ -1037,7 +1031,6 @@ describe('Stepper service unit tests', () => {
10371031
stepperService.expandThroughApi(steps[1]);
10381032

10391033
expect(stepperService.activeStep).toBe(steps[1]);
1040-
10411034
expect(steps[0].activeChange.emit).toHaveBeenCalledTimes(1);
10421035
expect(steps[0].activeChange.emit).toHaveBeenCalledWith(false);
10431036
expect(steps[1].activeChange.emit).toHaveBeenCalledTimes(1);
@@ -1052,6 +1045,14 @@ describe('Stepper service unit tests', () => {
10521045
expect(steps[1].activeChange.emit).toHaveBeenCalledWith(false);
10531046
expect(steps[0].activeChange.emit).toHaveBeenCalledTimes(2);
10541047
expect(steps[0].activeChange.emit).toHaveBeenCalledWith(true);
1048+
1049+
const testValues = [null, undefined, [], {}, 'sampleString'];
1050+
1051+
for(const val of testValues){
1052+
expect(() => {
1053+
stepperService.expandThroughApi(val as any);
1054+
}).toThrow();
1055+
}
10551056
});
10561057

10571058
it('should collapse the currently active step and fire the change event', () => {
@@ -1097,6 +1098,14 @@ describe('Stepper service unit tests', () => {
10971098
expect(steps[1].activeChange.emit).toHaveBeenCalledTimes(1);
10981099
expect(steps[1].activeChange.emit).toHaveBeenCalledWith(false);
10991100
expect(steps[0].activeChange.emit).not.toHaveBeenCalledTimes(2);
1101+
1102+
const testValues = [null, undefined, [], {}, 'sampleString'];
1103+
1104+
for(const val of testValues){
1105+
expect(() => {
1106+
stepperService.collapse(val as any);
1107+
}).toThrow();
1108+
}
11001109
});
11011110

11021111
it('should determine the steps that are marked as visited based on the active step', () => {
@@ -1137,7 +1146,7 @@ describe('Stepper service unit tests', () => {
11371146
expect(stepperService.linearDisabledSteps.size).toBe(0);
11381147
stepperService.calculateLinearDisabledSteps();
11391148
expect(stepperService.linearDisabledSteps.size).toBe(3);
1140-
let sampleSet: Set<IgxStepComponent> = new Set<IgxStepComponent>([steps[1], steps[2], steps[3]]);
1149+
let sampleSet = new Set<IgxStepComponent>([steps[1], steps[2], steps[3]]);
11411150
expect(stepperService.linearDisabledSteps).toEqual(sampleSet);
11421151

11431152
spyOnProperty(steps[0], 'isValid').and.returnValue(true);

0 commit comments

Comments
 (0)