Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1d84213
Start migrating remaining tests
amanmahajan7 Nov 21, 2024
120e395
-1
amanmahajan7 Nov 21, 2024
1027683
-1
amanmahajan7 Nov 21, 2024
b0e701d
-1
amanmahajan7 Nov 21, 2024
f4a79b7
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Nov 22, 2024
447d85e
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Nov 22, 2024
2a21212
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Jan 7, 2025
0a6ca5e
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Jan 7, 2025
48a6016
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 1, 2025
259d83b
Save changes
amanmahajan7 Mar 5, 2025
7c5c7dc
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 5, 2025
8d8ca91
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 12, 2025
1d1218b
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 14, 2025
fa1c707
Migrate remaining tests
amanmahajan7 Mar 14, 2025
efa80cf
-1
amanmahajan7 Mar 14, 2025
49b6d0e
revert `getCellsAtRowIndex`
amanmahajan7 Mar 14, 2025
3e15758
Remove `@testing-library/react` usage
amanmahajan7 Mar 14, 2025
403f1d6
Uninstall testing-library
amanmahajan7 Mar 14, 2025
1f30662
- async
amanmahajan7 Mar 14, 2025
f13252a
Import browser userEvent
amanmahajan7 Mar 14, 2025
ad9d7a3
Fix scroll
amanmahajan7 Mar 14, 2025
8dfd131
Install `@testing-library/dom`
amanmahajan7 Mar 14, 2025
e06fdac
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 19, 2025
dfd9294
-1
amanmahajan7 Mar 19, 2025
b9235f5
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 19, 2025
5a16b94
Fix last test
amanmahajan7 Mar 19, 2025
cf2ab47
Add back `userEvent` for consistency
amanmahajan7 Mar 19, 2025
381d5a5
Merge branch 'main' into am-migrate-remaining-tests
amanmahajan7 Mar 19, 2025
8042334
uninstall @testing-library/dom
nstepien Mar 19, 2025
0df0bad
Address comments
amanmahajan7 Mar 19, 2025
faf38b4
Check if selected cell has focus
amanmahajan7 Mar 19, 2025
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
6 changes: 1 addition & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,6 @@ export default defineConfig([
name: 'react-dom',
importNames: ['default'],
message: 'Use named imports instead.'
},
{
name: '@testing-library/dom',
message: 'Import @testing-library/react instead.'
}
],
'@typescript-eslint/no-shadow': 0,
Expand Down Expand Up @@ -702,7 +698,7 @@ export default defineConfig([
'testing-library/prefer-explicit-assert': 1,
'testing-library/prefer-find-by': 1,
'testing-library/prefer-implicit-assert': 0,
'testing-library/prefer-presence-queries': 1,
'testing-library/prefer-presence-queries': 0,
'testing-library/prefer-query-by-disappearance': 1,
'testing-library/prefer-query-matchers': 0,
'testing-library/prefer-screen-queries': 0,
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
"@microsoft/api-extractor": "^7.50.0",
"@tanstack/react-router": "^1.114.16",
"@tanstack/router-plugin": "^1.114.16",
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^22.13.1",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
Expand Down
195 changes: 97 additions & 98 deletions test/browser/TreeDataGrid.test.tsx

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions test/browser/column/cellClass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Row {

const rows: readonly Row[] = [{ id: 0 }, { id: 1 }];

test('cellClass is undefined', async () => {
test('cellClass is undefined', () => {
const columns: readonly Column<Row>[] = [
{
key: 'id',
Expand All @@ -17,11 +17,11 @@ test('cellClass is undefined', async () => {
];
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
expect(cell1).toHaveClass(cellClassname, { exact: true });
expect(cell2).toHaveClass(cellClassname, { exact: true });
});

test('cellClass is a string', async () => {
test('cellClass is a string', () => {
const columns: readonly Column<Row>[] = [
{
key: 'id',
Expand All @@ -31,11 +31,11 @@ test('cellClass is a string', async () => {
];
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(`${cellClassname} my-cell`, { exact: true });
await expect.element(cell2).toHaveClass(`${cellClassname} my-cell`, { exact: true });
expect(cell1).toHaveClass(`${cellClassname} my-cell`, { exact: true });
expect(cell2).toHaveClass(`${cellClassname} my-cell`, { exact: true });
});

test('cellClass returns a string', async () => {
test('cellClass returns a string', () => {
const columns: readonly Column<Row>[] = [
{
key: 'id',
Expand All @@ -45,11 +45,11 @@ test('cellClass returns a string', async () => {
];
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(`${cellClassname} my-cell-0`, { exact: true });
await expect.element(cell2).toHaveClass(`${cellClassname} my-cell-1`, { exact: true });
expect(cell1).toHaveClass(`${cellClassname} my-cell-0`, { exact: true });
expect(cell2).toHaveClass(`${cellClassname} my-cell-1`, { exact: true });
});

test('cellClass returns undefined', async () => {
test('cellClass returns undefined', () => {
const columns: readonly Column<Row>[] = [
{
key: 'id',
Expand All @@ -59,6 +59,6 @@ test('cellClass returns undefined', async () => {
];
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
expect(cell1).toHaveClass(cellClassname, { exact: true });
expect(cell2).toHaveClass(cellClassname, { exact: true });
});
100 changes: 50 additions & 50 deletions test/browser/column/colSpan.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { userEvent } from '@vitest/browser/context';

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

describe('colSpan', () => {
function setupColSpanGrid(colCount = 15) {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('colSpan', () => {
expect(getHeaderCells()).toHaveLength(13);

// top summary rows
const topSummarryRow1 = getCellsAtRowIndexOld(0);
const topSummarryRow1 = getCellsAtRowIndex(0);
expect(topSummarryRow1).toHaveLength(14);
// 7th-8th cells are merged
expect(topSummarryRow1[7]).toHaveAttribute('aria-colindex', '8');
Expand All @@ -52,10 +52,10 @@ describe('colSpan', () => {
'grid-column-start': '8',
'grid-column-end': '10'
});
expect(getCellsAtRowIndexOld(1)).toHaveLength(15);
expect(getCellsAtRowIndex(1)).toHaveLength(15);

// rows
const row1 = getCellsAtRowIndexOld(3);
const row1 = getCellsAtRowIndex(3);
expect(row1).toHaveLength(14);
// 7th-8th cells are merged
expect(row1[6]).toHaveAttribute('aria-colindex', '7');
Expand All @@ -68,7 +68,7 @@ describe('colSpan', () => {
expect(row1[7]).not.toHaveAttribute('aria-colspan');

// 3rd-5th, 7th-8th cells are merged
const row2 = getCellsAtRowIndexOld(4);
const row2 = getCellsAtRowIndex(4);
expect(row2).toHaveLength(12);
expect(row2[2]).toHaveAttribute('aria-colindex', '3');
expect(row2[2]).toHaveStyle({
Expand All @@ -84,95 +84,95 @@ describe('colSpan', () => {
});
expect(row2[5]).toHaveAttribute('aria-colindex', '9');

expect(getCellsAtRowIndexOld(6)).toHaveLength(14); // colSpan 6 won't work as there are 5 frozen columns
expect(getCellsAtRowIndexOld(7)).toHaveLength(10);
expect(getCellsAtRowIndex(6)).toHaveLength(14); // colSpan 6 won't work as there are 5 frozen columns
expect(getCellsAtRowIndex(7)).toHaveLength(10);

// bottom summary row
expect(getCellsAtRowIndexOld(12)).toHaveLength(14);
expect(getCellsAtRowIndexOld(13)).toHaveLength(15);
expect(getCellsAtRowIndex(12)).toHaveLength(14);
expect(getCellsAtRowIndex(13)).toHaveLength(15);
});

it('should navigate between merged cells', async () => {
setupColSpanGrid();
// header row
await userEvent.click(getHeaderCells()[7]);
validateCellPositionOld(7, 0);
validateCellPosition(7, 0);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(8, 0);
validateCellPosition(8, 0);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(11, 0);
validateCellPosition(11, 0);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(12, 0);
validateCellPosition(12, 0);
await userEvent.keyboard('{arrowleft}{arrowleft}{arrowleft}');
validateCellPositionOld(7, 0);
validateCellPosition(7, 0);

// top summary rows
await userEvent.click(getCellsAtRowIndexOld(0)[6]);
validateCellPositionOld(6, 1);
await userEvent.click(getCellsAtRowIndex(0)[6]);
validateCellPosition(6, 1);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(7, 1);
validateCellPosition(7, 1);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(9, 1);
validateCellPosition(9, 1);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(10, 1);
validateCellPosition(10, 1);
await userEvent.keyboard('{arrowleft}{arrowleft}{arrowleft}');
validateCellPositionOld(6, 1);
validateCellPosition(6, 1);

// viewport rows
await userEvent.click(getCellsAtRowIndexOld(3)[1]);
validateCellPositionOld(1, 4);
await userEvent.click(getCellsAtRowIndex(3)[1]);
validateCellPosition(1, 4);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(2, 4);
validateCellPosition(2, 4);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(3, 4);
validateCellPosition(3, 4);
await userEvent.keyboard('{arrowdown}');
validateCellPositionOld(2, 5);
validateCellPosition(2, 5);
await userEvent.keyboard('{arrowleft}');
validateCellPositionOld(1, 5);
validateCellPosition(1, 5);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(2, 5);
validateCellPosition(2, 5);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(5, 5);
validateCellPosition(5, 5);
await userEvent.keyboard('{arrowleft}');
validateCellPositionOld(2, 5);
validateCellPosition(2, 5);
await userEvent.keyboard('{arrowdown}');
validateCellPositionOld(2, 6);
validateCellPosition(2, 6);
await userEvent.keyboard('{arrowdown}{arrowdown}');
validateCellPositionOld(0, 8);
validateCellPosition(0, 8);
await userEvent.keyboard('{arrowLeft}');
validateCellPositionOld(0, 8);
validateCellPosition(0, 8);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(5, 8);
validateCellPosition(5, 8);
await userEvent.tab({ shift: true });
await userEvent.tab({ shift: true });
validateCellPositionOld(14, 7);
validateCellPosition(14, 7);
await userEvent.tab();
validateCellPositionOld(0, 8);
await userEvent.click(getCellsAtRowIndexOld(10)[11]);
validateCellPositionOld(11, 11);
validateCellPosition(0, 8);
await userEvent.click(getCellsAtRowIndex(10)[11]);
validateCellPosition(11, 11);
await userEvent.tab();
validateCellPositionOld(12, 11);
validateCellPosition(12, 11);
await userEvent.tab();
validateCellPositionOld(0, 12);
validateCellPosition(0, 12);
await userEvent.tab({ shift: true });
validateCellPositionOld(12, 11);
validateCellPosition(12, 11);

// bottom summary rows
await userEvent.click(getCellsAtRowIndexOld(12)[6]);
validateCellPositionOld(6, 13);
await userEvent.click(getCellsAtRowIndex(12)[6]);
validateCellPosition(6, 13);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(7, 13);
validateCellPosition(7, 13);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(9, 13);
validateCellPosition(9, 13);
await userEvent.keyboard('{arrowright}');
validateCellPositionOld(10, 13);
validateCellPosition(10, 13);
await userEvent.keyboard('{arrowleft}{arrowleft}{arrowleft}');
validateCellPositionOld(6, 13);
validateCellPosition(6, 13);
});

it('should scroll to the merged cell when selected', async () => {
setupColSpanGrid(30);
await userEvent.click(getCellsAtRowIndexOld(10)[23]); // last visible cell (1920/80)
await userEvent.click(getCellsAtRowIndex(10)[23]); // last visible cell (1920/80)
const spy = vi.spyOn(window.HTMLElement.prototype, 'scrollIntoView');
const testScrollIntoView = () => {
expect(spy).toHaveBeenCalled();
Expand All @@ -182,13 +182,13 @@ describe('colSpan', () => {
testScrollIntoView();
await navigate(1);
testScrollIntoView(); // should bring the merged cell into view
validateCellPositionOld(27, 11);
validateCellPosition(27, 11);
await navigate(7);
testScrollIntoView();
validateCellPositionOld(6, 12); // should navigate to the next row
validateCellPosition(6, 12); // should navigate to the next row
await navigate(7, true);
testScrollIntoView();
validateCellPositionOld(27, 11); // should navigate to the previous row
validateCellPosition(27, 11); // should navigate to the previous row
await navigate(27);
testScrollIntoView();
await navigate(1);
Expand Down
8 changes: 4 additions & 4 deletions test/browser/column/draggable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ test('draggable columns', async () => {
setup({ columns, rows: [], onColumnsReorder });
const [cell1, cell2, cell3, cell4] = getHeaderCells();

await expect.element(cell1).not.toHaveAttribute('draggable');
await expect.element(cell2).toHaveAttribute('draggable');
await expect.element(cell3).toHaveAttribute('draggable');
await expect.element(cell4).toHaveAttribute('draggable');
expect(cell1).not.toHaveAttribute('draggable');
expect(cell2).toHaveAttribute('draggable');
expect(cell3).toHaveAttribute('draggable');
expect(cell4).toHaveAttribute('draggable');

expect(onColumnsReorder).not.toHaveBeenCalled();

Expand Down
22 changes: 9 additions & 13 deletions test/browser/column/frozen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Column } from '../../../src';
import { cellClassname, cellFrozenClassname } from '../../../src/style/cell';
import { getHeaderCells, setup } from '../utils';

test('frozen column have a specific class, and are stable-sorted before non-frozen columns', async () => {
test('frozen column have a specific class, and are stable-sorted before non-frozen columns', () => {
const columns: readonly Column<never>[] = [
{
key: 'col1',
Expand All @@ -28,17 +28,13 @@ test('frozen column have a specific class, and are stable-sorted before non-froz
setup({ columns, rows: [] });
const [cell1, cell2, cell3, cell4] = getHeaderCells();

await expect
.element(cell1)
.toHaveClass(`${cellClassname} ${cellFrozenClassname}`, { exact: true });
await expect
.element(cell2)
.toHaveClass(`${cellClassname} ${cellFrozenClassname}`, { exact: true });
await expect.element(cell3).toHaveClass(cellClassname, { exact: true });
await expect.element(cell4).toHaveClass(cellClassname, { exact: true });
expect(cell1).toHaveClass(`${cellClassname} ${cellFrozenClassname}`, { exact: true });
expect(cell2).toHaveClass(`${cellClassname} ${cellFrozenClassname}`, { exact: true });
expect(cell3).toHaveClass(cellClassname, { exact: true });
expect(cell4).toHaveClass(cellClassname, { exact: true });

await expect.element(cell1).toHaveTextContent('col1');
await expect.element(cell2).toHaveTextContent('col3');
await expect.element(cell3).toHaveTextContent('col2');
await expect.element(cell4).toHaveTextContent('col4');
expect(cell1).toHaveTextContent('col1');
expect(cell2).toHaveTextContent('col3');
expect(cell3).toHaveTextContent('col2');
expect(cell4).toHaveTextContent('col4');
});
12 changes: 6 additions & 6 deletions test/browser/column/headerCellClass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Column, ColumnGroup } from '../../../src';
import { cellClassname } from '../../../src/style/cell';
import { getHeaderCells, setup } from '../utils';

test('headerCellClass is either nullish or a string', async () => {
test('headerCellClass is either nullish or a string', () => {
const columns: readonly Column<never>[] = [
{
key: 'id',
Expand All @@ -17,11 +17,11 @@ test('headerCellClass is either nullish or a string', async () => {

setup({ columns, rows: [] });
const [cell1, cell2] = getHeaderCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(`${cellClassname} my-header`, { exact: true });
expect(cell1).toHaveClass(cellClassname, { exact: true });
expect(cell2).toHaveClass(`${cellClassname} my-header`, { exact: true });
});

test('columnGroup.headerCellClass is either nullish or a string', async () => {
test('columnGroup.headerCellClass is either nullish or a string', () => {
const columns: readonly ColumnGroup<never>[] = [
{
name: 'Group 1',
Expand All @@ -36,6 +36,6 @@ test('columnGroup.headerCellClass is either nullish or a string', async () => {

setup({ columns, rows: [] });
const [cell1, cell2] = getHeaderCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(`${cellClassname} my-header`, { exact: true });
expect(cell1).toHaveClass(cellClassname, { exact: true });
expect(cell2).toHaveClass(`${cellClassname} my-header`, { exact: true });
});
6 changes: 3 additions & 3 deletions test/browser/column/name.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Column } from '../../../src';
import { getHeaderCells, setup } from '../utils';

test('name is either a string or an element', async () => {
test('name is either a string or an element', () => {
function Header() {
return 'Fancy';
}
Expand All @@ -19,6 +19,6 @@ test('name is either a string or an element', async () => {

setup({ columns, rows: [] });
const [cell1, cell2] = getHeaderCells();
await expect.element(cell1).toHaveTextContent('ID');
await expect.element(cell2).toHaveTextContent('Fancy');
expect(cell1).toHaveTextContent('ID');
expect(cell2).toHaveTextContent('Fancy');
});
Loading