Skip to content

Commit 49dedf2

Browse files
committed
fix(combo): test for clicking away when the combo is opened
1 parent cdebeea commit 49dedf2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3603,6 +3603,28 @@ describe('igxCombo', () => {
36033603
expect(combo.valid).toEqual(IgxInputState.INITIAL);
36043604
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
36053605
}));
3606+
3607+
fit('should mark the combo as touched and invalid when opened and the user clicks away', fakeAsync(() => {
3608+
// Access the NgModel for the testCombo
3609+
const ngModel = fixture.debugElement.query(By.directive(NgModel)).injector.get(NgModel);
3610+
3611+
// Initially, the combo should not be touched
3612+
expect(combo.valid).toEqual(IgxInputState.INITIAL);
3613+
expect(combo.comboInput.valid).toEqual(IgxInputState.INITIAL);
3614+
expect(ngModel.touched).toBeFalse();
3615+
3616+
combo.open();
3617+
fixture.detectChanges();
3618+
3619+
const documentClickEvent = new MouseEvent('click', { bubbles: true });
3620+
document.body.dispatchEvent(documentClickEvent);
3621+
fixture.detectChanges();
3622+
tick();
3623+
3624+
expect(combo.valid).toEqual(IgxInputState.INVALID);
3625+
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
3626+
expect(ngModel.touched).toBeTrue(); // NgModel should now be marked as touched
3627+
}));
36063628
});
36073629
});
36083630
describe('Display density', () => {
@@ -3784,7 +3806,7 @@ class IgxComboFormComponent {
37843806
@Component({
37853807
template: `
37863808
<form #form="ngForm">
3787-
<igx-combo #testCombo class="input-container" [placeholder]="'Locations'"
3809+
<igx-combo #testCombo #testComboNgModel="ngModel" class="input-container" [placeholder]="'Locations'"
37883810
name="anyName" required [(ngModel)]="values"
37893811
[data]="items" [filterable]="filterableFlag"
37903812
[displayKey]="'field'" [valueKey]="'field'"

0 commit comments

Comments
 (0)