-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathmodal.spec.ts
104 lines (88 loc) · 3.67 KB
/
modal.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
104
describe('Modal Test', () => {
it('Navigate to Modal section', () => {
cy.visit('http://localhost:3000/modal-demo-nav-link');
});
it('Verify Half Width Modal', () => {
cy.get('#showHalfWidthModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
cy.wrap(modalButton).click();
cy.get('.pf-v6-c-page').then((page: JQuery<HTMLElement>) => {
cy.get('.pf-v6-c-modal-box')
.then(() => {
cy.get('.pf-v6-c-modal-box').should('have.css', 'width', `${page.width() / 2}px`);
cy.get('.pf-v6-c-modal-box .pf-v6-c-button[aria-label="Close"]').then((closeButton) => {
cy.wrap(closeButton).click();
cy.get('.pf-v6-c-modal-box').should('not.exist');
});
})
.then(() => {
cy.wrap(modalButton).click();
cy.get('.pf-v6-c-modal-box').should('exist');
cy.get('body').type('{esc}');
cy.get('.pf-v6-c-modal-box').should('not.exist');
});
});
});
});
it('Verify Custom Escape Press Modal', () => {
cy.get('#showCustomEscapeModalButton.customEscapePressed').should('not.exist');
cy.get('#showCustomEscapeModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
cy.wrap(modalButton).click();
cy.get('.pf-v6-c-modal-box').should('exist');
cy.get('.pf-v6-c-modal-box')
.then(() => {
cy.get('.pf-v6-c-modal-box .pf-v6-c-button[aria-label="Close"]').then((closeButton) => {
cy.wrap(closeButton).click();
cy.get('.pf-v6-c-modal-box').should('not.exist');
cy.get('#showCustomEscapeModalButton.customEscapePressed').should('not.exist');
});
})
.then(() => {
cy.wrap(modalButton).click();
cy.get('.pf-v6-c-modal-box').should('exist');
cy.get('body').type('{esc}');
cy.get('.pf-v6-c-modal-box').should('not.exist');
cy.get('#showCustomEscapeModalButton.customEscapePressed').should('exist');
});
});
});
it('Verify focustrap for basic modal', () => {
cy.get('#tabstop-test').focus();
// @ts-ignore
cy.tab().click(); // click first btn to open first modal
cy.focused().should('have.attr', 'aria-label', 'Close');
// @ts-ignore
cy.tab();
cy.focused().should('have.attr', 'data-id', 'modal-01-confirm-btn');
// @ts-ignore
cy.tab();
cy.focused().should('have.attr', 'data-id', 'modal-01-cancel-btn');
// @ts-ignore
cy.tab();
cy.focused().should('have.attr', 'aria-label', 'Close');
cy.focused().click();
});
it('Verify escape key closes modal', () => {
cy.get('#tabstop-test').focus();
// @ts-ignore
cy.tab().tab().click(); // open second modal
cy.get('.pf-v6-c-modal-box').should('exist');
// press escape key
cy.get('body').type('{esc}');
cy.get('.pf-v6-c-modal-box').should('not.exist');
});
it('Verify first focusable element receives focus by default', () => {
cy.get('#showDefaultModalButton').click();
cy.get('.pf-v6-c-modal-box__close > .pf-v6-c-button.pf-m-plain').should('have.focus');
cy.get('.pf-v6-c-modal-box__close > .pf-v6-c-button.pf-m-plain').click();
});
it('Verify custom element receives focus', () => {
cy.get('#showCustomFocusModalButton').click();
cy.get('#modal-custom-focus-confirm-button').should('have.focus');
cy.get('#modal-custom-focus-cancel-button').click();
});
it("Verify the same id doesn't appear multiple times", () => {
cy.get('#showDescriptionModalButton').click();
cy.get('body').find('div#test-modal-id').should('have.length', 1);
cy.get('.pf-v6-c-modal-box__close > .pf-v6-c-button.pf-m-plain').click();
});
});