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