2017-01-18 23:13:48 +01:00
|
|
|
import {browser, by, element, Key} from 'protractor';
|
2017-06-01 17:49:20 +02:00
|
|
|
import {
|
|
|
|
|
expectToExist,
|
|
|
|
|
expectFocusOn,
|
|
|
|
|
pressKeys,
|
|
|
|
|
clickElementAtPoint,
|
|
|
|
|
waitForElement,
|
2017-06-10 01:09:08 +02:00
|
|
|
} from '../util/index';
|
2016-12-19 20:17:23 +02:00
|
|
|
|
2016-11-15 01:50:17 +01:00
|
|
|
describe('dialog', () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
beforeEach(async () => await browser.get('/dialog'));
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2019-01-11 23:43:04 +01:00
|
|
|
it('should open a dialog', async () => {
|
|
|
|
|
await element(by.id('default')).click();
|
|
|
|
|
await expectToExist('mat-dialog-container');
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2019-01-11 23:43:04 +01:00
|
|
|
it('should open a template dialog', async () => {
|
|
|
|
|
await expectToExist('.my-template-dialog', false);
|
|
|
|
|
await element(by.id('template')).click();
|
|
|
|
|
await expectToExist('.my-template-dialog');
|
2017-02-09 10:32:07 -08:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should close by clicking on the backdrop', async() => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await clickOnBackdrop();
|
|
|
|
|
await expectToExist('mat-dialog-container', false);
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should close by pressing escape', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await pressKeys(Key.ESCAPE);
|
|
|
|
|
await expectToExist('mat-dialog-container', false);
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should close by pressing escape when the first tabbable element has lost focus',
|
|
|
|
|
async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2017-02-15 01:48:44 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await clickElementAtPoint('mat-dialog-container', { x: 0, y: 0 });
|
|
|
|
|
await pressKeys(Key.ESCAPE);
|
|
|
|
|
await expectToExist('mat-dialog-container', false);
|
2017-02-15 01:48:44 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should close by clicking on the "close" button', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('close')).click();
|
|
|
|
|
await expectToExist('mat-dialog-container', false);
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should focus the first focusable element', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await expectFocusOn('mat-dialog-container input');
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should restore focus to the element that opened the dialog', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
const openButton = element(by.id('default'));
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2019-01-11 23:43:04 +01:00
|
|
|
await openButton.click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await clickOnBackdrop();
|
|
|
|
|
await expectFocusOn(openButton);
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should prevent tabbing out of the dialog', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('default')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await pressKeys(Key.TAB, Key.TAB, Key.TAB);
|
|
|
|
|
await expectFocusOn('#close');
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should be able to prevent closing by clicking on the backdrop', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('disabled')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await clickOnBackdrop();
|
|
|
|
|
await expectToExist('mat-dialog-container');
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
it('should be able to prevent closing by pressing escape', async () => {
|
2019-01-11 23:43:04 +01:00
|
|
|
await element(by.id('disabled')).click();
|
2016-11-15 01:50:17 +01:00
|
|
|
|
2017-06-01 17:49:20 +02:00
|
|
|
await waitForDialog();
|
2019-01-11 23:43:04 +01:00
|
|
|
await pressKeys(Key.ESCAPE);
|
|
|
|
|
await expectToExist('mat-dialog-container');
|
2016-11-15 01:50:17 +01:00
|
|
|
});
|
|
|
|
|
|
2019-01-11 23:43:04 +01:00
|
|
|
async function waitForDialog() {
|
|
|
|
|
await waitForElement('mat-dialog-container');
|
2016-11-15 01:50:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-11 23:43:04 +01:00
|
|
|
async function clickOnBackdrop() {
|
|
|
|
|
await clickElementAtPoint('.cdk-overlay-backdrop', { x: 0, y: 0 });
|
2016-11-15 01:50:17 +01:00
|
|
|
}
|
|
|
|
|
});
|