|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe('simple modal', () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.visit('http://localhost:3000/examples'); |
| 6 | + // Page is heavy to load so we wait for it to be loaded |
| 7 | + cy.wait(500); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should open modal when clicking open button', () => { |
| 11 | + cy.get('button').eq(2).click(); |
| 12 | + cy.get('[data-testid=modal]').should('exist'); |
| 13 | + }); |
| 14 | + |
| 15 | + // TODO overlay not working, see how to fix |
| 16 | + // it('should close modal when clicking overlay', () => { |
| 17 | + // cy.get('button').eq(2).click(); |
| 18 | + // cy.get('[data-testid=overlay]').click(); |
| 19 | + // cy.get('[data-testid=modal]').should('not.exist'); |
| 20 | + // }); |
| 21 | + |
| 22 | + it('should close modal when clicking the close icon', () => { |
| 23 | + cy.get('button').eq(2).click(); |
| 24 | + cy.get('[data-testid=close-button]').click(); |
| 25 | + cy.get('[data-testid=modal]').should('not.exist'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should close modal when pressing esc key', () => { |
| 29 | + cy.get('button').eq(2).click(); |
| 30 | + cy.get('body').type('{esc}'); |
| 31 | + cy.get('[data-testid=modal]').should('not.exist'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should close only last modal when pressing esc key when multiple modals are opened', () => { |
| 35 | + cy.get('button').eq(8).click(); |
| 36 | + cy.get('[data-testid=modal] button').eq(0).click(); |
| 37 | + cy.get('[data-testid=modal]').should('have.length', 2); |
| 38 | + cy.get('body').type('{esc}'); |
| 39 | + cy.get('[data-testid=modal]').should('have.length', 1); |
| 40 | + cy.get('body').type('{esc}'); |
| 41 | + cy.get('[data-testid=modal]').should('not.exist'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should block the scroll when modal is opened', () => { |
| 45 | + cy.get('button').eq(2).click(); |
| 46 | + cy.get('html').should('have.css', 'position', 'fixed'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should unblock the scroll when modal is closed', () => { |
| 50 | + cy.get('button').eq(2).click(); |
| 51 | + cy.get('html').should('have.css', 'position', 'fixed'); |
| 52 | + cy.get('body').type('{esc}'); |
| 53 | + cy.get('html').should('not.have.css', 'position', 'fixed'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should unblock scroll only after last modal is closed when multiple modals are opened', () => { |
| 57 | + cy.get('button').eq(8).click(); |
| 58 | + cy.get('[data-testid=modal] button').eq(0).click(); |
| 59 | + cy.get('[data-testid=modal]').should('have.length', 2); |
| 60 | + cy.get('html').should('have.css', 'position', 'fixed'); |
| 61 | + cy.get('body').type('{esc}'); |
| 62 | + cy.get('[data-testid=modal]').should('have.length', 1); |
| 63 | + cy.get('html').should('have.css', 'position', 'fixed'); |
| 64 | + cy.get('body').type('{esc}'); |
| 65 | + cy.get('[data-testid=modal]').should('not.exist'); |
| 66 | + cy.get('html').should('not.have.css', 'position', 'fixed'); |
| 67 | + }); |
| 68 | +}); |
0 commit comments