Skip to content

Commit ef6044a

Browse files
committed
fix(simple-combo): add test for tab behavior
1 parent 5eec83b commit ef6044a

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.spec.ts

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,8 @@ describe('IgxSimpleCombo', () => {
11151115
IgxSimpleComboSampleComponent,
11161116
IgxComboInContainerTestComponent,
11171117
IgxSimpleComboIconTemplatesComponent,
1118-
IgxSimpleComboDirtyCheckTestComponent
1118+
IgxSimpleComboDirtyCheckTestComponent,
1119+
IgxSimpleComboTabBehaviorTestComponent
11191120
]
11201121
}).compileComponents();
11211122
}));
@@ -2109,6 +2110,35 @@ describe('IgxSimpleCombo', () => {
21092110

21102111
expect(reactiveForm.dirty).toBe(false);
21112112
}));
2113+
2114+
it('should focus on the next combo when Tab is pressed', fakeAsync(() => {
2115+
fixture = TestBed.createComponent(IgxSimpleComboTabBehaviorTestComponent);
2116+
fixture.detectChanges();
2117+
2118+
const combos = fixture.debugElement.queryAll(By.directive(IgxSimpleComboComponent));
2119+
expect(combos.length).toBe(3);
2120+
2121+
const firstComboInput = combos[0].query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2122+
const secondComboInput = combos[1].query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2123+
const thirdComboInput = combos[2].query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2124+
2125+
firstComboInput.nativeElement.focus();
2126+
tick();
2127+
fixture.detectChanges();
2128+
expect(document.activeElement).toEqual(firstComboInput.nativeElement);
2129+
2130+
UIInteractions.triggerEventHandlerKeyDown('Tab', firstComboInput);
2131+
secondComboInput.nativeElement.focus();
2132+
tick();
2133+
fixture.detectChanges();
2134+
expect(document.activeElement).toEqual(secondComboInput.nativeElement);
2135+
2136+
UIInteractions.triggerEventHandlerKeyDown('Tab', secondComboInput);
2137+
thirdComboInput.nativeElement.focus();
2138+
tick();
2139+
fixture.detectChanges();
2140+
expect(document.activeElement).toEqual(thirdComboInput.nativeElement);
2141+
}));
21122142
});
21132143

21142144
describe('Form control tests: ', () => {
@@ -3407,3 +3437,63 @@ export class IgxSimpleComboDirtyCheckTestComponent implements OnInit {
34073437
];
34083438
}
34093439
}
3440+
3441+
@Component({
3442+
template: `
3443+
<form [formGroup]="form">
3444+
<div class="combo-section">
3445+
<igx-simple-combo
3446+
#combo
3447+
[data]="cities"
3448+
[displayKey]="'name'"
3449+
[valueKey]="'id'"
3450+
formControlName="city"
3451+
>
3452+
</igx-simple-combo>
3453+
3454+
<igx-simple-combo
3455+
#combo2
3456+
[data]="cities"
3457+
[displayKey]="'name'"
3458+
[valueKey]="'id'"
3459+
formControlName="city2"
3460+
></igx-simple-combo>
3461+
3462+
<igx-simple-combo
3463+
#combo3
3464+
[data]="cities"
3465+
[displayKey]="'name'"
3466+
[valueKey]="'id'"
3467+
formControlName="city3"
3468+
></igx-simple-combo>
3469+
</div>
3470+
</form>
3471+
`,
3472+
imports: [IgxSimpleComboComponent, ReactiveFormsModule]
3473+
})
3474+
export class IgxSimpleComboTabBehaviorTestComponent implements OnInit {
3475+
@ViewChild('combo', { read: IgxSimpleComboComponent, static: true })
3476+
public combo: IgxSimpleComboComponent;
3477+
@ViewChild('combo2', { read: IgxSimpleComboComponent, static: true })
3478+
public combo2: IgxSimpleComboComponent;
3479+
@ViewChild('combo3', { read: IgxSimpleComboComponent, static: true })
3480+
public combo3: IgxSimpleComboComponent;
3481+
3482+
public cities = [];
3483+
3484+
public form = new FormGroup({
3485+
city: new FormControl<number>({ value: undefined, disabled: false }),
3486+
city2: new FormControl<number>({ value: undefined, disabled: false }),
3487+
city3: new FormControl<number>({ value: undefined, disabled: false }),
3488+
});
3489+
3490+
public ngOnInit(): void {
3491+
this.cities = [
3492+
{ id: 1, name: 'New York' },
3493+
{ id: 2, name: 'Los Angeles' },
3494+
{ id: 3, name: 'Chicago' },
3495+
{ id: 4, name: 'Houston' },
3496+
{ id: 5, name: 'Phoenix' }
3497+
];
3498+
}
3499+
}

0 commit comments

Comments
 (0)