Skip to content

Commit b92b87e

Browse files
test(overlay): shoult not close when esc is pressed and closeOnEsc is false
1 parent e8985b2 commit b92b87e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,7 @@ describe('igxOverlay', () => {
27322732
button.dispatchEvent(new MouseEvent('click'));
27332733
}));
27342734

2735-
it('Should closes the component when esc key is pressed.', fakeAsync(() => {
2735+
it('Should close the component when esc key is pressed.', fakeAsync(() => {
27362736
const fixture = TestBed.createComponent(EmptyPageComponent);
27372737
const overlay = fixture.componentInstance.overlay;
27382738
const overlaySettings: OverlaySettings = {
@@ -2761,6 +2761,35 @@ describe('igxOverlay', () => {
27612761
tick();
27622762
}));
27632763

2764+
it('Should not close the component when esc key is pressed and closeOnEsc is false', fakeAsync(() => {
2765+
const fixture = TestBed.createComponent(EmptyPageComponent);
2766+
const overlay = fixture.componentInstance.overlay;
2767+
const overlaySettings: OverlaySettings = {
2768+
modal: true,
2769+
closeOnEsc: false,
2770+
positionStrategy: new GlobalPositionStrategy()
2771+
};
2772+
const targetButton = 'Escape';
2773+
const escEvent = new KeyboardEvent('keydown', {
2774+
key: targetButton
2775+
});
2776+
2777+
overlay.show(overlay.attach(SimpleDynamicComponent), overlaySettings);
2778+
tick();
2779+
2780+
let overlayWrapper = document.getElementsByClassName(CLASS_OVERLAY_WRAPPER_MODAL)[0];
2781+
overlayWrapper.addEventListener('keydown', (event: KeyboardEvent) => {
2782+
if (event.key === targetButton) {
2783+
overlayWrapper = document.getElementsByClassName(CLASS_OVERLAY_WRAPPER_MODAL)[0];
2784+
}
2785+
});
2786+
overlayWrapper.dispatchEvent(escEvent);
2787+
tick();
2788+
fixture.detectChanges();
2789+
2790+
expect(overlayWrapper).toBeTruthy();
2791+
}));
2792+
27642793
// Test #1883 #1820
27652794
it('It should close the component when esc key is pressed and there were other keys pressed prior to esc.', fakeAsync(() => {
27662795
const fixture = TestBed.createComponent(EmptyPageComponent);

0 commit comments

Comments
 (0)