Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress #100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ jobs:
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

cypress:
name: End-to-End tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cypress run
uses: cypress-io/github-action@v2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/.idea
tsconfig.tsbuildinfo
/coverage
/cypress/videos/
/.nyc_output/
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"componentFolder": "cypress/component",
"testFiles": "**/*.tsx",
"video": false
}
89 changes: 89 additions & 0 deletions cypress/component/click.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react'
import { mount } from '@cypress/react'
import { DataSheetGrid, DataSheetGridRef } from '../../src'

it('should select cell on click', () => {
const ref = { current: null as unknown as DataSheetGridRef }

cy.viewport(500, 500)
mount(
<DataSheetGrid
columns={[{ id: 'a' }, { id: 'b' }]}
value={[{}, {}]}
style={{ marginTop: 100, width: 440 }}
ref={ref}
/>
)
cy.get('.dsg-container')
.click(100, 60)
.then(() => {
expect(ref.current.activeCell).to.deep.equal({
col: 0,
row: 0,
colId: 'a',
})
})

cy.get('.dsg-container')
.click(300, 85)
.then(() => {
expect(ref.current.activeCell).to.deep.equal({
col: 1,
row: 1,
colId: 'b',
})
})

cy.get('.dsg-container')
.click(350, 20)
.then(() => {
expect(ref.current.selection).to.deep.equal({
min: {
col: 1,
row: 0,
colId: 'b',
},
max: {
col: 1,
row: 1,
colId: 'b',
},
})
})

cy.get('.dsg-container')
.click(20, 50)
.then(() => {
expect(ref.current.selection).to.deep.equal({
min: {
col: 0,
row: 0,
colId: 'a',
},
max: {
col: 1,
row: 0,
colId: 'b',
},
})
})

cy.get('.dsg-container')
.click(20, 20)
.then(() => {
expect(ref.current.selection).to.deep.equal({
min: {
col: 0,
row: 0,
colId: 'a',
},
max: {
col: 1,
row: 1,
colId: 'b',
},
})
})
})

export {}
16 changes: 16 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="cypress" />
import injectDevServer from '@cypress/react/plugins/react-scripts'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import injectCoverage from '@cypress/code-coverage/task'

const pluginConfig: Cypress.PluginConfig = (on, config) => {
injectCoverage(on, config)

if (config.testingType === 'component') {
injectDevServer(on, config)
}

return config
}
export default pluginConfig
27 changes: 27 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

import '@testing-library/cypress/add-commands'
12 changes: 12 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import './commands'
import '@cypress/code-coverage/support'

Cypress.on('uncaught:exception', (err) => {
if (err.message.includes('ResizeObserver loop limit exceeded')) {
return false
}

return true
})
14 changes: 14 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
// be explicit about types included
// to avoid clashing with Jest types
"types": ["cypress", "@testing-library/cypress"]
},
"include": [
"../node_modules/cypress",
"./**/*.ts",
"./**/*.tsx"
]
}
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config: Config.InitialOptions = {
verbose: true,
preset: 'ts-jest',
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['./dist'],
testPathIgnorePatterns: ['./dist', './cypress'],
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleNameMapper: {
'\\.css$': '<rootDir>/tests/helpers/styleMock.ts',
Expand Down
Loading