1
- import { page , userEvent } from '@vitest/browser/context' ;
1
+ import { commands , page , userEvent } from '@vitest/browser/context' ;
2
2
3
3
import { DataGrid , SelectColumn } from '../../src' ;
4
4
import type { Column } from '../../src' ;
5
- import {
6
- getCellsAtRowIndex ,
7
- getSelectedCell ,
8
- scrollGrid ,
9
- setup ,
10
- tabIntoGrid ,
11
- validateCellPosition
12
- } from './utils' ;
5
+ import { getSelectedCell , setup , tabIntoGrid , validateCellPosition } from './utils' ;
13
6
14
7
type Row = undefined ;
15
8
@@ -249,6 +242,10 @@ test('navigation when header and summary rows have focusable elements', async ()
249
242
250
243
test ( 'navigation when selected cell not in the viewport' , async ( ) => {
251
244
const columns : Column < Row , Row > [ ] = [ SelectColumn ] ;
245
+ const selectedRowCells = page
246
+ . getByRole ( 'row' )
247
+ . filter ( { has : getSelectedCell ( ) } )
248
+ . getByRole ( 'gridcell' ) ;
252
249
for ( let i = 0 ; i < 99 ; i ++ ) {
253
250
columns . push ( { key : `col${ i } ` , name : `col${ i } ` , frozen : i < 5 } ) ;
254
251
}
@@ -258,23 +255,23 @@ test('navigation when selected cell not in the viewport', async () => {
258
255
259
256
await userEvent . keyboard ( '{Control>}{end}{/Control}{arrowup}{arrowup}' ) ;
260
257
await validateCellPosition ( 99 , 100 ) ;
261
- expect ( getCellsAtRowIndex ( 100 ) ) . not . toHaveLength ( 1 ) ;
262
-
263
- await scrollGrid ( { scrollTop : 0 } ) ;
264
- expect ( getCellsAtRowIndex ( 99 ) ) . toHaveLength ( 1 ) ;
258
+ // TODO: replace with ` toHaveLength` when migrating to v4
259
+ await expect . poll ( ( ) => selectedRowCells . elements ( ) . length ) . not . toBe ( 1 ) ;
260
+ await commands . scrollGrid ( { scrollTop : 0 } ) ;
261
+ await expect . poll ( ( ) => selectedRowCells . elements ( ) . length ) . toBe ( 1 ) ;
265
262
await userEvent . keyboard ( '{arrowup}' ) ;
266
263
await validateCellPosition ( 99 , 99 ) ;
267
- expect ( getCellsAtRowIndex ( 99 ) ) . not . toHaveLength ( 1 ) ;
264
+ await expect . poll ( ( ) => selectedRowCells . elements ( ) . length ) . not . toBe ( 1 ) ;
268
265
269
- await scrollGrid ( { scrollLeft : 0 } ) ;
266
+ await commands . scrollGrid ( { scrollLeft : 0 } ) ;
270
267
await userEvent . keyboard ( '{arrowdown}' ) ;
271
268
await validateCellPosition ( 99 , 100 ) ;
272
269
273
270
await userEvent . keyboard (
274
271
'{home}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}'
275
272
) ;
276
273
await validateCellPosition ( 7 , 100 ) ;
277
- await scrollGrid ( { scrollLeft : 2000 } ) ;
274
+ await commands . scrollGrid ( { scrollLeft : 2000 } ) ;
278
275
await userEvent . keyboard ( '{arrowleft}' ) ;
279
276
await validateCellPosition ( 6 , 100 ) ;
280
277
} ) ;
0 commit comments