Skip to content

Commit

Permalink
Remove setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 committed Nov 19, 2024
1 parent 292793b commit 1933b86
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 69 deletions.
10 changes: 5 additions & 5 deletions test/browser/column/cellClass.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Column } from '../../../src';
import { cellClassname } from '../../../src/style/cell';
import { getCells, setupNew } from '../utils';
import { getCells, setup } from '../utils';

interface Row {
id: number;
Expand All @@ -15,7 +15,7 @@ test('cellClass is undefined', async () => {
name: 'ID'
}
];
setupNew({ columns, rows });
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
Expand All @@ -29,7 +29,7 @@ test('cellClass is a string', async () => {
cellClass: 'my-cell'
}
];
setupNew({ columns, rows });
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 });
Expand All @@ -43,7 +43,7 @@ test('cellClass returns a string', async () => {
cellClass: (row) => `my-cell-${row.id}`
}
];
setupNew({ columns, rows });
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 });
Expand All @@ -57,7 +57,7 @@ test('cellClass returns undefined', async () => {
cellClass: () => undefined
}
];
setupNew({ columns, rows });
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
Expand Down
4 changes: 2 additions & 2 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, setupNew, validateCellPositionOld } from '../utils';
import { getCellsAtRowIndexOld, getHeaderCells, setup, validateCellPositionOld } from '../utils';

describe('colSpan', () => {
function setupColSpanGrid(colCount = 15) {
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('colSpan', () => {
}
});
}
setupNew({ columns, rows, bottomSummaryRows: [1, 2], topSummaryRows: [1, 2] });
setup({ columns, rows, bottomSummaryRows: [1, 2], topSummaryRows: [1, 2] });
}

it('should merges cells', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/draggable.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 { getHeaderCells, setupNew } from '../utils';
import { getHeaderCells, setup } from '../utils';

const columns: readonly Column<never>[] = [
{
Expand All @@ -27,7 +27,7 @@ const columns: readonly Column<never>[] = [

test('draggable columns', async () => {
const onColumnsReorder = vi.fn();
setupNew({ columns, rows: [], onColumnsReorder });
setup({ columns, rows: [], onColumnsReorder });
const [cell1, cell2, cell3, cell4] = getHeaderCells();

await expect.element(cell1).not.toHaveAttribute('draggable');
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/frozen.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Column } from '../../../src';
import { cellClassname, cellFrozenClassname } from '../../../src/style/cell';
import { getHeaderCells, setupNew } from '../utils';
import { getHeaderCells, setup } from '../utils';

test('frozen column have a specific class, and are stable-sorted before non-frozen columns', async () => {
const columns: readonly Column<never>[] = [
Expand All @@ -25,7 +25,7 @@ test('frozen column have a specific class, and are stable-sorted before non-froz
}
];

setupNew({ columns, rows: [] });
setup({ columns, rows: [] });
const [cell1, cell2, cell3, cell4] = getHeaderCells();

await expect
Expand Down
6 changes: 3 additions & 3 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/context';

import type { ColumnOrColumnGroup } from '../../../src';
import { getSelectedCell, setupNew, validateCellPosition } from '../utils';
import { getSelectedCell, setup, validateCellPosition } from '../utils';

const columns: readonly ColumnOrColumnGroup<NonNullable<unknown>>[] = [
{ key: 'col1', name: 'col 1' },
Expand Down Expand Up @@ -88,7 +88,7 @@ const columns: readonly ColumnOrColumnGroup<NonNullable<unknown>>[] = [
];

test('grouping', async () => {
setupNew({ columns, rows: [{}] });
setup({ columns, rows: [{}] });

const grid = page.getByRole('grid');
await expect.element(grid).toHaveAttribute('aria-colcount', '12');
Expand Down Expand Up @@ -248,7 +248,7 @@ test('grouping', async () => {
});

test('keyboard navigation', async () => {
setupNew({ columns, rows: [{}] });
setup({ columns, rows: [{}] });

// no initial selection
await expect.element(getSelectedCell()).not.toBeInTheDocument();
Expand Down
6 changes: 3 additions & 3 deletions test/browser/column/headerCellClass.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Column, ColumnGroup } from '../../../src';
import { cellClassname } from '../../../src/style/cell';
import { getHeaderCells, setupNew } from '../utils';
import { getHeaderCells, setup } from '../utils';

test('headerCellClass is either nullish or a string', async () => {
const columns: readonly Column<never>[] = [
Expand All @@ -15,7 +15,7 @@ test('headerCellClass is either nullish or a string', async () => {
}
];

setupNew({ columns, rows: [] });
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 });
Expand All @@ -34,7 +34,7 @@ test('columnGroup.headerCellClass is either nullish or a string', async () => {
}
];

setupNew({ columns, rows: [] });
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 });
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/key.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Column } from '../../../src';
import { setupNew } from '../utils';
import { setup } from '../utils';

test('key is escaped in query selectors', () => {
const columns: readonly Column<never>[] = [
Expand All @@ -10,6 +10,6 @@ test('key is escaped in query selectors', () => {
];

expect(() => {
setupNew({ columns, rows: [] });
setup({ columns, rows: [] });
}).not.toThrow();
});
4 changes: 2 additions & 2 deletions test/browser/column/name.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Column } from '../../../src';
import { getHeaderCells, setupNew } from '../utils';
import { getHeaderCells, setup } from '../utils';

test('name is either a string or an element', async () => {
function Header() {
Expand All @@ -17,7 +17,7 @@ test('name is either a string or an element', async () => {
}
];

setupNew({ columns, rows: [] });
setup({ columns, rows: [] });
const [cell1, cell2] = getHeaderCells();
await expect.element(cell1).toHaveTextContent('ID');
await expect.element(cell2).toHaveTextContent('Fancy');
Expand Down
8 changes: 4 additions & 4 deletions test/browser/column/renderCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { page, userEvent } from '@vitest/browser/context';

import DataGrid from '../../../src';
import type { Column } from '../../../src';
import { getCells, getCellsAtRowIndexOld, setupNew } from '../utils';
import { getCells, getCellsAtRowIndexOld, setup } from '../utils';

interface Row {
id: number;
Expand All @@ -18,14 +18,14 @@ describe('renderValue', () => {
const rows: readonly Row[] = [{ id: 101 }];

it('should be used by default', async () => {
setupNew({ columns, rows });
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveTextContent('101');
await expect.element(cell2).toBeEmptyDOMElement();
});

it('should handle non-object values', async () => {
setupNew({ columns, rows: [null] });
setup({ columns, rows: [null] });
const [cell1, cell2] = getCells();
await expect.element(cell1).toBeEmptyDOMElement();
await expect.element(cell2).toBeEmptyDOMElement();
Expand All @@ -49,7 +49,7 @@ describe('Custom cell renderer', () => {
const rows: readonly Row[] = [{ id: 101 }];

it('should replace the default cell renderer', async () => {
setupNew({ columns, rows });
setup({ columns, rows });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveTextContent('#101');
await expect.element(cell2).toHaveTextContent('No name');
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/renderHeaderCell.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Column } from '../../../src';
import { getHeaderCells, setupNew } from '../utils';
import { getHeaderCells, setup } from '../utils';

test('renderHeaderCell is either undefined or a component', async () => {
const columns: readonly Column<never>[] = [
Expand All @@ -14,7 +14,7 @@ test('renderHeaderCell is either undefined or a component', async () => {
}
];

setupNew({ columns, rows: [] });
setup({ columns, rows: [] });
const [cell1, cell2] = getHeaderCells();
await expect.element(cell1).toHaveTextContent('ID');
await expect.element(cell2).toHaveTextContent('Fancy! Name');
Expand Down
4 changes: 2 additions & 2 deletions test/browser/column/renderSummaryCell.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Column } from '../../../src';
import { getCells, setupNew } from '../utils';
import { getCells, setup } from '../utils';

interface SummaryRow {
id: number;
Expand All @@ -22,7 +22,7 @@ const columns: readonly Column<never, SummaryRow>[] = [
];

test('renderSummaryCell', async () => {
setupNew({
setup({
columns,
rows: [],
topSummaryRows: [
Expand Down
12 changes: 3 additions & 9 deletions test/browser/column/resizable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { act } from 'react';
import { commands, userEvent } from '@vitest/browser/context';

import type { Column } from '../../../src';
Expand Down Expand Up @@ -32,19 +31,14 @@ interface ResizeArgs {
async function resize({ column, resizeBy }: ResizeArgs) {
expect(getResizeHandle(column)).toBeInTheDocument();

await act(async () => {
// @ts-expect-error
await commands.resizeColumn(resizeBy);
});
// @ts-expect-error
await commands.resizeColumn(resizeBy);
}

async function autoResize(column: Element) {
const resizeHandle = getResizeHandle(column);

// eslint-disable-next-line testing-library/no-unnecessary-act
await act(async () => {
await userEvent.dblClick(resizeHandle);
});
await userEvent.dblClick(resizeHandle);
}

const columns: readonly Column<Row>[] = [
Expand Down
10 changes: 5 additions & 5 deletions test/browser/column/summaryCellClass.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Column } from '../../../src';
import { cellClassname as cellClass } from '../../../src/style/cell';
import { summaryCellClassname } from '../../../src/SummaryCell';
import { getCells, setupNew } from '../utils';
import { getCells, setup } from '../utils';

interface SummaryRow {
id: number;
Expand All @@ -18,7 +18,7 @@ test('summaryCellClass is undefined', async () => {
name: 'ID'
}
];
setupNew({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
setup({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
const [cell1, cell2] = getCells();
await expect.element(cell1).toHaveClass(cellClassname, { exact: true });
await expect.element(cell2).toHaveClass(cellClassname, { exact: true });
Expand All @@ -32,7 +32,7 @@ test('summaryCellClass is a string', async () => {
summaryCellClass: 'my-cell'
}
];
setupNew({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
setup({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
const cells = getCells();
for (const cell of cells) {
await expect.element(cell).toHaveClass(`${cellClassname} my-cell`, { exact: true });
Expand All @@ -47,7 +47,7 @@ test('summaryCellClass returns a string', async () => {
summaryCellClass: (row) => `my-cell-${row.id}`
}
];
setupNew({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
setup({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
const [cell1, cell2, cell3, cell4] = getCells();
await expect.element(cell1).toHaveClass(`${cellClassname} my-cell-0`, { exact: true });
await expect.element(cell2).toHaveClass(`${cellClassname} my-cell-1`, { exact: true });
Expand All @@ -63,7 +63,7 @@ test('summaryCellClass returns undefined', async () => {
summaryCellClass: () => undefined
}
];
setupNew({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
setup({ columns, topSummaryRows, bottomSummaryRows, rows: [] });
const cells = getCells();
for (const cell of cells) {
await expect.element(cell).toHaveClass(cellClassname, { exact: true });
Expand Down
8 changes: 4 additions & 4 deletions test/browser/direction.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import userEvent from '@testing-library/user-event';

import type { Column } from '../../src';
import { getGrid, getSelectedCell, setupNew } from './utils';
import { getGrid, getSelectedCell, setup } from './utils';

interface Row {
id: number;
Expand All @@ -22,7 +22,7 @@ const columns: readonly Column<Row>[] = [
const rows: readonly Row[] = [];

test('should use left to right direction by default', async () => {
setupNew({ rows, columns });
setup({ rows, columns });
await expect.element(getGrid()).toHaveAttribute('dir', 'ltr');
await userEvent.tab();
await expect.element(getSelectedCell()).toHaveTextContent('ID');
Expand All @@ -31,7 +31,7 @@ test('should use left to right direction by default', async () => {
});

test('should use left to right direction if direction prop is set to ltr', async () => {
setupNew({ rows, columns, direction: 'ltr' });
setup({ rows, columns, direction: 'ltr' });
await expect.element(getGrid()).toHaveAttribute('dir', 'ltr');
await userEvent.tab();
await expect.element(getSelectedCell()).toHaveTextContent('ID');
Expand All @@ -40,7 +40,7 @@ test('should use left to right direction if direction prop is set to ltr', async
});

test('should use right to left direction if direction prop is set to rtl', async () => {
setupNew({ rows, columns, direction: 'rtl' });
setup({ rows, columns, direction: 'rtl' });
await expect.element(getGrid()).toHaveAttribute('dir', 'rtl');
await userEvent.tab();
await expect.element(getSelectedCell()).toHaveTextContent('ID');
Expand Down
Loading

0 comments on commit 1933b86

Please sign in to comment.