|
| 1 | +import { page } from 'vitest/browser'; |
| 2 | + |
| 3 | +import { DataGrid, SelectColumn, type Column } from '../../src'; |
| 4 | +import { getGrid } from '../browser/utils'; |
| 5 | + |
| 6 | +interface Row { |
| 7 | + id: number; |
| 8 | + name: string; |
| 9 | +} |
| 10 | + |
| 11 | +const columns: readonly Column<Row, Row>[] = [ |
| 12 | + SelectColumn, |
| 13 | + { |
| 14 | + key: 'name', |
| 15 | + name: 'Name', |
| 16 | + renderSummaryCell(props) { |
| 17 | + return props.row.name; |
| 18 | + } |
| 19 | + } |
| 20 | +]; |
| 21 | + |
| 22 | +const rows: readonly Row[] = [ |
| 23 | + { id: 1, name: 'Row 1' }, |
| 24 | + { id: 2, name: 'Row 2' }, |
| 25 | + { id: 3, name: 'Row 3' } |
| 26 | +]; |
| 27 | + |
| 28 | +const topSummaryRows: readonly Row[] = [ |
| 29 | + { id: 4, name: 'Top Summary Row 1' }, |
| 30 | + { id: 5, name: 'Top Summary Row 2' } |
| 31 | +]; |
| 32 | + |
| 33 | +const bottomSummaryRows: readonly Row[] = [ |
| 34 | + { id: 6, name: 'Bottom Summary Row 1' }, |
| 35 | + { id: 7, name: 'Bottom Summary Row 2' } |
| 36 | +]; |
| 37 | + |
| 38 | +function rowKeyGetter(row: Row) { |
| 39 | + return row.id; |
| 40 | +} |
| 41 | + |
| 42 | +test('basic grid', async () => { |
| 43 | + await page.render( |
| 44 | + <DataGrid |
| 45 | + rowKeyGetter={rowKeyGetter} |
| 46 | + columns={columns} |
| 47 | + rows={rows} |
| 48 | + topSummaryRows={topSummaryRows} |
| 49 | + bottomSummaryRows={bottomSummaryRows} |
| 50 | + /> |
| 51 | + ); |
| 52 | + |
| 53 | + await expect(getGrid()).toMatchScreenshot('basic-grid'); |
| 54 | +}); |
0 commit comments