import React from 'react'; import { describe, expect, it, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; const navigateMock = vi.fn(); const authState = { user: { role: 'tenant_admin' }, }; vi.mock('react-router-dom', () => ({ useNavigate: () => navigateMock, })); vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string, fallback?: string | Record) => { if (typeof fallback === 'string') { return fallback; } if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') { return fallback.defaultValue; } return key; }, }), })); vi.mock('../../api', () => ({ getEvents: vi.fn().mockResolvedValue([ { id: 1, name: 'Demo Event', slug: 'demo-event', event_date: '2026-02-19', settings: {}, }, ]), })); vi.mock('../../auth/tokens', () => ({ isAuthError: () => false, })); vi.mock('../../auth/context', () => ({ useAuth: () => authState, })); vi.mock('../../lib/apiError', () => ({ getApiErrorMessage: () => 'error', })); vi.mock('../../lib/eventFilters', () => ({ buildEventStatusCounts: () => ({ all: 1, upcoming: 1, draft: 0, past: 0 }), filterEventsByStatus: (events: any[]) => events, resolveEventStatusKey: () => 'upcoming', })); vi.mock('../../lib/eventListStats', () => ({ buildEventListStats: () => ({ photos: 2, guests: 3, tasks: 4 }), })); vi.mock('../hooks/useBackNavigation', () => ({ useBackNavigation: () => undefined, })); vi.mock('../components/MobileShell', () => ({ MobileShell: ({ children }: { children: React.ReactNode }) =>
{children}
, HeaderActionButton: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('../components/Primitives', () => ({ PillBadge: ({ children }: { children: React.ReactNode }) =>
{children}
, CTAButton: ({ label }: { label: string }) => , FloatingActionButton: ({ label }: { label: string }) =>
{label}
, SkeletonCard: () =>
Loading...
, })); vi.mock('../components/FormControls', () => ({ MobileInput: (props: React.InputHTMLAttributes) => , })); vi.mock('@tamagui/card', () => ({ Card: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('@tamagui/scroll-view', () => ({ ScrollView: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('@tamagui/react-native-web-lite', () => ({ Pressable: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => ( ), })); vi.mock('@tamagui/toggle-group', () => ({ ToggleGroup: Object.assign(({ children }: { children: React.ReactNode }) =>
{children}
, { Item: ({ children }: { children: React.ReactNode }) =>
{children}
, }), })); vi.mock('@tamagui/separator', () => ({ Separator: () =>
, })); vi.mock('@tamagui/stacks', () => ({ YStack: ({ children }: { children: React.ReactNode }) =>
{children}
, XStack: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('@tamagui/text', () => ({ SizableText: ({ children }: { children: React.ReactNode }) => {children}, })); vi.mock('../theme', () => ({ useAdminTheme: () => ({ text: '#111827', muted: '#6b7280', subtle: '#94a3b8', border: '#e5e7eb', primary: '#ff5a5f', danger: '#dc2626', surface: '#ffffff', surfaceMuted: '#f9fafb', accentSoft: '#eef2ff', accent: '#6366f1', shadow: 'rgba(15,23,42,0.12)', }), })); import MobileEventsPage from '../EventsPage'; describe('MobileEventsPage', () => { it('renders filters and event list', async () => { render(); expect(await screen.findByText('Filters & Search')).toBeInTheDocument(); expect(screen.getByText('Status')).toBeInTheDocument(); expect(screen.getByText('Demo Event')).toBeInTheDocument(); }); it('hides create actions for members', async () => { authState.user = { role: 'member' }; render(); expect(await screen.findByText('Demo Event')).toBeInTheDocument(); expect(screen.queryByText('Create New Event')).not.toBeInTheDocument(); authState.user = { role: 'tenant_admin' }; }); });