Skip to content

Commit 847ab1c

Browse files
authored
feat: create E2E suite to test on real browser (#449)
1 parent d51f8e0 commit 847ab1c

File tree

9 files changed

+666
-17
lines changed

9 files changed

+666
-17
lines changed

.github/workflows/main.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,12 @@ jobs:
3333
3434
- name: Install dependencies
3535
run: yarn install --immutable
36-
env:
37-
CI: true
3836

3937
- name: Lint
4038
run: yarn lint
41-
env:
42-
CI: true
4339

4440
- name: Test
4541
run: yarn test --ci --coverage --maxWorkers=2
46-
env:
47-
CI: true
4842

4943
- name: Report coverage
5044
uses: codecov/codecov-action@v1
@@ -54,5 +48,10 @@ jobs:
5448

5549
- name: Build docs
5650
run: yarn docz:build
57-
env:
58-
CI: true
51+
52+
- name: Cypress run
53+
uses: cypress-io/github-action@v2
54+
with:
55+
# Dependencies already installed before
56+
install: false
57+
start: yarn dlx serve -l 3000 .docz/dist

cypress.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/integration/modal.spec.ts

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
});

cypress/plugins/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
module.exports = (on, config) => {
19+
// `on` is used to hook into various events Cypress emits
20+
// `config` is the resolved Cypress config
21+
}

cypress/support/commands.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

cypress/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["es5", "dom"],
5+
"types": ["cypress"]
6+
},
7+
"include": ["**/*.ts"]
8+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"setupFilesAfterEnv": [
2727
"./__tests__/setupTests.ts"
2828
],
29+
"modulePathIgnorePatterns": [
30+
"cypress"
31+
],
2932
"coveragePathIgnorePatterns": [
3033
"src/lib"
3134
]
@@ -80,6 +83,7 @@
8083
"@types/react": "16.9.56",
8184
"@types/react-dom": "16.9.9",
8285
"@types/react-transition-group": "4.4.0",
86+
"cypress": "5.5.0",
8387
"docz": "2.3.1",
8488
"gatsby": "2.23.11",
8589
"gatsby-theme-docz": "2.3.1",

0 commit comments

Comments
 (0)