Skip to content

Commit

Permalink
test(dialog): add test for focused dialog when opened #3199
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacho committed Dec 3, 2018
1 parent e9bbae3 commit 5e1b432
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions projects/igniteui-angular/src/lib/dialog/dialog.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,29 @@ describe('Dialog', () => {
expect(overlayWrapper.classList.contains(OVERLAY_WRAPPER_CLASS)).toBe(false);
}));

it('The dialog is focused after opening it and can be closed with keyboard.', fakeAsync(() => {
const fix = TestBed.createComponent(CustomTemplates1DialogComponent);
fix.detectChanges();

const dialog: IgxDialogComponent = fix.componentInstance.dialog as IgxDialogComponent;
dialog.open();
tick();
fix.detectChanges();

// Verify dialog is opened and focused
expect(document.activeElement).toBe(dialog.toggleRef.element);
expect(dialog.isOpen).toEqual(true);

// Press 'escape' key
UIInteractions.simulateKeyDownEvent(document.activeElement, 'Escape');
tick();
fix.detectChanges();

// Verify dialog is closed and no longer focused
expect(document.activeElement).not.toBe(dialog.toggleRef.element);
expect(dialog.isOpen).toEqual(false);
}));

function dispatchEvent(element: HTMLElement, eventType: string) {
const event = new Event(eventType);
element.dispatchEvent(event);
Expand Down

0 comments on commit 5e1b432

Please sign in to comment.