135 lines
3.6 KiB
TypeScript
135 lines
3.6 KiB
TypeScript
import React from 'react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
const logoutMock = vi.fn();
|
|
const navigateMock = vi.fn();
|
|
|
|
vi.mock('react-router-dom', () => ({
|
|
useNavigate: () => navigateMock,
|
|
}));
|
|
|
|
vi.mock('react-i18next', () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string, fallback?: string | Record<string, unknown>) => {
|
|
if (typeof fallback === 'string') {
|
|
return fallback;
|
|
}
|
|
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
|
return fallback.defaultValue;
|
|
}
|
|
return key;
|
|
},
|
|
}),
|
|
}));
|
|
|
|
vi.mock('../../i18n', () => ({
|
|
default: {
|
|
language: 'de',
|
|
changeLanguage: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock('../../auth/context', () => ({
|
|
useAuth: () => ({
|
|
user: { name: 'Demo User', email: 'demo@example.com', role: 'tenant_admin' },
|
|
logout: logoutMock,
|
|
}),
|
|
}));
|
|
|
|
vi.mock('../../api', () => ({
|
|
fetchTenantProfile: vi.fn().mockResolvedValue({
|
|
name: 'Demo User',
|
|
email: 'demo@example.com',
|
|
role: 'tenant_admin',
|
|
}),
|
|
}));
|
|
|
|
vi.mock('@/hooks/use-appearance', () => ({
|
|
useAppearance: () => ({
|
|
appearance: 'system',
|
|
updateAppearance: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock('../hooks/useBackNavigation', () => ({
|
|
useBackNavigation: () => undefined,
|
|
}));
|
|
|
|
vi.mock('@tamagui/avatar', () => ({
|
|
Avatar: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
|
|
Fallback: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}),
|
|
}));
|
|
|
|
vi.mock('@tamagui/card', () => ({
|
|
Card: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}));
|
|
|
|
vi.mock('@tamagui/group', () => ({
|
|
YGroup: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
|
|
Item: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}),
|
|
}));
|
|
|
|
vi.mock('@tamagui/list-item', () => ({
|
|
ListItem: ({ title, iconAfter }: { title?: React.ReactNode; iconAfter?: React.ReactNode }) => (
|
|
<div>
|
|
{title}
|
|
{iconAfter}
|
|
</div>
|
|
),
|
|
}));
|
|
|
|
vi.mock('@tamagui/stacks', () => ({
|
|
YStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
XStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}));
|
|
|
|
vi.mock('@tamagui/text', () => ({
|
|
SizableText: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
|
|
}));
|
|
|
|
vi.mock('../components/MobileShell', () => ({
|
|
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}));
|
|
|
|
vi.mock('../components/Primitives', () => ({
|
|
CTAButton: ({ label }: { label: string }) => <button type="button">{label}</button>,
|
|
}));
|
|
|
|
vi.mock('../components/FormControls', () => ({
|
|
MobileSelect: ({ children }: { children: React.ReactNode }) => <select>{children}</select>,
|
|
}));
|
|
|
|
vi.mock('../components/colors', () => ({
|
|
withAlpha: (color: string) => color,
|
|
}));
|
|
|
|
vi.mock('../theme', () => ({
|
|
useAdminTheme: () => ({
|
|
textStrong: '#111827',
|
|
muted: '#6b7280',
|
|
border: '#e5e7eb',
|
|
accentSoft: '#eef2ff',
|
|
primary: '#ff5a5f',
|
|
subtle: '#94a3b8',
|
|
surface: '#ffffff',
|
|
surfaceMuted: '#f9fafb',
|
|
shadow: 'rgba(15,23,42,0.12)',
|
|
danger: '#dc2626',
|
|
}),
|
|
}));
|
|
|
|
import MobileProfilePage from '../ProfilePage';
|
|
|
|
describe('MobileProfilePage', () => {
|
|
it('renders settings and preferences sections', async () => {
|
|
render(<MobileProfilePage />);
|
|
|
|
expect(await screen.findByText('Settings')).toBeInTheDocument();
|
|
expect(screen.getByText('Preferences')).toBeInTheDocument();
|
|
expect(screen.getByText('Log out')).toBeInTheDocument();
|
|
});
|
|
});
|