Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/browser/column/colSpan.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { page, userEvent } from 'vitest/browser';

import type { Column } from '../../../src';
import { getCellsAtRowIndex, setup, validateCellPosition } from '../utils';
import { getCellsAtRowIndex, safeTab, setup, validateCellPosition } from '../utils';

const headerCells = page.getHeaderCell();

Expand Down Expand Up @@ -145,18 +145,18 @@ describe('colSpan', () => {
await validateCellPosition(0, 8);
await userEvent.keyboard('{arrowright}');
await validateCellPosition(5, 8);
await userEvent.tab({ shift: true });
await userEvent.tab({ shift: true });
await safeTab(true);
await safeTab(true);
await validateCellPosition(14, 7);
await userEvent.tab();
await safeTab();
await validateCellPosition(0, 8);
await userEvent.click(getCellsAtRowIndex(10).nth(11));
await validateCellPosition(11, 11);
await userEvent.tab();
await safeTab();
await validateCellPosition(12, 11);
await userEvent.tab();
await safeTab();
await validateCellPosition(0, 12);
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(12, 11);

// bottom summary rows
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('colSpan', () => {

async function navigate(count: number, shift = false) {
for (let i = 0; i < count; i++) {
await userEvent.tab({ shift });
await safeTab(shift);
}
}
});
Expand Down
18 changes: 9 additions & 9 deletions test/browser/column/grouping.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { page, userEvent } from 'vitest/browser';

import type { ColumnOrColumnGroup } from '../../../src';
import { setup, tabIntoGrid, testCount, validateCellPosition } from '../utils';
import { safeTab, setup, tabIntoGrid, testCount, validateCellPosition } from '../utils';

const grid = page.getGrid();
const headerRows = grid.getHeaderRow();
Expand Down Expand Up @@ -323,21 +323,21 @@ test('keyboard navigation', async () => {
await validateCellPosition(10, 3);

// tab navigation
await userEvent.tab();
await safeTab();
await validateCellPosition(11, 3);
await userEvent.tab({ shift: true });
await userEvent.tab({ shift: true });
await userEvent.tab({ shift: true });
await safeTab(true);
await safeTab(true);
await safeTab(true);
await validateCellPosition(8, 3);
await userEvent.keyboard('{arrowup}');
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(4, 0);
await userEvent.tab();
await safeTab();
await validateCellPosition(8, 0);

await userEvent.keyboard('{home}{end}');
await userEvent.tab();
await safeTab();
await validateCellPosition(0, 4);
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(11, 3);
});
6 changes: 3 additions & 3 deletions test/browser/column/renderCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { page, userEvent } from 'vitest/browser';
import { DataGrid } from '../../../src';
import type { Column } from '../../../src';
import defaultRenderHeaderCell from '../../../src/renderHeaderCell';
import { getCellsAtRowIndex, setup } from '../utils';
import { getCellsAtRowIndex, safeTab, setup } from '../utils';

const cells = page.getCell();

Expand Down Expand Up @@ -144,15 +144,15 @@ test('Focus child if it sets tabIndex', async () => {
await userEvent.click(page.getByText('Text'));
await expect.element(button1).toHaveFocus();
await expect.element(button1).toHaveAttribute('tabindex', '0');
await userEvent.tab({ shift: true });
await safeTab(true);
await expect.element(button1).not.toHaveFocus();
await expect.element(button1).toHaveAttribute('tabindex', '-1');
await expect.element(cell).toHaveAttribute('tabindex', '-1');
await userEvent.click(button1);
await expect.element(button1).toHaveFocus();
await expect.element(button1).toHaveAttribute('tabindex', '0');
await expect.element(cell).toHaveAttribute('tabindex', '-1');
await userEvent.tab({ shift: true });
await safeTab(true);
await userEvent.click(button2);
await expect.element(button2).toHaveFocus();
// It is user's responsibilty to set the tabIndex on button2
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/renderEditCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { page, userEvent } from 'vitest/browser';

import { DataGrid } from '../../../src';
import type { Column, DataGridProps } from '../../../src';
import { getCellsAtRowIndex, getRowWithCell, scrollGrid, testCount } from '../utils';
import { getCellsAtRowIndex, getRowWithCell, safeTab, scrollGrid, testCount } from '../utils';

const grid = page.getGrid();

Expand All @@ -22,7 +22,7 @@ describe('Editor', () => {
await userEvent.dblClick(getCellsAtRowIndex(0).nth(0));
await expect.element(editor).toHaveValue(1);
await userEvent.keyboard('2');
await userEvent.tab();
await safeTab();
await expect.element(editor).not.toBeInTheDocument();
await expect.element(getCellsAtRowIndex(0).nth(0)).toHaveTextContent(/^12$/);
});
Expand Down
4 changes: 2 additions & 2 deletions test/browser/copyPaste.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { page, userEvent } from 'vitest/browser';

import { DataGrid } from '../../src';
import type { CellPasteArgs, Column } from '../../src';
import { getCellsAtRowIndex } from './utils';
import { getCellsAtRowIndex, safeTab } from './utils';

interface Row {
col: string;
Expand Down Expand Up @@ -116,7 +116,7 @@ test('should allow copying a readonly cell', async () => {

test('should not allow copy/paste on header or summary cells', async () => {
await setup();
await userEvent.tab();
await safeTab();
await userEvent.copy();
expect(onCellCopySpy).not.toHaveBeenCalled();
await userEvent.paste();
Expand Down
3 changes: 2 additions & 1 deletion test/browser/events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { page, userEvent } from 'vitest/browser';

import { DataGrid } from '../../src';
import type { Column, DataGridProps } from '../../src';
import { safeTab } from './utils';

interface Row {
col1: number;
Expand Down Expand Up @@ -162,7 +163,7 @@ describe('Events', () => {
expect(onSelectedCellChange).toHaveBeenCalledTimes(4);

// Selected by tab key
await userEvent.keyboard('{Tab}');
await safeTab();
expect(onSelectedCellChange).toHaveBeenLastCalledWith({
column: expect.objectContaining(columns[1]),
row: rows[0],
Expand Down
51 changes: 26 additions & 25 deletions test/browser/keyboardNavigation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataGrid, SelectColumn } from '../../src';
import type { Column } from '../../src';
import {
getRowWithCell,
safeTab,
scrollGrid,
setup,
tabIntoGrid,
Expand Down Expand Up @@ -40,11 +41,11 @@ test('keyboard navigation', async () => {
await validateCellPosition(0, 0);

// tab to the next cell
await userEvent.tab();
await safeTab();
await validateCellPosition(1, 0);

// tab back to the previous cell
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(0, 0);

// arrow navigation
Expand Down Expand Up @@ -97,11 +98,11 @@ test('keyboard navigation', async () => {

// tab at the end of a row selects the first cell on the next row
await userEvent.keyboard('{end}');
await userEvent.tab();
await safeTab();
await validateCellPosition(0, 1);

// shift tab should select the last cell of the previous row
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(6, 0);
});

Expand All @@ -122,11 +123,11 @@ test('arrow and tab navigation', async () => {
await validateCellPosition(6, 1);

// pressing tab on the rightmost cell navigates to the leftmost cell on the next row
await userEvent.tab();
await safeTab();
await validateCellPosition(0, 2);

// pressing shift+tab on the leftmost cell navigates to the rightmost cell on the previous row
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(6, 1);
});

Expand All @@ -144,10 +145,10 @@ test('grid enter/exit', async () => {
await validateCellPosition(0, 0);

// shift+tab tabs out of the grid if we are at the first cell
await userEvent.tab({ shift: true });
await safeTab(true);
await expect.element(beforeButton).toHaveFocus();

await userEvent.tab();
await safeTab();
await validateCellPosition(0, 0);

await userEvent.keyboard('{arrowdown}{arrowdown}');
Expand All @@ -156,19 +157,19 @@ test('grid enter/exit', async () => {
// tab should select the last selected cell
// click outside the grid
await userEvent.click(beforeButton);
await userEvent.tab();
await safeTab();
await userEvent.keyboard('{arrowdown}');
await validateCellPosition(0, 3);

// shift+tab should select the last selected cell
await userEvent.click(afterButton);
await userEvent.tab({ shift: true });
await safeTab(true);
await validateCellPosition(0, 3);
await expect.element(selectedCell.getByRole('checkbox')).toHaveFocus();

// tab tabs out of the grid if we are at the last cell
await userEvent.keyboard('{Control>}{end}{/Control}');
await userEvent.tab();
await safeTab();
await expect.element(afterButton).toHaveFocus();
});

Expand All @@ -184,7 +185,7 @@ test('navigation with focusable cell renderer', async () => {
await expect.element(checkbox).toHaveFocus();
await expect.element(checkbox).toHaveAttribute('tabIndex', '0');

await userEvent.tab();
await safeTab();
await validateCellPosition(1, 1);
// cell should set tabIndex to 0 if it does not have focusable cell renderer
await expect.element(selectedCell).toHaveAttribute('tabIndex', '0');
Expand Down Expand Up @@ -223,31 +224,31 @@ test('navigation when header and summary rows have focusable elements', async ()
// should set focus on the header filter
await expect.element(page.getByTestId('header-filter1')).toHaveFocus();

await userEvent.tab();
await safeTab();
await expect.element(page.getByTestId('header-filter2')).toHaveFocus();

await userEvent.tab();
await safeTab();
await validateCellPosition(0, 1);

await userEvent.tab({ shift: true });
await safeTab(true);
await expect.element(page.getByTestId('header-filter2')).toHaveFocus();

await userEvent.tab({ shift: true });
await safeTab(true);
await expect.element(page.getByTestId('header-filter1')).toHaveFocus();

await userEvent.tab();
await userEvent.tab();
await safeTab();
await safeTab();
await userEvent.keyboard('{Control>}{end}{/Control}{arrowup}{arrowup}');
await validateCellPosition(1, 2);

await userEvent.tab();
await safeTab();
await expect.element(page.getByTestId('summary-col2-1')).toHaveFocus();

await userEvent.tab();
await safeTab();
await expect.element(page.getByTestId('summary-col3-1')).toHaveFocus();

await userEvent.tab({ shift: true });
await userEvent.tab({ shift: true });
await safeTab(true);
await safeTab(true);
await validateCellPosition(1, 2);
await expect.element(selectedCell).toHaveFocus();
});
Expand Down Expand Up @@ -297,7 +298,7 @@ test('reset selected cell when column is removed', async () => {

const { rerender } = await page.render(<Test columns={columns} />);

await userEvent.tab();
await safeTab();
await userEvent.keyboard('{arrowdown}{arrowright}');
await validateCellPosition(1, 1);

Expand All @@ -319,7 +320,7 @@ test('reset selected cell when row is removed', async () => {

const { rerender } = await page.render(<Test rows={rows} />);

await userEvent.tab();
await safeTab();
await userEvent.keyboard('{arrowdown}{arrowdown}{arrowright}');
await validateCellPosition(1, 2);

Expand All @@ -332,7 +333,7 @@ test('should not change the left and right arrow behavior for right to left lang
await setup<Row, Row>({ columns, rows, direction: 'rtl' }, true);
await tabIntoGrid();
await validateCellPosition(0, 0);
await userEvent.tab();
await safeTab();
await validateCellPosition(1, 0);
await userEvent.keyboard('{arrowright}');
await validateCellPosition(0, 0);
Expand Down
3 changes: 2 additions & 1 deletion test/browser/renderTextEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { page, userEvent } from 'vitest/browser';

import { DataGrid, renderTextEditor } from '../../src';
import type { Column } from '../../src';
import { safeTab } from './utils';

interface Row {
readonly name: string;
Expand Down Expand Up @@ -48,7 +49,7 @@ test('renderTextEditor', async () => {
// blurring the input closes and commits the editor
await userEvent.dblClick(cell);
await userEvent.fill(input, 'Jim Milton');
await userEvent.tab();
await safeTab();
await expect.element(input).not.toBeInTheDocument();
await expect.element(cell).toHaveTextContent(/^Jim Milton$/);
});
Loading