105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import React from 'react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
import { EventDataProvider } from '../context/EventDataContext';
|
|
|
|
vi.mock('react-router-dom', () => ({
|
|
useNavigate: () => vi.fn(),
|
|
}));
|
|
|
|
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('@tamagui/button', () => ({
|
|
Button: ({ children, ...rest }: { children: React.ReactNode }) => (
|
|
<button type="button" {...rest}>
|
|
{children}
|
|
</button>
|
|
),
|
|
}));
|
|
|
|
vi.mock('lucide-react', () => ({
|
|
Camera: () => <span>camera</span>,
|
|
Sparkles: () => <span>sparkles</span>,
|
|
Image: () => <span>image</span>,
|
|
Star: () => <span>star</span>,
|
|
Trophy: () => <span>trophy</span>,
|
|
}));
|
|
|
|
vi.mock('../components/AppShell', () => ({
|
|
default: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}));
|
|
|
|
vi.mock('../services/uploadApi', () => ({
|
|
useUploadQueue: () => ({ items: [], loading: false, refresh: vi.fn() }),
|
|
}));
|
|
|
|
vi.mock('../services/tasksApi', () => ({
|
|
fetchTasks: vi.fn().mockResolvedValue([
|
|
{
|
|
id: 12,
|
|
title: 'Capture the dancefloor',
|
|
description: 'Find the happiest crew.',
|
|
instructions: 'Look for the brightest smiles.',
|
|
duration: 5,
|
|
emotion: { slug: 'freude', name: 'Joy' },
|
|
},
|
|
]),
|
|
}));
|
|
|
|
vi.mock('../services/emotionsApi', () => ({
|
|
fetchEmotions: vi.fn().mockResolvedValue([{ slug: 'freude', name: 'Joy' }]),
|
|
}));
|
|
|
|
vi.mock('../services/photosApi', () => ({
|
|
fetchGallery: vi.fn().mockResolvedValue({ data: [] }),
|
|
}));
|
|
|
|
vi.mock('@/guest/i18n/useTranslation', () => ({
|
|
useTranslation: () => ({ t: (key: string, fallback?: string) => fallback ?? key, locale: 'de' }),
|
|
}));
|
|
|
|
vi.mock('@/guest/i18n/LocaleContext', () => ({
|
|
useLocale: () => ({ locale: 'de' }),
|
|
}));
|
|
|
|
vi.mock('@/hooks/use-appearance', () => ({
|
|
useAppearance: () => ({ resolved: 'light' }),
|
|
}));
|
|
|
|
vi.mock('@/guest/hooks/useGuestTaskProgress', () => ({
|
|
useGuestTaskProgress: () => ({ isCompleted: () => false }),
|
|
}));
|
|
|
|
import HomeScreen from '../screens/HomeScreen';
|
|
|
|
describe('HomeScreen', () => {
|
|
it('shows task hero content when tasks are enabled', async () => {
|
|
render(
|
|
<EventDataProvider tasksEnabledFallback>
|
|
<HomeScreen />
|
|
</EventDataProvider>
|
|
);
|
|
|
|
expect(await screen.findByText('Capture the dancefloor')).toBeInTheDocument();
|
|
expect(screen.getByText("Let's go!")).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows capture-ready content when tasks are disabled', () => {
|
|
render(
|
|
<EventDataProvider tasksEnabledFallback={false}>
|
|
<HomeScreen />
|
|
</EventDataProvider>
|
|
);
|
|
|
|
expect(screen.getByText('Capture ready')).toBeInTheDocument();
|
|
expect(screen.getByText('Upload / Take photo')).toBeInTheDocument();
|
|
});
|
|
});
|