forked from ng-bootstrap/ng-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal-autoclose.e2e-spec.ts
103 lines (79 loc) · 3.74 KB
/
modal-autoclose.e2e-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import {ModalAutoClosePage} from './modal-autoclose.po';
import {expectNoOpenModals, openUrl, sendKey} from '../../tools.po';
import {browser, Key} from 'protractor';
describe('Modal', () => {
let page: ModalAutoClosePage;
beforeAll(() => page = new ModalAutoClosePage());
beforeEach(async() => {
await openUrl('modal/autoclose');
await page.getResetButton().click();
});
afterEach(async() => { await expectNoOpenModals(); });
it('should close modal from the inside', async() => {
const modal = await page.openModal();
// close
await page.getModalCloseButton().click();
expect(await modal.isPresent()).toBeFalsy('The modal should be closed imperatively');
expect(await page.getDismissReason()).toBe('Closed', `Modal should have been closed`);
});
it('should close modal on ESC', async() => {
await page.openModal();
// close
await sendKey(Key.ESCAPE);
expect(await page.getModal().isPresent()).toBeFalsy('The modal should be closed on ESC');
expect(await page.getDismissReason()).toBe('Escape', `Modal should have been dismissed with 'Escape' reason`);
});
it(`should NOT close modal on ESC when keyboard === 'false'`, async() => {
const modal = await page.openModal('no-keyboard');
// close
await sendKey(Key.ESCAPE);
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on ESC');
await page.getModalCloseButton().click();
});
it('should close modal on backdrop click', async() => {
const modal = await page.openModal();
// dialog click
await page.getModalDialog().click();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on dialog click');
// close
await modal.click();
expect(await modal.isPresent()).toBeFalsy('The modal should be closed on backdrop click');
expect(await page.getDismissReason()).toBe('Click', `Modal should have been dismissed with 'Click' reason`);
});
it('should close modal when dragging from backdrop -> dialog', async() => {
const modal = await page.openModal();
// close
const dialog = await page.getModalDialog();
await browser.actions().dragAndDrop(modal, dialog).mouseUp().perform();
expect(await modal.isPresent()).toBeFalsy('The modal should be closed on drag from backdrop -> dialog');
expect(await page.getDismissReason()).toBe('Click', `Modal should have been dismissed with 'Click' reason`);
});
it('should NOT close modal when dragging from dialog -> backdrop', async() => {
const modal = await page.openModal();
// close
const dialog = await page.getModalDialog();
await browser.actions().dragAndDrop(dialog, modal).mouseUp().perform();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on drag from dialog -> backdrop');
await page.getModalCloseButton().click();
});
it(`should NOT close modal on 'static' backdrop click`, async() => {
const modal = await page.openModal('backdrop-static');
// dialog click
await page.getModalDialog().click();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on dialog click');
// close
await modal.click();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on backdrop click');
await page.getModalCloseButton().click();
});
it(`should NOT close modal on click with no backdrop`, async() => {
const modal = await page.openModal('backdrop-false');
// dialog click
await page.getModalDialog().click();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on dialog click');
// close
await modal.click();
expect(await modal.isPresent()).toBeTruthy('The modal should stay opened on backdrop click');
await page.getModalCloseButton().click();
});
});