forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal.spec.ts
86 lines (78 loc) · 3.2 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
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-v5-c-page').then((page: JQuery<HTMLElement>) => {
cy.get('.pf-v5-c-modal-box')
.then(() => {
cy.get('.pf-v5-c-modal-box').should('have.css', 'width', `${page.width() / 2}px`);
cy.get('.pf-v5-c-modal-box .pf-v5-c-button[aria-label="Close"]').then((closeButton) => {
cy.wrap(closeButton).click();
cy.get('.pf-v5-c-modal-box').should('not.exist');
});
})
.then(() => {
cy.wrap(modalButton).click();
cy.get('.pf-v5-c-modal-box').should('exist');
cy.get('body').type('{esc}');
cy.get('.pf-v5-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-v5-c-modal-box').should('exist');
cy.get('.pf-v5-c-modal-box')
.then(() => {
cy.get('.pf-v5-c-modal-box .pf-v5-c-button[aria-label="Close"]').then((closeButton) => {
cy.wrap(closeButton).click();
cy.get('.pf-v5-c-modal-box').should('not.exist');
cy.get('#showCustomEscapeModalButton.customEscapePressed').should('not.exist');
});
})
.then(() => {
cy.wrap(modalButton).click();
cy.get('.pf-v5-c-modal-box').should('exist');
cy.get('body').type('{esc}');
cy.get('.pf-v5-c-modal-box').should('not.exist');
cy.get('#showCustomEscapeModalButton.customEscapePressed').should('exist');
});
});
});
it('Verify focustrap for basic modal', () => {
cy.get('#tabstop-test').focus();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cy.tab().click(); // click first btn to open first modal
cy.focused().should('have.attr', 'aria-label', 'Close');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cy.tab();
cy.focused().should('have.attr', 'data-id', 'modal-01-cancel-btn');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cy.tab();
cy.focused().should('have.attr', 'data-id', 'modal-01-confirm-btn');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @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();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cy.tab().tab().click(); // open second modal
cy.get('.pf-v5-c-modal-box').should('exist');
// press escape key
cy.get('body').type('{esc}');
cy.get('.pf-v5-c-modal-box').should('not.exist');
});
});