Skip to content

Commit 049b45b

Browse files
committed
Use commands.scrollGrid
1 parent 9df268d commit 049b45b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

test/browser/keyboardNavigation.test.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { page, userEvent } from '@vitest/browser/context';
1+
import { commands, page, userEvent } from '@vitest/browser/context';
22

33
import { DataGrid, SelectColumn } from '../../src';
44
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';
136

147
type Row = undefined;
158

@@ -249,6 +242,10 @@ test('navigation when header and summary rows have focusable elements', async ()
249242

250243
test('navigation when selected cell not in the viewport', async () => {
251244
const columns: Column<Row, Row>[] = [SelectColumn];
245+
const selectedRowCells = page
246+
.getByRole('row')
247+
.filter({ has: getSelectedCell() })
248+
.getByRole('gridcell');
252249
for (let i = 0; i < 99; i++) {
253250
columns.push({ key: `col${i}`, name: `col${i}`, frozen: i < 5 });
254251
}
@@ -258,23 +255,23 @@ test('navigation when selected cell not in the viewport', async () => {
258255

259256
await userEvent.keyboard('{Control>}{end}{/Control}{arrowup}{arrowup}');
260257
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);
265262
await userEvent.keyboard('{arrowup}');
266263
await validateCellPosition(99, 99);
267-
expect(getCellsAtRowIndex(99)).not.toHaveLength(1);
264+
await expect.poll(() => selectedRowCells.elements().length).not.toBe(1);
268265

269-
await scrollGrid({ scrollLeft: 0 });
266+
await commands.scrollGrid({ scrollLeft: 0 });
270267
await userEvent.keyboard('{arrowdown}');
271268
await validateCellPosition(99, 100);
272269

273270
await userEvent.keyboard(
274271
'{home}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}'
275272
);
276273
await validateCellPosition(7, 100);
277-
await scrollGrid({ scrollLeft: 2000 });
274+
await commands.scrollGrid({ scrollLeft: 2000 });
278275
await userEvent.keyboard('{arrowleft}');
279276
await validateCellPosition(6, 100);
280277
});

0 commit comments

Comments
 (0)