/
modal-1.spec.js
66 lines (63 loc) 路 2.29 KB
/
modal-1.spec.js
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
const PageModal = require('../../../src/components/Modal/pageObject');
const { ESCAPE_KEY, TAB_KEY } = require('../../constants');
const BUTTON = '#button-1';
const MODAL = '#modal-1';
describe('Modal base example', () => {
beforeAll(() => {
browser.url('/#!/Modal/1');
});
beforeEach(() => {
browser.refresh();
const component = $(BUTTON);
component.waitForExist();
});
it('should open the modal', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
expect(modal.isOpen()).toBe(true);
});
it('should close the modal when is opened and press ESC', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
browser.keys(ESCAPE_KEY);
modal.waitUntilClose();
expect(modal.isOpen()).toBe(false);
});
it('should return focus to trigger element when close modal with ESC key', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
browser.keys(ESCAPE_KEY);
expect(triggerButton.isFocused()).toBe(true);
});
it('should focus the close button when the modal is opened and press TAB', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
browser.keys(TAB_KEY);
expect(modal.hasFocusCloseButton()).toBe(true);
});
it.skip('should close the modal when is opened and click the closeButton', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
modal.clickCloseButton();
modal.waitUntilClose();
expect(modal.isOpen()).toBe(false);
});
it.skip('should return focus to trigger element when close modal with close button', () => {
const modal = new PageModal(MODAL);
const triggerButton = $(BUTTON);
triggerButton.click();
modal.waitUntilOpen();
modal.clickCloseButton();
expect(triggerButton.isFocused()).toBe(true);
});
});