mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
9bec97fc19
* Start the Journey date picker week on Monday (#1078) The Journey entry date picker started the week on Sunday (firstDow = getDay(), headers Su-first) while every other picker (CustomDateTimePicker, VacayCalendar) starts on Monday. Align it: Monday-first leading offset ((getDay()+6)%7) and Mo-first weekday headers. * Fix Taiwan resolving to CN-TW in the Atlas country search (#1049) natural-earth gives Taiwan ISO_A2='CN-TW' (a subdivision-style value) with ADM0_A3='TWN'. The dynamic A2_TO_A3 augmentation added 'CN-TW'->'TWN', which then overwrote the legitimate TWN->TW entry in the reverse map, so Taiwan's country option resolved to 'CN-TW' — unresolvable by Intl.DisplayNames (no name, broken flag, not searchable). Only augment A2_TO_A3 with real 2-letter codes. * Drop empty leftover dateless days when a trip gets a shorter dated range (#1083) generateDays kept all unused dateless placeholder days after switching to an explicit (shorter) date range, so day_count (COUNT(*) FROM days) stayed inflated. Delete the empty leftovers (no assignments/notes/accommodations) like the dateless path already does, while preserving any that still hold content. Adds TRIP-SVC-017. * Render GPX and route overlays once the Mapbox style has loaded (#1036) The GPX and route geojson effects ran before the map 'load' event had attached their sources, so on the first paint they hit the early return and never re-ran. Add mapReady to their dependencies so they fire again the moment the sources exist. * Convert HEIC trip and journey covers to JPEG before upload (#1085) HEIC/HEIF covers coming straight off an iPhone could not be rendered in the preview or stored as a usable image. Route both cover pickers through normalizeImageFile, the same conversion the journal entry editor already uses, so the file becomes a JPEG before it leaves the browser. * Name GPX routes and tracks after their source file so multiple imports stick (#1054) Unnamed routes and tracks all fell back to the same generic 'GPX Route' / 'GPX Track' label, so the name-based import dedup dropped every one after the first - importing several files (or one file with several tracks) only kept a single place. Derive the default name from the source filename with an index suffix when a file holds more than one geometry, thread the filename down through the controller, and let the import modal take more than one file at a time. Adds PLACE-SVC-037/038. * Namespace the modal backdrop class so content blockers stop hiding it (#1027) Generic class names like .modal-backdrop sit on the cosmetic filter lists that content blockers (1Blocker, EasyList Annoyances) ship, and get hidden with display:none. The shared Modal - used by New Trip and Add Place - carried that class, so Safari users running such a blocker saw the modal silently fail to open with no error and no network request. Rename it to .trek-modal-backdrop. * Highlight GB regions by resolving England/Scotland/Wales/NI to finer admin-1 codes (#1067) A zoom-8 reverse geocode of a UK place only resolves to the constituent country (GB-ENG/SCT/WLS/NIR), but Natural Earth's admin-1 polygons for GB are counties and boroughs (GB-LND, GB-MAN, GB-CON, ...). Those four codes match no polygon, so places in England never highlighted in the Atlas while CH/IT/NL/etc. worked. When a GB lookup lands on a constituent country, re-resolve it at a finer zoom where Nominatim exposes the county/borough code the polygons actually carry. Other countries keep the exact zoom-8 behaviour. Adds ATLAS-UNIT-021. * Surface the real place-search error instead of a generic toast (#1092) When a place search or detail lookup fails, the backend already forwards the upstream reason - including descriptive Google Places API messages such as 'Places API (New) has not been used in project ... or it is disabled'. The planner discarded it and always showed 'Place search failed', so a key that is mis-enabled, unbilled, or pointed at the legacy API instead of Places API (New) looked like an unexplained silent failure. Show the server-provided message when present, and stop the Atlas bucket-list search from swallowing its error without a trace. * Await the async cover normalization in the TripFormModal paste test (#1085) handleCoverSelect now normalizes the pasted file before previewing it, so URL.createObjectURL is called a microtask later. The assertion moves into waitFor; a non-HEIC file still passes through unchanged.
292 lines
13 KiB
TypeScript
292 lines
13 KiB
TypeScript
// FE-COMP-TRIPFORM-001 to FE-COMP-TRIPFORM-028
|
|
import { render, screen, waitFor, fireEvent } from '../../../tests/helpers/render';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { useAuthStore } from '../../store/authStore';
|
|
import { useTripStore } from '../../store/tripStore';
|
|
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
|
import { buildUser, buildTrip } from '../../../tests/helpers/factories';
|
|
import { server } from '../../../tests/helpers/msw/server';
|
|
import TripFormModal from './TripFormModal';
|
|
|
|
const defaultProps = {
|
|
isOpen: true,
|
|
onClose: vi.fn(),
|
|
onSave: vi.fn(),
|
|
trip: null,
|
|
onCoverUpdate: vi.fn(),
|
|
};
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
seedStore(useAuthStore, { user: buildUser(), isAuthenticated: true });
|
|
seedStore(useTripStore, { trip: buildTrip({ id: 1 }) });
|
|
});
|
|
|
|
describe('TripFormModal', () => {
|
|
it('FE-COMP-TRIPFORM-001: renders without crashing', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
expect(document.body).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-002: shows Create New Trip title for new trip', () => {
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
expect(screen.getAllByText('Create New Trip').length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-003: shows Edit Trip title when editing', () => {
|
|
const trip = buildTrip({ id: 1, title: 'Japan 2025' });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
expect(screen.getByText('Edit Trip')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-004: shows trip title input field', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
expect(screen.getByPlaceholderText(/Summer in Japan/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-005: Cancel button is present', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
expect(screen.getByRole('button', { name: /Cancel/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-006: clicking Cancel calls onClose', async () => {
|
|
const user = userEvent.setup();
|
|
const onClose = vi.fn();
|
|
render(<TripFormModal {...defaultProps} onClose={onClose} />);
|
|
await user.click(screen.getByRole('button', { name: /Cancel/i }));
|
|
expect(onClose).toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-007: Create New Trip submit button is present', () => {
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
// Submit button text is "Create New Trip" for new trips
|
|
const createBtns = screen.getAllByText('Create New Trip');
|
|
expect(createBtns.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-008: Update button shown when editing', () => {
|
|
const trip = buildTrip({ id: 1, title: 'Japan 2025' });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
expect(screen.getByRole('button', { name: /Update/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-009: submitting with empty title shows error', async () => {
|
|
const user = userEvent.setup();
|
|
render(<TripFormModal {...defaultProps} />);
|
|
// Click submit without filling title
|
|
const submitBtn = screen.getAllByText('Create New Trip').find(
|
|
el => el.tagName === 'BUTTON' || el.closest('button')
|
|
);
|
|
if (submitBtn) {
|
|
await user.click(submitBtn.closest('button') || submitBtn);
|
|
}
|
|
// Error: "Title is required"
|
|
await screen.findByText('Title is required');
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-010: typing title and submitting calls onSave', async () => {
|
|
const user = userEvent.setup();
|
|
const onSave = vi.fn().mockResolvedValue({ trip: buildTrip({ id: 99 }) });
|
|
render(<TripFormModal {...defaultProps} onSave={onSave} />);
|
|
await user.type(screen.getByPlaceholderText(/Summer in Japan/i), 'Paris 2026');
|
|
const submitBtns = screen.getAllByText('Create New Trip');
|
|
const submitBtn = submitBtns.find(el => el.closest('button'));
|
|
await user.click(submitBtn!.closest('button')!);
|
|
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
|
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ title: 'Paris 2026' }));
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-011: pre-fills title when editing trip', () => {
|
|
const trip = buildTrip({ id: 1, title: 'Iceland Adventure' });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
expect(screen.getByDisplayValue('Iceland Adventure')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-012: shows Title label', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
// dashboard.tripTitle = "Title"
|
|
expect(screen.getByText('Title')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-013: shows Cover Image section', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
expect(screen.getByText('Cover Image')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-014: shows start and end date labels', () => {
|
|
render(<TripFormModal {...defaultProps} />);
|
|
// Uses CustomDatePicker with labels "Start Date" and "End Date"
|
|
const startEls = screen.getAllByText('Start Date');
|
|
const endEls = screen.getAllByText('End Date');
|
|
expect(startEls.length).toBeGreaterThan(0);
|
|
expect(endEls.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-015: renders date picker components for start and end', () => {
|
|
const trip = buildTrip({ id: 1, title: 'Test Trip', start_date: '2026-06-01', end_date: '2026-06-15' });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
// CustomDatePicker shows formatted dates as button text (locale-dependent)
|
|
// Just verify labels and form render without error
|
|
expect(screen.getByText('Start Date')).toBeInTheDocument();
|
|
expect(screen.getByText('End Date')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-016: end-date validation shows error when end < start', async () => {
|
|
const user = userEvent.setup();
|
|
const onSave = vi.fn();
|
|
// Trip with end_date before start_date; title is set so title validation passes
|
|
const trip = buildTrip({ id: 1, title: 'Test Trip', start_date: '2026-06-15', end_date: '2026-06-01' } as any);
|
|
render(<TripFormModal {...defaultProps} trip={trip} onSave={onSave} />);
|
|
const updateBtn = screen.getByRole('button', { name: /Update/i });
|
|
await user.click(updateBtn);
|
|
await screen.findByText('End date must be after start date');
|
|
expect(onSave).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-017: day count field visible when no dates set', () => {
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
expect(screen.getByText('Number of Days')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-018: day count hidden when trip has dates', () => {
|
|
const trip = buildTrip({ id: 1, start_date: '2026-06-01', end_date: '2026-06-10' });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
expect(screen.queryByText('Number of Days')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-019: reminder buttons visible when tripRemindersEnabled=true', async () => {
|
|
seedStore(useAuthStore, { tripRemindersEnabled: true });
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
expect(screen.getByRole('button', { name: 'None' })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: '1 day' })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: '3 days' })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: '9 days' })).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-020: reminder section shows disabled hint when tripRemindersEnabled=false', () => {
|
|
seedStore(useAuthStore, { tripRemindersEnabled: false });
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
expect(screen.getByText(/Trip reminders are disabled/i)).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: 'None' })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: 'Custom' })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-021: custom reminder input appears and accepts value', async () => {
|
|
const user = userEvent.setup();
|
|
seedStore(useAuthStore, { tripRemindersEnabled: true });
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
await user.click(screen.getByRole('button', { name: 'Custom' }));
|
|
// custom reminder input has max=30
|
|
const customInput = document.querySelector('input[max="30"]') as HTMLInputElement;
|
|
expect(customInput).toBeInTheDocument();
|
|
// Use fireEvent.change to set the value directly (avoids clamping from char-by-char typing)
|
|
fireEvent.change(customInput, { target: { value: '14' } });
|
|
expect(customInput.value).toBe('14');
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-022: member selector not visible when editing existing trip', () => {
|
|
const trip = buildTrip({ id: 1 });
|
|
render(<TripFormModal {...defaultProps} trip={trip} />);
|
|
expect(screen.queryByText('Travel buddies')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-023: member selector appears when creating and other users exist', async () => {
|
|
server.use(
|
|
http.get('/api/auth/users', () =>
|
|
HttpResponse.json({ users: [{ id: 100, username: 'alice' }] })
|
|
)
|
|
);
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
await screen.findByText('Travel buddies');
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-024: selecting a member adds a chip', async () => {
|
|
const user = userEvent.setup();
|
|
seedStore(useAuthStore, { user: buildUser({ id: 1, username: 'me' }), isAuthenticated: true });
|
|
server.use(
|
|
http.get('/api/auth/users', () =>
|
|
HttpResponse.json({ users: [{ id: 100, username: 'alice' }] })
|
|
)
|
|
);
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
// Wait for member section to load
|
|
await screen.findByText('Travel buddies');
|
|
// Click the CustomSelect trigger (placeholder "Add member")
|
|
const selectTrigger = screen.getByText('Add member').closest('button')!;
|
|
await user.click(selectTrigger);
|
|
// alice option appears in portal (document.body)
|
|
const aliceOption = await screen.findByRole('button', { name: 'alice' });
|
|
await user.click(aliceOption);
|
|
// alice chip should now be in the member chip list
|
|
expect(screen.getByText('alice')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-025: removing a member chip deselects them', async () => {
|
|
const user = userEvent.setup();
|
|
seedStore(useAuthStore, { user: buildUser({ id: 1, username: 'me' }), isAuthenticated: true });
|
|
server.use(
|
|
http.get('/api/auth/users', () =>
|
|
HttpResponse.json({ users: [{ id: 100, username: 'alice' }] })
|
|
)
|
|
);
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
await screen.findByText('Travel buddies');
|
|
// Select alice
|
|
const selectTrigger = screen.getByText('Add member').closest('button')!;
|
|
await user.click(selectTrigger);
|
|
const aliceOption = await screen.findByRole('button', { name: 'alice' });
|
|
await user.click(aliceOption);
|
|
// alice chip is present
|
|
const aliceChip = screen.getByText('alice');
|
|
expect(aliceChip).toBeInTheDocument();
|
|
// Click the chip to remove alice
|
|
await user.click(aliceChip.closest('span')!);
|
|
// alice chip should be gone
|
|
await waitFor(() => expect(screen.queryByText('alice')).not.toBeInTheDocument());
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-026: cover image paste fires URL.createObjectURL', async () => {
|
|
const mockCreateObjectURL = vi.fn(() => 'blob:mock-paste-url');
|
|
const original = URL.createObjectURL;
|
|
Object.defineProperty(URL, 'createObjectURL', { writable: true, configurable: true, value: mockCreateObjectURL });
|
|
|
|
render(<TripFormModal {...defaultProps} trip={null} />);
|
|
const form = document.querySelector('form')!;
|
|
const file = new File(['img'], 'cover.png', { type: 'image/png' });
|
|
fireEvent.paste(form, {
|
|
clipboardData: {
|
|
items: [{ type: 'image/png', getAsFile: () => file }],
|
|
},
|
|
});
|
|
// Cover selection now normalizes the file (HEIC -> JPEG) before previewing, so the
|
|
// createObjectURL call lands a microtask later; a non-HEIC file passes through unchanged.
|
|
await waitFor(() => expect(mockCreateObjectURL).toHaveBeenCalledWith(file));
|
|
|
|
Object.defineProperty(URL, 'createObjectURL', { writable: true, configurable: true, value: original });
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-027: onSave error message is displayed', async () => {
|
|
const user = userEvent.setup();
|
|
const onSave = vi.fn().mockRejectedValue(new Error('Server error'));
|
|
render(<TripFormModal {...defaultProps} onSave={onSave} trip={null} />);
|
|
await user.type(screen.getByPlaceholderText(/Summer in Japan/i), 'My Trip');
|
|
const submitBtns = screen.getAllByText('Create New Trip');
|
|
const submitBtn = submitBtns.find(el => el.closest('button'))!;
|
|
await user.click(submitBtn.closest('button')!);
|
|
await screen.findByText('Server error');
|
|
});
|
|
|
|
it('FE-COMP-TRIPFORM-028: loading spinner shown while submitting', async () => {
|
|
const user = userEvent.setup();
|
|
const onSave = vi.fn().mockImplementation(() => new Promise(() => {}));
|
|
render(<TripFormModal {...defaultProps} onSave={onSave} trip={null} />);
|
|
await user.type(screen.getByPlaceholderText(/Summer in Japan/i), 'My Trip');
|
|
const submitBtns = screen.getAllByText('Create New Trip');
|
|
const submitBtn = submitBtns.find(el => el.closest('button'))!;
|
|
await user.click(submitBtn.closest('button')!);
|
|
await waitFor(() => expect(screen.getByText('Saving...')).toBeInTheDocument());
|
|
});
|
|
});
|