me.test.tsx133 lines · main
1import { render, screen } from '@testing-library/react'
2import type { ReactNode } from 'react'
3import { beforeEach, describe, expect, it, vi } from 'vitest'
4
5import PreferencesPage from '@/pages/account/me'
6
7const { mockIsPlatform, mockUseIsFeatureEnabled, mockUseProfile } = vi.hoisted(() => ({
8 mockIsPlatform: { value: true },
9 mockUseIsFeatureEnabled: vi.fn(),
10 mockUseProfile: vi.fn(),
11}))
12
13vi.mock('@/lib/constants', async () => {
14 const actual = await vi.importActual<Record<string, unknown>>('@/lib/constants')
15 return {
16 ...actual,
17 get IS_PLATFORM() {
18 return mockIsPlatform.value
19 },
20 }
21})
22
23vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
24 useIsFeatureEnabled: mockUseIsFeatureEnabled,
25}))
26
27vi.mock('@/lib/profile', () => ({
28 useProfile: mockUseProfile,
29}))
30
31vi.mock('@/components/layouts/AccountLayout/AccountLayout', () => ({
32 __esModule: true,
33 default: ({ children }: { children: ReactNode }) => <div>{children}</div>,
34}))
35
36vi.mock('@/components/layouts/AppLayout/AppLayout', () => ({
37 AppLayout: ({ children }: { children: ReactNode }) => <div>{children}</div>,
38}))
39
40vi.mock('@/components/layouts/DefaultLayout', () => ({
41 DefaultLayout: ({ children }: { children: ReactNode }) => <div>{children}</div>,
42}))
43
44vi.mock('@/components/interfaces/Account/Preferences/ProfileInformation', () => ({
45 ProfileInformation: () => <div>ProfileInformation</div>,
46}))
47
48vi.mock('@/components/interfaces/Account/Preferences/AccountIdentities', () => ({
49 AccountIdentities: () => <div>AccountIdentities</div>,
50}))
51
52vi.mock('@/components/interfaces/Account/Preferences/AccountConnections', () => ({
53 AccountConnections: () => <div>AccountConnections</div>,
54}))
55
56vi.mock('@/components/interfaces/Account/Preferences/ThemeSettings', () => ({
57 ThemeSettings: () => <div>ThemeSettings</div>,
58}))
59
60vi.mock('@/components/interfaces/Account/Preferences/TimezoneSettings', () => ({
61 TimezoneSettings: () => <div>TimezoneSettings</div>,
62}))
63
64vi.mock('@/components/interfaces/Account/Preferences/HotkeySettings', () => ({
65 HotkeySettings: () => <div>HotkeySettings</div>,
66}))
67
68vi.mock('@/components/interfaces/Account/Preferences/DashboardSettings', () => ({
69 DashboardSettings: () => <div>DashboardSettings</div>,
70}))
71
72vi.mock('@/components/interfaces/Account/Preferences/AnalyticsSettings', () => ({
73 AnalyticsSettings: () => <div>AnalyticsSettings</div>,
74}))
75
76vi.mock('@/components/interfaces/Account/Preferences/AccountDeletion', () => ({
77 AccountDeletion: () => <div>AccountDeletion</div>,
78}))
79
80vi.mock('@/components/ui/AlertError', () => ({
81 AlertError: () => <div>AlertError</div>,
82}))
83
84describe('/account/me', () => {
85 beforeEach(() => {
86 mockUseIsFeatureEnabled.mockClear()
87 mockUseProfile.mockClear()
88 mockUseIsFeatureEnabled.mockReturnValue({
89 profileShowInformation: true,
90 profileShowAnalyticsAndMarketing: true,
91 profileShowAccountDeletion: true,
92 })
93 mockUseProfile.mockReturnValue({
94 error: null,
95 isLoading: false,
96 isError: false,
97 isSuccess: true,
98 })
99 })
100
101 it('renders hosted account sections on platform', () => {
102 mockIsPlatform.value = true
103
104 render(<PreferencesPage dehydratedState={{}} />)
105
106 expect(screen.getByText('ProfileInformation')).toBeInTheDocument()
107 expect(screen.getByText('AccountIdentities')).toBeInTheDocument()
108 expect(screen.getByText('AccountConnections')).toBeInTheDocument()
109 expect(screen.getByText('ThemeSettings')).toBeInTheDocument()
110 expect(screen.getByText('TimezoneSettings')).toBeInTheDocument()
111 expect(screen.getByText('HotkeySettings')).toBeInTheDocument()
112 expect(screen.getByText('DashboardSettings')).toBeInTheDocument()
113 expect(screen.getByText('AnalyticsSettings')).toBeInTheDocument()
114 expect(screen.getByText('AccountDeletion')).toBeInTheDocument()
115 })
116
117 it('renders only local preferences on self-hosted', () => {
118 mockIsPlatform.value = false
119
120 render(<PreferencesPage dehydratedState={{}} />)
121
122 expect(screen.getByText('ThemeSettings')).toBeInTheDocument()
123 expect(screen.getByText('TimezoneSettings')).toBeInTheDocument()
124 expect(screen.getByText('HotkeySettings')).toBeInTheDocument()
125 expect(screen.getByText('DashboardSettings')).toBeInTheDocument()
126 expect(screen.queryByText('ProfileInformation')).not.toBeInTheDocument()
127 expect(screen.queryByText('AccountIdentities')).not.toBeInTheDocument()
128 expect(screen.queryByText('AccountConnections')).not.toBeInTheDocument()
129 expect(screen.queryByText('AnalyticsSettings')).not.toBeInTheDocument()
130 expect(screen.queryByText('AccountDeletion')).not.toBeInTheDocument()
131 expect(mockUseProfile).not.toHaveBeenCalled()
132 })
133})