ReadReplicaEligibilityWarnings.test.tsx 3.5 KB

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