-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use vitest-browser-react
and browserUserEvent
#3629
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1876ca4
Try out vitest-browser-react
amanmahajan7 38a273f
skip eslint
amanmahajan7 04b9a80
Disable
amanmahajan7 638e876
Revert
amanmahajan7 f714be7
Use `.fill`
amanmahajan7 9075091
Fix node tests
amanmahajan7 8bafe9c
Use page object
amanmahajan7 2b9d74d
Use vitest browser api
amanmahajan7 3ca1c60
eslint
amanmahajan7 397e6c1
increase timeout?
amanmahajan7 d5f4f88
increase again
amanmahajan7 fafcd73
revert timout changes
amanmahajan7 056a216
Fix tests
amanmahajan7 375b0e5
tweak
amanmahajan7 91a95be
increase delay
amanmahajan7 27d8f57
Merge branch 'main' into vitest-browser-react
amanmahajan7 2698375
Address comments, pin eslint to fix build
amanmahajan7 1b9a13a
Using `expect.element`
amanmahajan7 6519308
Update test/browser/column/renderEditCell.test.tsx
amanmahajan7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import { useState } from 'react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { page, userEvent } from '@vitest/browser/context'; | ||
|
||
import DataGrid, { textEditor } from '../../src'; | ||
import type { Column } from '../../src'; | ||
import { getCells } from './utils'; | ||
import { getCellsNew } from './utils'; | ||
|
||
interface Row { | ||
readonly name: string; | ||
} | ||
|
||
const columns: readonly Column<Row>[] = [{ key: 'name', name: 'Name', renderEditCell: textEditor }]; | ||
const columns: readonly Column<Row>[] = [ | ||
{ | ||
key: 'name', | ||
name: 'Name', | ||
renderEditCell: textEditor, | ||
editorOptions: { | ||
commitOnOutsideClick: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this so we can test the blur event |
||
} | ||
} | ||
]; | ||
const initialRows: readonly Row[] = [{ name: 'Tacitus Kilgore' }]; | ||
|
||
function Test() { | ||
|
@@ -20,10 +28,10 @@ function Test() { | |
} | ||
|
||
test('TextEditor', async () => { | ||
render(<Test />); | ||
page.render(<Test />); | ||
|
||
await userEvent.dblClick(getCells()[0]); | ||
let input: HTMLInputElement | null = screen.getByRole<HTMLInputElement>('textbox'); | ||
await userEvent.dblClick(getCellsNew()[0]); | ||
let input = page.getByRole('textbox').element() as HTMLInputElement; | ||
expect(input).toHaveClass('rdg-text-editor'); | ||
// input value is row[column.key] | ||
expect(input).toHaveValue(initialRows[0].name); | ||
|
@@ -36,13 +44,13 @@ test('TextEditor', async () => { | |
// pressing escape closes the editor without committing | ||
await userEvent.keyboard('Test{escape}'); | ||
expect(input).not.toBeInTheDocument(); | ||
expect(getCells()[0]).toHaveTextContent(/^Tacitus Kilgore$/); | ||
await expect.element(getCellsNew()[0]).toHaveTextContent(/^Tacitus Kilgore$/); | ||
|
||
// blurring the input closes and commits the editor | ||
await userEvent.dblClick(getCells()[0]); | ||
input = screen.getByRole<HTMLInputElement>('textbox'); | ||
await userEvent.keyboard('Jim Milton'); | ||
fireEvent.blur(input); | ||
await userEvent.dblClick(getCellsNew()[0]); | ||
input = page.getByRole('textbox').element() as HTMLInputElement; | ||
await userEvent.fill(input, 'Jim Milton'); | ||
await userEvent.tab(); | ||
expect(input).not.toBeInTheDocument(); | ||
expect(getCells()[0]).toHaveTextContent(/^Jim Milton$/); | ||
await expect.element(getCellsNew()[0]).toHaveTextContent(/^Jim Milton$/); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to disable it as this complains about
page...