SettingsMenu.selfhosted.test.tsx60 lines · main
| 1 | import { renderHook } from '@testing-library/react' |
| 2 | import { describe, expect, it, vi } from 'vitest' |
| 3 | |
| 4 | import { useGenerateSettingsMenu } from './SettingsMenu.utils' |
| 5 | |
| 6 | vi.mock('@/lib/constants', async () => { |
| 7 | const actual = await vi.importActual<Record<string, unknown>>('@/lib/constants') |
| 8 | return { |
| 9 | ...actual, |
| 10 | IS_PLATFORM: false, |
| 11 | } |
| 12 | }) |
| 13 | |
| 14 | vi.mock('common', () => ({ |
| 15 | useFlag: vi.fn().mockReturnValue(false), |
| 16 | useParams: vi.fn().mockReturnValue({ ref: 'project-ref' }), |
| 17 | })) |
| 18 | |
| 19 | vi.mock('@/hooks/misc/useSelectedOrganization', () => ({ |
| 20 | useSelectedOrganizationQuery: vi.fn().mockReturnValue({ data: { slug: 'my-org' } }), |
| 21 | })) |
| 22 | |
| 23 | vi.mock('@/hooks/misc/useSelectedProject', () => ({ |
| 24 | useSelectedProjectQuery: vi.fn().mockReturnValue({ data: { status: 'ACTIVE_HEALTHY' } }), |
| 25 | })) |
| 26 | |
| 27 | vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({ |
| 28 | useIsFeatureEnabled: vi |
| 29 | .fn() |
| 30 | .mockReturnValue({ projectSettingsLegacyJwtKeys: false, billingAll: true }), |
| 31 | })) |
| 32 | |
| 33 | vi.mock('@/components/interfaces/App/FeaturePreview/FeaturePreviewContext', () => ({ |
| 34 | useIsPlatformWebhooksEnabled: vi.fn().mockReturnValue(false), |
| 35 | })) |
| 36 | |
| 37 | describe('useGenerateSettingsMenu (self-hosted)', () => { |
| 38 | it('includes Log Drains in self-hosted mode', () => { |
| 39 | const { result } = renderHook(() => useGenerateSettingsMenu()) |
| 40 | const configGroup = result.current.find((group) => group.title === 'Configuration') |
| 41 | |
| 42 | expect(configGroup?.items.some((item) => item.key === 'log-drains')).toBe(true) |
| 43 | }) |
| 44 | |
| 45 | it('does not include dashboard settings in self-hosted mode', () => { |
| 46 | const { result } = renderHook(() => useGenerateSettingsMenu()) |
| 47 | const configGroup = result.current.find((group) => group.title === 'Configuration') |
| 48 | |
| 49 | expect(configGroup?.items.some((item) => item.key === 'dashboard')).toBe(false) |
| 50 | }) |
| 51 | |
| 52 | it('does not include platform-only settings in self-hosted mode', () => { |
| 53 | const { result } = renderHook(() => useGenerateSettingsMenu()) |
| 54 | const configGroup = result.current.find((group) => group.title === 'Configuration') |
| 55 | |
| 56 | expect(configGroup?.items.some((item) => item.key === 'general')).toBe(false) |
| 57 | expect(configGroup?.items.some((item) => item.key === 'api-keys')).toBe(false) |
| 58 | expect(configGroup?.items.some((item) => item.key === 'infrastructure')).toBe(false) |
| 59 | }) |
| 60 | }) |