ReadReplicaEligibilityWarnings.test.tsx87 lines · main
1import { screen } from '@testing-library/react'
2import { describe, expect, it, vi } from 'vitest'
3
4import { ReadReplicaEligibilityWarnings } from '@/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings'
5import { useCheckEligibilityDeployReplica } from '@/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/useCheckEligibilityDeployReplica'
6import { READ_REPLICAS_MAX_COUNT } from '@/data/read-replicas/replicas-query'
7import { customRender } from '@/tests/lib/custom-render'
8
9vi.mock(
10 '@/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/useCheckEligibilityDeployReplica'
11)
12vi.mock('@/data/projects/project-detail-query', () => ({
13 useProjectDetailQuery: () => ({ data: undefined, isSuccess: false }),
14}))
15vi.mock('@/data/database/enable-physical-backups-mutation', () => ({
16 useEnablePhysicalBackupsMutation: () => ({ mutate: vi.fn(), isPending: false }),
17}))
18vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
19 useSelectedOrganizationQuery: () => ({ data: { slug: 'test-org' } }),
20}))
21vi.mock('@/hooks/misc/useSelectedProject', () => ({
22 useSelectedProjectQuery: () => ({ data: { dbVersion: 'briven-postgres-15.1.0' } }),
23}))
24
25const eligibility = (delta: Record<string, unknown>) => ({
26 can: false,
27 hasOverdueInvoices: false,
28 isAWSProvider: true,
29 isAwsK8s: false,
30 isPgVersionBelow15: false,
31 isBelowSmallCompute: false,
32 isWalgNotEnabled: false,
33 isProWithSpendCapEnabled: false,
34 isReachedMaxReplicas: false,
35 maxNumberOfReplicas: READ_REPLICAS_MAX_COUNT,
36 ...delta,
37})
38
39describe('ReadReplicaEligibilityWarnings – below small compute', () => {
40 it('shows upgrade CTA when project is on pico, nano, or micro compute', () => {
41 vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(
42 eligibility({ isBelowSmallCompute: true })
43 )
44
45 customRender(<ReadReplicaEligibilityWarnings />)
46
47 expect(
48 screen.getByText('Project required to at least be on a Small compute')
49 ).toBeInTheDocument()
50 expect(
51 screen.getByText(
52 "This is to ensure that read replicas can keep up with the primary databases' activities."
53 )
54 ).toBeInTheDocument()
55 })
56})
57
58describe('ReadReplicaEligibilityWarnings – max replicas reached', () => {
59 it('shows upsell to upgrade compute when below the default cap (e.g. ci_small/medium/large → 4 replicas)', () => {
60 vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(
61 eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: 4 })
62 )
63
64 customRender(<ReadReplicaEligibilityWarnings />)
65
66 expect(
67 screen.getByText('You can only deploy up to 4 read replicas at once')
68 ).toBeInTheDocument()
69 expect(screen.getByText(/you may deploy up to/i)).toBeInTheDocument()
70 expect(screen.getByRole('link', { name: /change compute size/i })).toBeInTheDocument()
71 })
72
73 it('does NOT show the compute upsell when already at the default cap (XL+)', () => {
74 vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(
75 eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: READ_REPLICAS_MAX_COUNT })
76 )
77
78 customRender(<ReadReplicaEligibilityWarnings />)
79
80 expect(
81 screen.getByText(`You can only deploy up to ${READ_REPLICAS_MAX_COUNT} read replicas at once`)
82 ).toBeInTheDocument()
83 expect(screen.queryByText(/you may deploy up to/i)).not.toBeInTheDocument()
84 expect(screen.queryByText(/XL compute or higher/i)).not.toBeInTheDocument()
85 expect(screen.queryByRole('link', { name: /change compute size/i })).not.toBeInTheDocument()
86 })
87})