Migrate guest v2 achievements and refresh share page
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import React from 'react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
const useEventDataMock = vi.fn();
|
||||
const navigateMock = vi.fn();
|
||||
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useNavigate: () => vi.fn(),
|
||||
useNavigate: () => navigateMock,
|
||||
}));
|
||||
|
||||
vi.mock('../context/EventDataContext', () => ({
|
||||
@@ -21,8 +22,8 @@ vi.mock('@tamagui/text', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/button', () => ({
|
||||
Button: ({ children, ...rest }: { children: React.ReactNode }) => (
|
||||
<button type="button" {...rest}>
|
||||
Button: ({ children, onPress, ...rest }: { children: React.ReactNode; onPress?: () => void }) => (
|
||||
<button type="button" onClick={onPress} {...rest}>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
@@ -84,11 +85,17 @@ vi.mock('../services/emotionsApi', () => ({
|
||||
fetchEmotions: vi.fn().mockResolvedValue([{ slug: 'freude', name: 'Joy' }]),
|
||||
}));
|
||||
|
||||
const fetchGalleryMock = vi.fn().mockResolvedValue({ data: [] });
|
||||
|
||||
vi.mock('../services/photosApi', () => ({
|
||||
fetchGallery: vi.fn().mockResolvedValue({ data: [] }),
|
||||
fetchGallery: (...args: unknown[]) => fetchGalleryMock(...args),
|
||||
}));
|
||||
|
||||
const translate = (key: string, fallback?: string) => fallback ?? key;
|
||||
const translate = (key: string, options?: unknown, fallback?: string) => {
|
||||
if (typeof fallback === 'string') return fallback;
|
||||
if (typeof options === 'string') return options;
|
||||
return key;
|
||||
};
|
||||
|
||||
vi.mock('@/guest/i18n/useTranslation', () => ({
|
||||
useTranslation: () => ({ t: translate, locale: 'de' }),
|
||||
@@ -119,7 +126,13 @@ vi.mock('@/guest/hooks/useGuestTaskProgress', () => ({
|
||||
import HomeScreen from '../screens/HomeScreen';
|
||||
|
||||
describe('HomeScreen', () => {
|
||||
beforeEach(() => {
|
||||
navigateMock.mockReset();
|
||||
fetchGalleryMock.mockReset();
|
||||
});
|
||||
|
||||
it('shows task hero content when tasks are enabled', async () => {
|
||||
fetchGalleryMock.mockResolvedValueOnce({ data: [] });
|
||||
useEventDataMock.mockReturnValue({
|
||||
tasksEnabled: true,
|
||||
token: 'demo',
|
||||
@@ -133,6 +146,7 @@ describe('HomeScreen', () => {
|
||||
});
|
||||
|
||||
it('shows capture-ready content when tasks are disabled', () => {
|
||||
fetchGalleryMock.mockResolvedValueOnce({ data: [] });
|
||||
useEventDataMock.mockReturnValue({
|
||||
tasksEnabled: false,
|
||||
token: 'demo',
|
||||
@@ -144,4 +158,22 @@ describe('HomeScreen', () => {
|
||||
expect(screen.getByText('Capture ready')).toBeInTheDocument();
|
||||
expect(screen.getByText('Upload / Take photo')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens gallery lightbox from preview tile', async () => {
|
||||
fetchGalleryMock.mockResolvedValueOnce({
|
||||
data: [{ id: 42, thumbnail_url: '/storage/demo.jpg' }],
|
||||
});
|
||||
useEventDataMock.mockReturnValue({
|
||||
tasksEnabled: false,
|
||||
token: 'demo',
|
||||
event: { name: 'Demo Event' },
|
||||
});
|
||||
|
||||
render(<HomeScreen />);
|
||||
|
||||
const previewButton = await screen.findByRole('button', { name: /foto 42/i });
|
||||
fireEvent.click(previewButton);
|
||||
|
||||
expect(navigateMock).toHaveBeenCalledWith('/e/demo/gallery?photo=42');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user