Skip to content

Commit 10ea5bd

Browse files
committed
First cypress test
1 parent 3775674 commit 10ea5bd

File tree

9 files changed

+48336
-13971
lines changed

9 files changed

+48336
-13971
lines changed

cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"componentFolder": "cypress/component",
3+
"testFiles": "**/*.tsx"
4+
}

cypress/component/click.spec.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react'
2+
import { mount } from '@cypress/react'
3+
import { DataSheetGrid, DataSheetGridRef } from '../../src'
4+
5+
it('should select cell on click', () => {
6+
const ref = { current: null as unknown as DataSheetGridRef }
7+
8+
cy.viewport(500, 500)
9+
mount(
10+
<DataSheetGrid
11+
columns={[{ id: 'a' }, { id: 'b' }]}
12+
value={[{}, {}]}
13+
style={{ marginTop: 100, width: 440 }}
14+
ref={ref}
15+
/>
16+
)
17+
cy.get('.dsg-container')
18+
.click(100, 60)
19+
.then(() => {
20+
expect(ref.current.activeCell).to.deep.equal({
21+
col: 0,
22+
row: 0,
23+
colId: 'a',
24+
})
25+
})
26+
27+
cy.get('.dsg-container')
28+
.click(300, 85)
29+
.then(() => {
30+
expect(ref.current.activeCell).to.deep.equal({
31+
col: 1,
32+
row: 1,
33+
colId: 'b',
34+
})
35+
})
36+
37+
cy.get('.dsg-container')
38+
.click(350, 20)
39+
.then(() => {
40+
expect(ref.current.selection).to.deep.equal({
41+
min: {
42+
col: 1,
43+
row: 0,
44+
colId: 'b',
45+
},
46+
max: {
47+
col: 1,
48+
row: 1,
49+
colId: 'b',
50+
},
51+
})
52+
})
53+
54+
cy.get('.dsg-container')
55+
.click(20, 50)
56+
.then(() => {
57+
expect(ref.current.selection).to.deep.equal({
58+
min: {
59+
col: 0,
60+
row: 0,
61+
colId: 'a',
62+
},
63+
max: {
64+
col: 1,
65+
row: 0,
66+
colId: 'b',
67+
},
68+
})
69+
})
70+
})
71+
72+
export {}

cypress/plugins/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="cypress" />
2+
import injectDevServer from '@cypress/react/plugins/react-scripts'
3+
4+
const pluginConfig: Cypress.PluginConfig = (on, config) => {
5+
if (config.testingType === 'component') {
6+
injectDevServer(on, config)
7+
}
8+
9+
return config
10+
}
11+
export default pluginConfig

cypress/support/commands.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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) => { ... })
26+
27+
import '@testing-library/cypress/add-commands'

cypress/support/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-ignore
3+
import './commands'
4+
5+
Cypress.on('uncaught:exception', (err) => {
6+
if (err.message.includes('ResizeObserver loop limit exceeded')) {
7+
return false
8+
}
9+
10+
return true
11+
})

cypress/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
// be explicit about types included
6+
// to avoid clashing with Jest types
7+
"types": ["cypress", "@testing-library/cypress"]
8+
},
9+
"include": [
10+
"../node_modules/cypress",
11+
"./**/*.ts",
12+
"./**/*.tsx"
13+
]
14+
}

0 commit comments

Comments
 (0)