import { fireEvent, screen } from '@testing-library/react' import { useForm } from 'react-hook-form' import { Button } from 'ui' import { describe, expect, it } from 'vitest' import type { DestinationPanelSchemaType } from '../DestinationPanel/DestinationForm/DestinationForm.schema' import type { DestinationType } from '../DestinationPanel/DestinationPanel.types' import { PipelineConnectionReview } from './PipelineConnectionReview' import { PipelineDataReview } from './PipelineDataReview' import { describeBigQueryTableLayout } from './PipelineReviewSummary.utils' import type { ReplicationPublicationData } from '@/data/replication/publication-query' import { customRender } from '@/tests/lib/custom-render' const publication: ReplicationPublicationData = { name: 'analytics', config: { type: 'all_tables', operations: ['insert'], publish_via_partition_root: false }, tables: [{ id: 101, schema: 'public', name: 'orders', kind: 'table', partition_parent_id: null }], } const TestReview = ({ type = 'BigQuery', values = {}, available = true, }: { type?: DestinationType values?: Partial available?: boolean }) => { const form = useForm({ defaultValues: { publicationName: 'analytics', tableSyncCopyMode: 'include_all_tables', tableSyncCopyTableIds: [], maxFillMs: 10000, maxTableSyncWorkers: 4, maxCopyConnectionsPerTable: 4, connectionPoolSize: 4, ducklakePoolSize: 4, invalidatedSlotBehavior: 'error', ...values, }, }) return ( <> ) } describe('PipelineDataReview', () => { it('shows data defaults without unchanged advanced settings and reacts to changes', () => { customRender() expect(screen.getByLabelText('Publication')).toHaveValue('analytics') expect(screen.getByLabelText('Publication tables')).toHaveValue('1 table') expect(screen.getByLabelText('Initial sync')).toHaveValue('All tables') expect(screen.queryByLabelText('Table sync workers')).not.toBeInTheDocument() expect(screen.queryByText('Custom connection settings')).not.toBeInTheDocument() fireEvent.click(screen.getByText('Change workers')) expect(screen.getByLabelText('Table sync workers')).toHaveValue('8') expect( screen.getByText('Maximum number of tables synced at the same time.') ).toBeInTheDocument() fireEvent.click(screen.getByText('Change publication')) expect(screen.getByLabelText('Publication tables')).toHaveValue('Unavailable') }) it.each(['include_tables', 'skip_tables'] as const)( 'lists selected publication tables for %s', (mode) => { customRender( ) expect( screen.getByLabelText(mode === 'include_tables' ? 'Tables to include' : 'Tables to exclude') ).toHaveValue('public.orders') } ) it('shows custom replication and BigQuery settings and only configured layouts', () => { customRender( ) expect(screen.getByLabelText('Batch wait time')).toHaveValue('500 milliseconds') expect( screen.getByText('Maximum time before sending a partially filled batch.') ).toBeInTheDocument() expect( screen.getByText( 'Maximum number of source connections used to sync existing rows for each table.' ) ).toBeInTheDocument() expect( screen.getByText( 'If the replication slot becomes invalid, the pipeline replaces destination tables and runs a new, billable initial sync.' ) ).toBeInTheDocument() expect(screen.getByLabelText('Connection pool size')).toHaveValue('6') expect(screen.getByLabelText('Maximum staleness')).toHaveValue('0 minutes') expect(screen.getByText('public.orders')).toBeInTheDocument() expect(screen.getByText('No partitioning; Cluster by id')).toBeInTheDocument() expect(screen.queryByText('Table 999')).not.toBeInTheDocument() }) it.each([ { type: 'DuckLake', values: { ducklakePoolSize: 6 }, label: 'Pool size', value: '6' }, { type: 'Snowflake', values: { snowflakeRole: 'ANALYST' }, label: 'Role', value: 'ANALYST' }, ] satisfies { type: DestinationType values: Partial label: string value: string }[])('shows custom settings for $type', ({ type, values, label, value }) => { customRender() expect(screen.getByLabelText(label)).toHaveValue(value) expect(screen.queryByLabelText('Connection pool size')).not.toBeInTheDocument() }) it('puts the table name and incomplete partition summary in the value column', () => { customRender( ) expect(screen.getByText('Table layout')).toBeInTheDocument() expect( screen.getByText( 'Partitioning and clustering applied when destination tables are first created or reset.' ) ).toBeInTheDocument() expect(screen.getByText('public.orders')).toBeInTheDocument() expect( screen.getByText('Partition by Not selected (month); Cluster by table_id') ).toBeInTheDocument() expect(screen.queryByText('Table layout: public.orders')).not.toBeInTheDocument() }) it('does not describe unavailable selections as empty or show stale layouts', () => { const view = customRender( ) expect(screen.getByLabelText('Publication tables')).toHaveValue('Unavailable') expect(screen.getByLabelText('Tables to include')).toHaveValue('Unavailable') expect(screen.queryByText('Table 999')).not.toBeInTheDocument() view.unmount() customRender() expect(screen.queryByText('Table layout')).not.toBeInTheDocument() }) it('describes each partition mode', () => { expect( describeBigQueryTableLayout({ tableId: 1, partitionBy: { kind: 'ingestion_time', granularity: 'day' }, }) ).toBe('Partition by ingestion time (day); No clustering') expect( describeBigQueryTableLayout({ tableId: 1, partitionBy: { kind: 'time_column', column: 'created_at', granularity: 'day' }, }) ).toBe('Partition by created_at (day); No clustering') expect( describeBigQueryTableLayout({ tableId: 1, partitionBy: { kind: 'integer_range', column: 'id', start: 0, end: 100, interval: 10 }, }) ).toBe('Partition by id (range 0 to 100, interval 10); No clustering') }) })