mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
52ed63715c
The repository stubs of the tour service tests answer findProvenance, which getTour and createTour read since P2C-02. Switching the Tours addon off now ends live MCP sessions like every other addon that gates a tool (MCP-GATE-PARITY-001). copyTour refuses a line without a point instead of placing the copy at 0/0, and new tests cover the reachable paths of the copy, the source check and the provenance of a snapshot without its import record, including a trip copy keeping that record. On the client the shared day assignment hands the plan exactly the tour and the day, the new visibility store is reset between tests, and the tests of the sidebar, the detail, the phone sheet and the origin section match the views this PR built.
115 lines
4.4 KiB
TypeScript
115 lines
4.4 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import type { TripPlanner } from '../../../../src/mobile/screens/trip/MTripShell';
|
|
import MBrowseActionsSheet from '../../../../src/mobile/screens/trip/sheets/MBrowseActionsSheet';
|
|
import { useTripStore } from '../../../../src/store/tripStore';
|
|
import type { Place } from '../../../../src/types';
|
|
import { buildPlanner, buildShell } from '../../../helpers/mobileTrip';
|
|
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render';
|
|
import { resetAllStores, seedStore } from '../../../helpers/store';
|
|
|
|
function tourPlace(): Place {
|
|
return {
|
|
id: 42,
|
|
trip_id: 1,
|
|
name: 'Ridge walk',
|
|
address: null,
|
|
description: null,
|
|
category_id: null,
|
|
lat: 48,
|
|
lng: 11,
|
|
image_url: null,
|
|
google_place_id: null,
|
|
osm_id: null,
|
|
route_geometry: '[[48,11],[49,12]]',
|
|
route_color: null,
|
|
tour_place_id: 42,
|
|
} as unknown as Place;
|
|
}
|
|
|
|
const days = [
|
|
{ id: 7, trip_id: 1, day_number: 1, title: 'Day one', date: null },
|
|
{ id: 8, trip_id: 1, day_number: 2, title: 'Day two', date: null },
|
|
{ id: 9, trip_id: 1, day_number: 3, title: 'Day three', date: null },
|
|
] as never;
|
|
|
|
function mobilePlanner(overrides: Partial<TripPlanner> = {}) {
|
|
const place = tourPlace();
|
|
return buildPlanner({
|
|
places: [place],
|
|
days,
|
|
assignments: { '7': [{ id: 70, day_id: 7, place_id: place.id }] } as never,
|
|
isTourPlace: vi.fn((placeId: number) => placeId === place.id),
|
|
...overrides,
|
|
} as Partial<TripPlanner>);
|
|
}
|
|
|
|
function renderDayPicker(planner = mobilePlanner()) {
|
|
const shell = buildShell({ sheet: { id: 'bract', payload: { placeId: 42, dayPicker: true } } });
|
|
const view = render(<MBrowseActionsSheet planner={planner} shell={shell} />);
|
|
return { ...view, planner, shell };
|
|
}
|
|
|
|
describe('MBrowseActionsSheet Tour assignment picker', () => {
|
|
it('disables assigned Tour days, blocks repeat clicks, and refreshes on reopen', async () => {
|
|
resetAllStores();
|
|
// The days a tour is on are read from the trip store, the one place every tour view reads them from.
|
|
seedStore(useTripStore, { assignments: { '7': [{ id: 70, day_id: 7, place_id: 42 }] } as never });
|
|
let finishAssignment!: (assigned: boolean) => void;
|
|
const handleAssignToDay = vi.fn(
|
|
() =>
|
|
new Promise<boolean>((resolve) => {
|
|
finishAssignment = resolve;
|
|
})
|
|
);
|
|
const planner = mobilePlanner({ handleAssignToDay });
|
|
const { rerender, shell } = renderDayPicker(planner);
|
|
|
|
expect(screen.queryByRole('button', { name: 'Delete' })).not.toBeInTheDocument();
|
|
|
|
const dayOne = screen.getByRole('button', { name: /Day one/ });
|
|
const dayTwo = screen.getByRole('button', { name: /Day two/ });
|
|
expect(dayOne).toBeDisabled();
|
|
expect(dayTwo).toBeEnabled();
|
|
fireEvent.click(dayOne);
|
|
expect(handleAssignToDay).not.toHaveBeenCalled();
|
|
|
|
fireEvent.click(dayTwo);
|
|
fireEvent.click(dayTwo);
|
|
expect(handleAssignToDay).toHaveBeenCalledTimes(1);
|
|
expect(handleAssignToDay).toHaveBeenCalledWith(42, 8);
|
|
|
|
await act(async () => {
|
|
finishAssignment(true);
|
|
});
|
|
await waitFor(() => expect(shell.closeSheet).toHaveBeenCalledOnce());
|
|
|
|
const assignedAfter = {
|
|
'7': [{ id: 70, day_id: 7, place_id: 42 }],
|
|
'8': [{ id: 80, day_id: 8, place_id: 42 }],
|
|
} as never;
|
|
act(() => seedStore(useTripStore, { assignments: assignedAfter }));
|
|
const reopened = mobilePlanner({ assignments: assignedAfter });
|
|
rerender(<MBrowseActionsSheet planner={reopened} shell={shell} />);
|
|
expect(screen.getByRole('button', { name: /Day one/ })).toBeDisabled();
|
|
expect(screen.getByRole('button', { name: /Day two/ })).toBeDisabled();
|
|
expect(screen.getByRole('button', { name: /Day three/ })).toBeEnabled();
|
|
});
|
|
|
|
it('leaves ordinary Place day choices enabled and preserves their assignment write behavior', () => {
|
|
resetAllStores();
|
|
const place = { ...tourPlace(), tour_place_id: undefined };
|
|
const handleAssignToDay = vi.fn().mockResolvedValue(true);
|
|
const planner = mobilePlanner({
|
|
places: [place],
|
|
isTourPlace: vi.fn(() => false),
|
|
assignments: { '7': [{ id: 70, day_id: 7, place_id: place.id }] } as never,
|
|
handleAssignToDay,
|
|
});
|
|
renderDayPicker(planner);
|
|
const dayOne = screen.getByRole('button', { name: /Day one/ });
|
|
expect(dayOne).toBeEnabled();
|
|
fireEvent.click(dayOne);
|
|
expect(handleAssignToDay).toHaveBeenCalledWith(place.id, 7);
|
|
});
|
|
});
|