Skip to content

Commit cdc4327

Browse files
authored
WIP: feat(cypress): Added cypress and integration test for the close button. (#118)
* feat(cypress): Added cypress and integration test for the close button. * feat(cypress): Added code for cypress ci in package.json. * feat(github-actions): Added code for cypress integration tests. * fix(github actions): Added github actions.
1 parent 38d5dc3 commit cdc4327

File tree

12 files changed

+1571
-119
lines changed

12 files changed

+1571
-119
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,43 @@ jobs:
157157
run: npm run build:docs
158158
- name: A11y tests
159159
run: npm run serve:docs & npm run test:a11y
160+
test_cypress:
161+
runs-on: ubuntu-latest
162+
env:
163+
GH_PR_NUM: ${{ github.event.number }}
164+
needs: build
165+
steps:
166+
- uses: actions/checkout@v2
167+
# Yes, we really want to checkout the PR
168+
- run: |
169+
if [[ ! -z "${GH_PR_NUM}" ]]; then
170+
echo "Checking out PR"
171+
git fetch origin pull/$GH_PR_NUM/head:tmp
172+
git checkout tmp
173+
fi
174+
- uses: actions/setup-node@v3
175+
with:
176+
node-version: '16'
177+
- uses: actions/cache@v2
178+
id: npm-cache
179+
name: Cache npm deps
180+
with:
181+
path: |
182+
node_modules
183+
**/node_modules
184+
~/.cache/Cypress
185+
key: ${{ runner.os }}-yarn-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('package-lock.json') }}
186+
- run: npm install --frozen-lockfile
187+
if: steps.npm-cache.outputs.cache-hit != 'true'
188+
- uses: actions/cache@v2
189+
id: dist
190+
name: Cache dist
191+
with:
192+
path: |
193+
packages/*/dist
194+
packages/react-styles/css
195+
key: ${{ runner.os }}-dist-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('package-lock.json', 'package.json', 'packages/*/*', '!packages/*/dist', '!packages/*/node_modules') }}
196+
- name: Build dist
197+
run: npm run build
198+
- name: Run integration tests
199+
run: npm run cypress:run:ci

cypress.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
e2e: {
5+
viewportHeight: 1024,
6+
viewportWidth: 1400,
7+
screenshotOnRunFailure: false,
8+
reporter: "junit",
9+
reporterOptions: {
10+
mochaFile: "results/my-test-output-[hash].xml",
11+
toConsole: true
12+
},
13+
},
14+
});

cypress/e2e/CloseButton.spec.cy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('Test the close button', () => {
2+
it('passes', () => {
3+
cy.visit('http://localhost:8006/extensions/component-groups/about-component-groups', { onBeforeLoad: (win) => {cy.stub(win.console, 'log').as('consoleLog');}, });
4+
cy.wait(1000);
5+
cy.get('a[href="/extensions/component-groups/closebutton"]').click();
6+
cy.wait(1000);
7+
8+
cy.get('[data-test-id="close-button-example"]').click();
9+
cy.wait(1000);
10+
cy.get('@consoleLog').should('be.calledWith', 'Close button clicked');
11+
12+
})
13+
})

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

cypress/support/e2e.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts 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')

0 commit comments

Comments
 (0)