Files
fotospiel-app/resources/js/admin/mobile/__tests__/EventRecapPage.test.tsx
Codex Agent d2808ffa4f
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
feat(addons): finalize event addon catalog and ai styling upgrade flow
2026-02-07 12:35:07 +01:00

233 lines
6.9 KiB
TypeScript

import React from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
const fixtures = vi.hoisted(() => ({
event: {
id: 1,
name: 'Demo Event',
slug: 'demo-event',
event_date: '2026-02-19',
status: 'published',
settings: {
guest_downloads_enabled: true,
guest_sharing_enabled: false,
},
},
stats: {
total: 12,
likes: 3,
pending_photos: 1,
recent_uploads: 4,
status: 'published',
is_active: true,
},
invites: [],
addons: [
{
key: 'extend_gallery_30d',
label: 'Galerie um 30 Tage verlängern',
price_id: 'price_30d',
increments: { extra_gallery_days: 30 },
},
],
}));
vi.mock('react-router-dom', () => ({
useNavigate: () => vi.fn(),
useParams: () => ({ slug: fixtures.event.slug }),
}));
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;
},
i18n: { language: 'de' },
}),
initReactI18next: {
type: '3rdParty',
init: () => undefined,
},
}));
vi.mock('../hooks/useBackNavigation', () => ({
useBackNavigation: () => undefined,
}));
vi.mock('../../api', () => ({
getEvent: vi.fn().mockResolvedValue(fixtures.event),
getEventStats: vi.fn().mockResolvedValue(fixtures.stats),
getEventQrInvites: vi.fn().mockResolvedValue(fixtures.invites),
getAddonCatalog: vi.fn().mockResolvedValue(fixtures.addons),
updateEvent: vi.fn().mockResolvedValue(fixtures.event),
createEventAddonCheckout: vi.fn().mockResolvedValue({
checkout_url: null,
checkout_id: 'chk_123',
expires_at: null,
}),
getEventEngagement: vi.fn().mockResolvedValue({
summary: { totalPhotos: 0, uniqueGuests: 0, tasksSolved: 0, likesTotal: 0 },
leaderboards: { uploads: [], likes: [] },
highlights: { topPhoto: null, trendingEmotion: null, timeline: [] },
feed: [],
}),
listTenantDataExports: vi.fn().mockResolvedValue([]),
requestTenantDataExport: vi.fn(),
downloadTenantDataExport: vi.fn(),
}));
vi.mock('../../auth/tokens', () => ({
isAuthError: () => false,
}));
vi.mock('../../lib/apiError', () => ({
getApiErrorMessage: () => 'error',
}));
vi.mock('../components/MobileShell', () => ({
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
HeaderActionButton: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('../components/Primitives', () => ({
MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
CTAButton: ({ label, onPress }: { label: string; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{label}
</button>
),
PillBadge: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
SkeletonCard: () => <div>Loading...</div>,
}));
vi.mock('../components/FormControls', () => ({
MobileSelect: ({ children, value, onChange }: any) => (
<select value={value ?? ''} onChange={onChange}>
{children}
</select>
),
}));
vi.mock('../components/LegalConsentSheet', () => ({
LegalConsentSheet: ({
open,
onConfirm,
}: {
open: boolean;
onConfirm: (consents: { acceptedTerms: boolean; acceptedWaiver: boolean }) => void;
}) => (open ? <button type="button" onClick={() => onConfirm({ acceptedTerms: true, acceptedWaiver: true })}>Confirm legal</button> : null),
}));
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', () => ({
Tabs: Object.assign(({ children }: { children: React.ReactNode }) => <div>{children}</div>, {
List: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
Tab: ({ children }: { children: React.ReactNode }) => <button type="button">{children}</button>,
Content: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}),
}));
vi.mock('@tamagui/react-native-web-lite', () => ({
Pressable: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
<button type="button" onClick={onPress}>
{children}
</button>
),
}));
vi.mock('@tamagui/switch', () => ({
Switch: Object.assign(
({ children, checked, onCheckedChange, 'aria-label': ariaLabel }: any) => (
<label>
<input
type="checkbox"
aria-label={ariaLabel}
checked={checked}
onChange={(event) => onCheckedChange?.(event.target.checked)}
/>
{children}
</label>
),
{ Thumb: () => <span /> },
),
}));
vi.mock('../theme', () => ({
useAdminTheme: () => ({
text: '#111827',
muted: '#6b7280',
subtle: '#94a3b8',
border: '#e5e7eb',
primary: '#ff5a5f',
successText: '#16a34a',
danger: '#dc2626',
surface: '#ffffff',
surfaceMuted: '#f9fafb',
backdrop: '#111827',
accentSoft: '#eef2ff',
textStrong: '#0f172a',
}),
}));
import MobileEventRecapPage from '../EventRecapPage';
import { createEventAddonCheckout } from '../../api';
describe('MobileEventRecapPage', () => {
beforeEach(() => {
fixtures.addons = [
{
key: 'extend_gallery_30d',
label: 'Galerie um 30 Tage verlängern',
price_id: 'price_30d',
increments: { extra_gallery_days: 30 },
},
];
vi.clearAllMocks();
});
it('renders recap settings toggles', async () => {
render(<MobileEventRecapPage />);
expect(await screen.findByText('Nachlauf-Optionen')).toBeInTheDocument();
expect(screen.getByLabelText('Gäste dürfen Fotos laden')).toBeInTheDocument();
expect(screen.getByLabelText('Gäste dürfen Fotos teilen')).toBeInTheDocument();
});
it('requires consent and sends both legal acceptance flags for recap addon checkout', async () => {
const checkoutMock = vi.mocked(createEventAddonCheckout);
render(<MobileEventRecapPage />);
const checkoutButton = await screen.findByRole('button', { name: 'Galerie um 30 Tage verlängern' });
fireEvent.click(checkoutButton);
expect(checkoutMock).not.toHaveBeenCalled();
fireEvent.click(await screen.findByRole('button', { name: 'Confirm legal' }));
await waitFor(() => {
expect(checkoutMock).toHaveBeenCalledWith(fixtures.event.slug, {
addon_key: 'extend_gallery_30d',
success_url: window.location.href,
cancel_url: window.location.href,
accepted_terms: true,
accepted_waiver: true,
});
});
});
});