Skip to content

Commit e71109b

Browse files
committed
Add VRT for TreeDataGrid
1 parent fbc541e commit e71109b

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/visual/treeGrid.test.tsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { page } from 'vitest/browser';
2+
3+
import { SelectColumn, TreeDataGrid, type Column } from '../../src';
4+
import { getGrid } from '../browser/utils';
5+
6+
interface Row {
7+
id: number;
8+
country: string;
9+
year: number;
10+
}
11+
12+
type SummaryRow = undefined;
13+
14+
const topSummaryRows: readonly SummaryRow[] = [undefined];
15+
const bottomSummaryRows: readonly SummaryRow[] = [undefined];
16+
17+
const columns: readonly Column<Row, SummaryRow>[] = [
18+
SelectColumn,
19+
{
20+
key: 'sport',
21+
name: 'Sport'
22+
},
23+
{
24+
key: 'country',
25+
name: 'Country'
26+
},
27+
{
28+
key: 'year',
29+
name: 'Year'
30+
},
31+
{
32+
key: 'id',
33+
name: 'Id',
34+
renderGroupCell({ childRows }) {
35+
return Math.min(...childRows.map((c) => c.id));
36+
}
37+
}
38+
];
39+
40+
const rows: readonly Row[] = [
41+
{
42+
id: 1,
43+
country: 'USA',
44+
year: 2020
45+
},
46+
{
47+
id: 2,
48+
country: 'USA',
49+
year: 2021
50+
},
51+
{
52+
id: 3,
53+
country: 'Canada',
54+
year: 2021
55+
},
56+
{
57+
id: 4,
58+
country: 'Canada',
59+
year: 2022
60+
}
61+
];
62+
63+
test('tree grid', async () => {
64+
await page.render(
65+
<TreeDataGrid
66+
rowKeyGetter={rowKeyGetter}
67+
columns={columns}
68+
rows={rows}
69+
topSummaryRows={topSummaryRows}
70+
bottomSummaryRows={bottomSummaryRows}
71+
groupBy={['country', 'year']}
72+
rowGrouper={rowGrouper}
73+
expandedGroupIds={new Set(['USA', 2020])}
74+
onExpandedGroupIdsChange={() => {}}
75+
/>
76+
);
77+
78+
await expect(getGrid()).toMatchScreenshot('tree-grid');
79+
});
80+
81+
function rowKeyGetter(row: Row) {
82+
return row.id;
83+
}
84+
85+
function rowGrouper(rows: readonly Row[], columnKey: string) {
86+
// @ts-expect-error
87+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
88+
return Object.groupBy(rows, (r) => r[columnKey]) as Record<string, readonly R[]>;
89+
}

0 commit comments

Comments
 (0)