1
1
import { useState } from 'react' ;
2
- import { fireEvent , render , screen } from '@testing-library/react' ;
3
- import userEvent from '@testing-library/user-event' ;
2
+ import { page , userEvent } from '@vitest/browser/context' ;
4
3
5
4
import DataGrid , { textEditor } from '../../src' ;
6
5
import type { Column } from '../../src' ;
7
- import { getCells } from './utils' ;
6
+ import { getCellsNew } from './utils' ;
8
7
9
8
interface Row {
10
9
readonly name : string ;
11
10
}
12
11
13
- const columns : readonly Column < Row > [ ] = [ { key : 'name' , name : 'Name' , renderEditCell : textEditor } ] ;
12
+ const columns : readonly Column < Row > [ ] = [
13
+ {
14
+ key : 'name' ,
15
+ name : 'Name' ,
16
+ renderEditCell : textEditor ,
17
+ editorOptions : {
18
+ commitOnOutsideClick : false
19
+ }
20
+ }
21
+ ] ;
14
22
const initialRows : readonly Row [ ] = [ { name : 'Tacitus Kilgore' } ] ;
15
23
16
24
function Test ( ) {
@@ -20,10 +28,10 @@ function Test() {
20
28
}
21
29
22
30
test ( 'TextEditor' , async ( ) => {
23
- render ( < Test /> ) ;
31
+ page . render ( < Test /> ) ;
24
32
25
- await userEvent . dblClick ( getCells ( ) [ 0 ] ) ;
26
- let input : HTMLInputElement | null = screen . getByRole < HTMLInputElement > ( 'textbox' ) ;
33
+ await userEvent . dblClick ( getCellsNew ( ) [ 0 ] ) ;
34
+ let input = page . getByRole ( 'textbox' ) . element ( ) as HTMLInputElement ;
27
35
expect ( input ) . toHaveClass ( 'rdg-text-editor' ) ;
28
36
// input value is row[column.key]
29
37
expect ( input ) . toHaveValue ( initialRows [ 0 ] . name ) ;
@@ -36,13 +44,13 @@ test('TextEditor', async () => {
36
44
// pressing escape closes the editor without committing
37
45
await userEvent . keyboard ( 'Test{escape}' ) ;
38
46
expect ( input ) . not . toBeInTheDocument ( ) ;
39
- expect ( getCells ( ) [ 0 ] ) . toHaveTextContent ( / ^ T a c i t u s K i l g o r e $ / ) ;
47
+ await expect . element ( getCellsNew ( ) [ 0 ] ) . toHaveTextContent ( / ^ T a c i t u s K i l g o r e $ / ) ;
40
48
41
49
// blurring the input closes and commits the editor
42
- await userEvent . dblClick ( getCells ( ) [ 0 ] ) ;
43
- input = screen . getByRole < HTMLInputElement > ( 'textbox' ) ;
44
- await userEvent . keyboard ( 'Jim Milton' ) ;
45
- fireEvent . blur ( input ) ;
50
+ await userEvent . dblClick ( getCellsNew ( ) [ 0 ] ) ;
51
+ input = page . getByRole ( 'textbox' ) . element ( ) as HTMLInputElement ;
52
+ await userEvent . fill ( input , 'Jim Milton' ) ;
53
+ await userEvent . tab ( ) ;
46
54
expect ( input ) . not . toBeInTheDocument ( ) ;
47
- expect ( getCells ( ) [ 0 ] ) . toHaveTextContent ( / ^ J i m M i l t o n $ / ) ;
55
+ await expect . element ( getCellsNew ( ) [ 0 ] ) . toHaveTextContent ( / ^ J i m M i l t o n $ / ) ;
48
56
} ) ;
0 commit comments