import { render, screen } from '@testing-library/react' import type { ReactNode } from 'react' import { beforeEach, describe, expect, it, vi } from 'vitest' import PreferencesPage from '@/pages/account/me' const { mockIsPlatform, mockUseIsFeatureEnabled, mockUseProfile } = vi.hoisted(() => ({ mockIsPlatform: { value: true }, mockUseIsFeatureEnabled: vi.fn(), mockUseProfile: vi.fn(), })) vi.mock('@/lib/constants', async () => { const actual = await vi.importActual>('@/lib/constants') return { ...actual, get IS_PLATFORM() { return mockIsPlatform.value }, } }) vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({ useIsFeatureEnabled: mockUseIsFeatureEnabled, })) vi.mock('@/lib/profile', () => ({ useProfile: mockUseProfile, })) vi.mock('@/components/layouts/AccountLayout/AccountLayout', () => ({ __esModule: true, default: ({ children }: { children: ReactNode }) =>
{children}
, })) vi.mock('@/components/layouts/AppLayout/AppLayout', () => ({ AppLayout: ({ children }: { children: ReactNode }) =>
{children}
, })) vi.mock('@/components/layouts/DefaultLayout', () => ({ DefaultLayout: ({ children }: { children: ReactNode }) =>
{children}
, })) vi.mock('@/components/interfaces/Account/Preferences/ProfileInformation', () => ({ ProfileInformation: () =>
ProfileInformation
, })) vi.mock('@/components/interfaces/Account/Preferences/AccountIdentities', () => ({ AccountIdentities: () =>
AccountIdentities
, })) vi.mock('@/components/interfaces/Account/Preferences/AccountConnections', () => ({ AccountConnections: () =>
AccountConnections
, })) vi.mock('@/components/interfaces/Account/Preferences/ThemeSettings', () => ({ ThemeSettings: () =>
ThemeSettings
, })) vi.mock('@/components/interfaces/Account/Preferences/TimezoneSettings', () => ({ TimezoneSettings: () =>
TimezoneSettings
, })) vi.mock('@/components/interfaces/Account/Preferences/HotkeySettings', () => ({ HotkeySettings: () =>
HotkeySettings
, })) vi.mock('@/components/interfaces/Account/Preferences/DashboardSettings', () => ({ DashboardSettings: () =>
DashboardSettings
, })) vi.mock('@/components/interfaces/Account/Preferences/AnalyticsSettings', () => ({ AnalyticsSettings: () =>
AnalyticsSettings
, })) vi.mock('@/components/interfaces/Account/Preferences/AccountDeletion', () => ({ AccountDeletion: () =>
AccountDeletion
, })) vi.mock('@/components/ui/AlertError', () => ({ AlertError: () =>
AlertError
, })) describe('/account/me', () => { beforeEach(() => { mockUseIsFeatureEnabled.mockClear() mockUseProfile.mockClear() mockUseIsFeatureEnabled.mockReturnValue({ profileShowInformation: true, profileShowAnalyticsAndMarketing: true, profileShowAccountDeletion: true, }) mockUseProfile.mockReturnValue({ error: null, isLoading: false, isError: false, isSuccess: true, }) }) it('renders hosted account sections on platform', () => { mockIsPlatform.value = true render() expect(screen.getByText('ProfileInformation')).toBeInTheDocument() expect(screen.getByText('AccountIdentities')).toBeInTheDocument() expect(screen.getByText('AccountConnections')).toBeInTheDocument() expect(screen.getByText('ThemeSettings')).toBeInTheDocument() expect(screen.getByText('TimezoneSettings')).toBeInTheDocument() expect(screen.getByText('HotkeySettings')).toBeInTheDocument() expect(screen.getByText('DashboardSettings')).toBeInTheDocument() expect(screen.getByText('AnalyticsSettings')).toBeInTheDocument() expect(screen.getByText('AccountDeletion')).toBeInTheDocument() }) it('renders only local preferences on self-hosted', () => { mockIsPlatform.value = false render() expect(screen.getByText('ThemeSettings')).toBeInTheDocument() expect(screen.getByText('TimezoneSettings')).toBeInTheDocument() expect(screen.getByText('HotkeySettings')).toBeInTheDocument() expect(screen.getByText('DashboardSettings')).toBeInTheDocument() expect(screen.queryByText('ProfileInformation')).not.toBeInTheDocument() expect(screen.queryByText('AccountIdentities')).not.toBeInTheDocument() expect(screen.queryByText('AccountConnections')).not.toBeInTheDocument() expect(screen.queryByText('AnalyticsSettings')).not.toBeInTheDocument() expect(screen.queryByText('AccountDeletion')).not.toBeInTheDocument() expect(mockUseProfile).not.toHaveBeenCalled() }) })