Results.test.tsx61 lines · main
| 1 | import { screen } from '@testing-library/react' |
| 2 | import { expect, test, vi } from 'vitest' |
| 3 | |
| 4 | import Results from '@/components/interfaces/SQLEditor/UtilityPanel/Results' |
| 5 | import { customRender as render } from '@/tests/lib/custom-render' |
| 6 | |
| 7 | let contextMenuMountCount = 0 |
| 8 | |
| 9 | vi.mock('ui', async () => { |
| 10 | const actual = await vi.importActual<typeof import('ui')>('ui') |
| 11 | return { |
| 12 | ...actual, |
| 13 | ContextMenu: (props: any) => { |
| 14 | contextMenuMountCount++ |
| 15 | return <actual.ContextMenu {...props} /> |
| 16 | }, |
| 17 | } |
| 18 | }) |
| 19 | |
| 20 | vi.mock('react-data-grid', () => ({ |
| 21 | default: ({ columns, rows }: any) => ( |
| 22 | <div role="table"> |
| 23 | <div role="row"> |
| 24 | {columns.map((col: any, colIdx: number) => ( |
| 25 | <div key={colIdx} role="columnheader"> |
| 26 | {col.renderHeaderCell ? col.renderHeaderCell({}) : col.name} |
| 27 | </div> |
| 28 | ))} |
| 29 | </div> |
| 30 | {rows.map((row: any, rowIdx: number) => ( |
| 31 | <div key={rowIdx} role="row"> |
| 32 | {columns.map((col: any, colIdx: number) => ( |
| 33 | <div key={colIdx} role="cell"> |
| 34 | {col.renderCell?.({ row, rowIdx, isCellSelected: false })} |
| 35 | </div> |
| 36 | ))} |
| 37 | </div> |
| 38 | ))} |
| 39 | </div> |
| 40 | ), |
| 41 | })) |
| 42 | |
| 43 | function generateRows(count: number) { |
| 44 | return Array.from({ length: count }, (_, i) => ({ |
| 45 | id: i, |
| 46 | name: `row-${i}`, |
| 47 | })) |
| 48 | } |
| 49 | |
| 50 | test('renders a single context menu regardless of row count', () => { |
| 51 | contextMenuMountCount = 0 |
| 52 | const rows = generateRows(100) |
| 53 | render(<Results rows={rows} />) |
| 54 | |
| 55 | expect(contextMenuMountCount).toBe(1) |
| 56 | }) |
| 57 | |
| 58 | test('shows empty state when no rows provided', () => { |
| 59 | render(<Results rows={[]} />) |
| 60 | expect(screen.getByText('Success. No rows returned')).toBeTruthy() |
| 61 | }) |