ProjectIntegrationBadges.test.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { screen } from '@testing-library/react'
  2. import type React from 'react'
  3. import { describe, expect, it, vi } from 'vitest'
  4. import { ProjectCard } from './ProjectCard'
  5. import { ProjectTableRow } from './ProjectTableRow'
  6. import type { OrgProject } from '@/data/projects/org-projects-infinite-query'
  7. import { MANAGED_BY } from '@/lib/constants/infrastructure'
  8. import { render } from '@/tests/helpers'
  9. vi.mock('next/router', () => ({
  10. useRouter: () => ({
  11. push: vi.fn(),
  12. }),
  13. }))
  14. vi.mock('react-inlinesvg', () => ({
  15. default: () => <div data-testid="inline-svg" />,
  16. }))
  17. vi.mock('./ProjectCardStatus', () => ({
  18. ProjectCardStatus: () => <div data-testid="project-status" />,
  19. }))
  20. vi.mock('@/components/ui/CardButton', () => ({
  21. default: ({ title, footer }: { title: React.ReactNode; footer: React.ReactNode }) => (
  22. <div>
  23. <div>{title}</div>
  24. <div>{footer}</div>
  25. </div>
  26. ),
  27. }))
  28. vi.mock('@/components/ui/ComputeBadgeWrapper', () => ({
  29. ComputeBadgeWrapper: () => <div data-testid="compute-badge" />,
  30. }))
  31. vi.mock('@/components/ui/PartnerIcon', () => ({
  32. default: ({ organization }: { organization: { managed_by: string } }) =>
  33. organization.managed_by === MANAGED_BY.BRIVEN ? null : (
  34. <div data-testid="partner-icon" data-managed-by={organization.managed_by} />
  35. ),
  36. }))
  37. vi.mock('@/data/prefetchers/project.$ref', () => ({
  38. ProjectIndexPageLink: () => null,
  39. }))
  40. vi.mock('@/hooks/custom-content/useCustomContent', () => ({
  41. useCustomContent: () => ({ infraAwsNimbusLabel: 'AWS Nimbus' }),
  42. }))
  43. vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
  44. useIsFeatureEnabled: () => ({ projectHomepageShowInstanceSize: false }),
  45. }))
  46. vi.mock('@/lib/navigation', () => ({
  47. createNavigationHandler: () => vi.fn(),
  48. }))
  49. function createOrgProject(overrides: Partial<OrgProject> = {}): OrgProject {
  50. return {
  51. ref: 'proj_1',
  52. name: 'Hammer',
  53. status: 'ACTIVE_HEALTHY',
  54. cloud_provider: 'AWS',
  55. region: 'us-east-1',
  56. inserted_at: '2026-04-09T06:36:14.718416',
  57. is_branch: false,
  58. integration_source: null,
  59. databases: [],
  60. ...overrides,
  61. } as OrgProject
  62. }
  63. describe('project integration badges', () => {
  64. it('renders a Stripe badge on project cards from project integration_source', () => {
  65. render(<ProjectCard project={createOrgProject({ integration_source: 'stripe_projects' })} />)
  66. expect(screen.getByTestId('partner-icon')).toHaveAttribute(
  67. 'data-managed-by',
  68. MANAGED_BY.STRIPE_PROJECTS
  69. )
  70. })
  71. it('does not render a Stripe badge on project cards without project integration_source', () => {
  72. render(<ProjectCard project={createOrgProject()} />)
  73. expect(screen.queryByTestId('partner-icon')).toBeNull()
  74. })
  75. it('renders a Stripe badge on project table rows without requiring Vercel or GitHub integrations', () => {
  76. render(
  77. <table>
  78. <tbody>
  79. <ProjectTableRow project={createOrgProject({ integration_source: 'stripe_projects' })} />
  80. </tbody>
  81. </table>
  82. )
  83. expect(screen.getByTestId('partner-icon')).toHaveAttribute(
  84. 'data-managed-by',
  85. MANAGED_BY.STRIPE_PROJECTS
  86. )
  87. })
  88. it('does not render a Stripe badge on project table rows without project integration_source', () => {
  89. render(
  90. <table>
  91. <tbody>
  92. <ProjectTableRow project={createOrgProject()} />
  93. </tbody>
  94. </table>
  95. )
  96. expect(screen.queryByTestId('partner-icon')).toBeNull()
  97. })
  98. })