import React from 'react'; import { describe, expect, it, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; let locationSearch = '?return_to=encoded-value'; const navigateMock = vi.fn(); vi.mock('react-router-dom', () => ({ useNavigate: () => navigateMock, useLocation: () => ({ search: locationSearch }), })); 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('@tanstack/react-query', () => ({ useMutation: () => ({ mutate: vi.fn(), isPending: false }), })); vi.mock('../../auth/context', () => ({ useAuth: () => ({ status: 'unauthenticated', applyToken: vi.fn(), abilities: [] }), })); vi.mock('../../lib/returnTo', () => ({ resolveReturnTarget: () => ({ finalTarget: '/event-admin/mobile/dashboard', encodedFinal: 'encoded-value' }), })); vi.mock('../hooks/useInstallPrompt', () => ({ useInstallPrompt: () => ({ isInstalled: false, isStandalone: false, canInstall: false, isIos: false, promptInstall: vi.fn(), }), })); vi.mock('../lib/installBanner', () => ({ getInstallBannerDismissed: () => false, setInstallBannerDismissed: vi.fn(), shouldShowInstallBanner: () => ({ shouldShow: false }), })); vi.mock('../components/MobileInstallBanner', () => ({ MobileInstallBanner: () => null, })); 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('@tamagui/button', () => ({ Button: ({ children, onPress, onClick, ...rest }: { children: React.ReactNode; onPress?: () => void; onClick?: () => void }) => ( ), })); vi.mock('../components/Primitives', () => ({ MobileCard: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('../components/FormControls', () => ({ MobileField: ({ children }: { children: React.ReactNode }) =>
{children}
, MobileInput: (props: React.InputHTMLAttributes) => , })); vi.mock('../theme', () => ({ ADMIN_GRADIENTS: { loginBackground: 'linear-gradient(0deg, #000, #111)' }, useAdminTheme: () => ({ text: '#111827', muted: '#6b7280', primary: '#ff5a5f', dangerBg: '#fee2e2', dangerText: '#991b1b', border: '#e5e7eb', surface: '#ffffff', }), })); vi.mock('lucide-react', () => ({ Loader2: () => loader, })); import MobileLoginPage from '../LoginPage'; describe('MobileLoginPage', () => { it('renders OAuth login buttons', () => { locationSearch = '?return_to=encoded-value'; render(); const googleButton = screen.getByText('Mit Google anmelden'); expect(googleButton).toBeInTheDocument(); const facebookButton = screen.getByText('Mit Facebook anmelden'); expect(facebookButton).toBeInTheDocument(); }); it('shows oauth error details when present', () => { locationSearch = '?error=google_failed&error_description=Login%20failed'; render(); expect(screen.getByText('Login aktuell nicht moeglich')).toBeInTheDocument(); expect(screen.getByText('Login failed')).toBeInTheDocument(); }); });