Files
supabase/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCostEstimate.test.tsx
Joshen Lim 60b51d74d5 Audit existing unit tests + Remove redundant ones (#52215)
## Context

_TLDR: Changes here speeds up unit tests on CI from ~14 minutes to ~3
minutes_ 😂
_TLDR 2: The file changes are solely only test files +
`studio-unit-tests.yml`_

We've currently got a lot of unit tests in the repository which while
great for coverage, hasn't been ideally written. There's a lot of
redundancy + overly specific tests that break easily, and our current
unit test takes about 15 minutes to run in the GHA per PR. Hence am
doing a audit clean up of all existing unit tests in the studio repo.

## Changes involved
- `.test.ts` files now run in `node`, `.test.tsx` in `jsdom`
- jsdom costs about 1s of setup per file. A `.ts` test that needs the
DOM opts in with `// @vitest-environment jsdom` (46 files do).
- Removed redundant and over-specific tests
- Duplicates are merged into `test.each`. Tests that only covered
libraries, existed for coverage, or asserted class names and snapshots
are deleted. 19 files are merged into a sibling or deleted.
- Fixed about 15 tests that couldn't fail 
- Examples: unawaited assertions, fixtures equal to the default, and a
`semverGte` test calling `semverLte`.
- Sped up the slowest files 
- Real sleeps are replaced with fake timers, `user.type` with paste, and
Radix option queries are scoped to the open listbox. For example,
`RestoringState` went from 18s to 0.3s and
`useTableEditorFiltersSort.navigation` from 20s to 3s.
- These ^ already shave down the unit tests time from 14 mins to 9 mins,
but am also sharding unit tests across 4 jobs to increase speed up
further which then shaves down time to 3 mins now
2026-10-23 18:51:27 +08:00

100 lines
3.2 KiB
TypeScript

import { screen } from '@testing-library/react'
import { describe, expect, test } from 'vitest'
import { PipelineCostEstimate } from './PipelineCostEstimate'
import type { ReplicationCostEstimateData } from '@/data/replication/cost-estimate-query'
import { customRender } from '@/tests/lib/custom-render'
const estimate = {
currency: 'usd',
pipeline: { hourly_cost: 0.05, monthly_cost: 36.5 },
streaming: { rate_per_gb: 3 },
table_copy: {
rate_per_gb: 0.6,
total_bytes: 10_000_000_000,
total_cost: 10,
tables: [
{
schema: 'public',
name: 'orders',
estimated_bytes: 600_000_000,
estimated_cost: 0.6,
is_row_filtered: false,
},
{
schema: 'billing',
name: 'invoices',
estimated_bytes: 9_400_000_000,
estimated_cost: 9.4,
is_row_filtered: false,
},
],
},
} satisfies ReplicationCostEstimateData
const publicationTables = [
{ id: 101, schema: 'public', name: 'orders' },
{ id: 202, schema: 'billing', name: 'invoices' },
]
describe('PipelineCostEstimate', () => {
test('shows the selected initial sync tables and ongoing rates inline', () => {
customRender(
<PipelineCostEstimate
estimate={estimate}
publicationTables={publicationTables}
tableSyncCopy={{ type: 'include_tables', table_ids: [101] }}
/>
)
expect(screen.getByRole('heading', { name: 'Estimated costs' })).toBeInTheDocument()
expect(screen.getByText('public.orders')).toBeInTheDocument()
expect(screen.queryByText('billing.invoices')).not.toBeInTheDocument()
expect(screen.getByText('$0.05/hour')).toBeInTheDocument()
expect(screen.getByText('$3.00/GB')).toBeInTheDocument()
})
test('keeps pipeline creation available when the estimate is unavailable', () => {
customRender(<PipelineCostEstimate publicationTables={publicationTables} />)
expect(
screen.getByText('A cost estimate is unavailable. You can still start the pipeline.')
).toBeInTheDocument()
})
})
test('shows zero initial-sync cost when all existing rows are skipped', () => {
customRender(
<PipelineCostEstimate
estimate={estimate}
publicationTables={publicationTables}
tableSyncCopy={{ type: 'skip_all_tables' }}
/>
)
expect(screen.getByText('No tables will run an initial sync')).toBeInTheDocument()
expect(screen.getByText('$0.05/hour')).toBeInTheDocument()
})
test('does not show stale rates while an estimate is loading', () => {
customRender(
<PipelineCostEstimate estimate={estimate} isLoading publicationTables={publicationTables} />
)
expect(screen.queryByText('$0.05/hour')).not.toBeInTheDocument()
})
test('keeps the status region mounted when loading finishes without an estimate', () => {
const { rerender } = customRender(
<PipelineCostEstimate isLoading publicationTables={publicationTables} />
)
const status = screen.getByRole('status')
expect(status).toBeEmptyDOMElement()
rerender(<PipelineCostEstimate publicationTables={publicationTables} />)
expect(screen.getByRole('status')).toBe(status)
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
expect(status).toHaveTextContent(
'A cost estimate is unavailable. You can still start the pipeline.'
)
})