95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
import React from 'react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
|
|
const backMock = vi.fn();
|
|
const navigateMock = vi.fn();
|
|
|
|
vi.mock('react-router-dom', () => ({
|
|
useNavigate: () => navigateMock,
|
|
useParams: () => ({}),
|
|
}));
|
|
|
|
vi.mock('../hooks/useBackNavigation', () => ({
|
|
useBackNavigation: () => backMock,
|
|
}));
|
|
|
|
vi.mock('../../api', () => ({
|
|
createEvent: vi.fn(),
|
|
getEvent: vi.fn(),
|
|
updateEvent: vi.fn(),
|
|
getEventTypes: vi.fn().mockResolvedValue([]),
|
|
trackOnboarding: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('react-hot-toast', () => ({
|
|
default: {
|
|
error: vi.fn(),
|
|
success: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock('../components/MobileShell', () => ({
|
|
MobileShell: ({ 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>
|
|
),
|
|
}));
|
|
|
|
vi.mock('../components/FormControls', () => ({
|
|
MobileField: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
MobileInput: (props: React.InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
|
|
MobileSelect: ({ children, ...props }: { children: React.ReactNode }) => <select {...props}>{children}</select>,
|
|
MobileTextArea: (props: React.TextareaHTMLAttributes<HTMLTextAreaElement>) => <textarea {...props} />,
|
|
}));
|
|
|
|
vi.mock('../components/LegalConsentSheet', () => ({
|
|
LegalConsentSheet: () => 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/switch', () => ({
|
|
Switch: Object.assign(
|
|
({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
{ Thumb: () => <div /> },
|
|
),
|
|
}));
|
|
|
|
vi.mock('../theme', () => ({
|
|
useAdminTheme: () => ({
|
|
text: '#111827',
|
|
muted: '#6b7280',
|
|
subtle: '#94a3b8',
|
|
danger: '#b91c1c',
|
|
}),
|
|
}));
|
|
|
|
import MobileEventFormPage from '../EventFormPage';
|
|
|
|
describe('MobileEventFormPage', () => {
|
|
it('renders a save draft button when creating a new event', async () => {
|
|
await act(async () => {
|
|
render(<MobileEventFormPage />);
|
|
});
|
|
|
|
const saveDraft = screen.getByText('eventForm.actions.saveDraft');
|
|
fireEvent.click(saveDraft);
|
|
|
|
expect(backMock).toHaveBeenCalled();
|
|
});
|
|
});
|