OrganizationDropdown.test.tsx75 lines · main
| 1 | import { screen, within } from '@testing-library/react' |
| 2 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 3 | |
| 4 | import { OrganizationDropdown } from './OrganizationDropdown' |
| 5 | import { MANAGED_BY } from '@/lib/constants/infrastructure' |
| 6 | import { createMockOrganization, render } from '@/tests/helpers' |
| 7 | |
| 8 | const { mockUseIsFeatureEnabled, mockUseOrganizationsQuery, mockUseSelectedOrganizationQuery } = |
| 9 | vi.hoisted(() => ({ |
| 10 | mockUseIsFeatureEnabled: vi.fn(), |
| 11 | mockUseOrganizationsQuery: vi.fn(), |
| 12 | mockUseSelectedOrganizationQuery: vi.fn(), |
| 13 | })) |
| 14 | |
| 15 | vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({ |
| 16 | useIsFeatureEnabled: mockUseIsFeatureEnabled, |
| 17 | })) |
| 18 | |
| 19 | vi.mock('@/data/organizations/organizations-query', () => ({ |
| 20 | useOrganizationsQuery: mockUseOrganizationsQuery, |
| 21 | })) |
| 22 | |
| 23 | vi.mock('@/hooks/misc/useSelectedOrganization', () => ({ |
| 24 | useSelectedOrganizationQuery: mockUseSelectedOrganizationQuery, |
| 25 | })) |
| 26 | |
| 27 | vi.mock('@/components/ui/PartnerIcon', () => ({ |
| 28 | default: ({ organization }: { organization: { managed_by: string } }) => |
| 29 | organization.managed_by === MANAGED_BY.BRIVEN ? null : <div data-testid="partner-icon" />, |
| 30 | })) |
| 31 | |
| 32 | describe('OrganizationDropdown', () => { |
| 33 | beforeEach(() => { |
| 34 | vi.clearAllMocks() |
| 35 | mockUseIsFeatureEnabled.mockReturnValue(false) |
| 36 | mockUseOrganizationsQuery.mockReturnValue({ |
| 37 | data: [ |
| 38 | createMockOrganization({ slug: 'org-one', name: 'Org One' }), |
| 39 | createMockOrganization({ slug: 'org-two', name: 'Org Two' }), |
| 40 | ], |
| 41 | isPending: false, |
| 42 | isError: false, |
| 43 | }) |
| 44 | }) |
| 45 | |
| 46 | it('renders partner icon in selected organization area for managed organizations', () => { |
| 47 | mockUseSelectedOrganizationQuery.mockReturnValue({ |
| 48 | data: createMockOrganization({ |
| 49 | slug: 'org-one', |
| 50 | name: 'Org One', |
| 51 | managed_by: MANAGED_BY.AWS_MARKETPLACE, |
| 52 | }), |
| 53 | }) |
| 54 | |
| 55 | render(<OrganizationDropdown />) |
| 56 | |
| 57 | const selectedLink = screen.getByRole('link', { name: /org one/i }) |
| 58 | expect(within(selectedLink).getByTestId('partner-icon')).toBeInTheDocument() |
| 59 | }) |
| 60 | |
| 61 | it('does not render partner icon in selected organization area for Briven-managed orgs', () => { |
| 62 | mockUseSelectedOrganizationQuery.mockReturnValue({ |
| 63 | data: createMockOrganization({ |
| 64 | slug: 'org-one', |
| 65 | name: 'Org One', |
| 66 | managed_by: MANAGED_BY.BRIVEN, |
| 67 | }), |
| 68 | }) |
| 69 | |
| 70 | render(<OrganizationDropdown />) |
| 71 | |
| 72 | const selectedLink = screen.getByRole('link', { name: /org one/i }) |
| 73 | expect(within(selectedLink).queryByTestId('partner-icon')).toBeNull() |
| 74 | }) |
| 75 | }) |