|
| 1 | +import { renderToStaticMarkup } from 'react-dom/server'; |
| 2 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 3 | + |
| 4 | +import { ListPage } from './list-page.js'; |
| 5 | + |
| 6 | +// Capture the props ListPage forwards to PaginatedListDataTable. |
| 7 | +const captured: { props?: Record<string, any> } = {}; |
| 8 | + |
| 9 | +vi.mock('@/vdb/components/shared/paginated-list-data-table.js', () => ({ |
| 10 | + PaginatedListDataTable: (props: Record<string, any>) => { |
| 11 | + captured.props = props; |
| 12 | + return null; |
| 13 | + }, |
| 14 | +})); |
| 15 | + |
| 16 | +vi.mock('../layout-engine/page-layout.js', () => ({ |
| 17 | + Page: ({ children }: any) => <>{children}</>, |
| 18 | + PageTitle: ({ children }: any) => <>{children}</>, |
| 19 | + PageActionBar: ({ children }: any) => <>{children}</>, |
| 20 | + PageLayout: ({ children }: any) => <>{children}</>, |
| 21 | + FullWidthPageBlock: ({ children }: any) => <>{children}</>, |
| 22 | +})); |
| 23 | + |
| 24 | +vi.mock('@/vdb/hooks/use-user-settings.js', () => ({ |
| 25 | + useUserSettings: () => ({ setTableSettings: vi.fn(), settings: {} }), |
| 26 | +})); |
| 27 | + |
| 28 | +vi.mock('@tanstack/react-router', () => ({ |
| 29 | + useNavigate: () => vi.fn(), |
| 30 | +})); |
| 31 | + |
| 32 | +describe('ListPage prop forwarding', () => { |
| 33 | + const baseProps = { |
| 34 | + route: { useSearch: () => ({}), fullPath: '/' } as any, |
| 35 | + title: 'Test', |
| 36 | + listQuery: {} as any, |
| 37 | + }; |
| 38 | + |
| 39 | + beforeEach(() => { |
| 40 | + captured.props = undefined; |
| 41 | + }); |
| 42 | + |
| 43 | + it('forwards transformQueryKey, disableViewOptions and includeSelectionColumn to PaginatedListDataTable', () => { |
| 44 | + const transformQueryKey = (queryKey: any[]) => [...queryKey, 'extra']; |
| 45 | + |
| 46 | + renderToStaticMarkup( |
| 47 | + <ListPage |
| 48 | + {...baseProps} |
| 49 | + transformQueryKey={transformQueryKey} |
| 50 | + disableViewOptions={true} |
| 51 | + // false is the non-default value, so this asserts the value is really forwarded |
| 52 | + // rather than coinciding with PaginatedListDataTable's own default of true. |
| 53 | + includeSelectionColumn={false} |
| 54 | + />, |
| 55 | + ); |
| 56 | + |
| 57 | + expect(captured.props).toBeDefined(); |
| 58 | + expect(captured.props?.transformQueryKey).toBe(transformQueryKey); |
| 59 | + expect(captured.props?.disableViewOptions).toBe(true); |
| 60 | + expect(captured.props?.includeSelectionColumn).toBe(false); |
| 61 | + }); |
| 62 | +}); |
0 commit comments