mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
8f53d98d45
Every journey map (the desktop aside, the phone screens and the shared page) now carries four switches: Plan, Recorded, Entries and Photos, each with its count, a spinner while it loads, the warning tone when it could not be read and the reason when it has nothing to show. A switch only hides, in place: the map is not rebuilt and keeps its view, and the choice is kept in this browser per journey (per link on a shared page, by a hash of its token). The plan draws the places the linked trips put on their days as hollow dashed pins and the trips' GPX routes dashed; a place an entry was written about is not drawn twice, the entry's pin carries a check instead. The stays a day report was taken over from show as dots in the colour of their day. Marks on one spot join into a disc with their number and open as a list; a picked place or stay opens a card with its trip, days and times and leads to its entry. A key beside the switches explains every pin and line and says that a plan is no proof of a visit. The phone timelines now show the photos too. The GPX routes come with the map's layers through the linked trips, read only while the journey's track switch is on; the frozen /tracks answer stays Studio's. The share settings on desktop and phone get Trip plan and Recorded routes under Map, off by default and only switchable while the map is shared.
90 lines
3.4 KiB
TypeScript
90 lines
3.4 KiB
TypeScript
// FE-JOURNEY-MAPPICK-001 to FE-JOURNEY-MAPPICK-003
|
|
//
|
|
// JRN-04: what a picked plan place or stay is, and several on one spot as a list.
|
|
import type { JourneyMapPlace, JourneyMapStay } from '@trek/shared';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { fireEvent, render, screen } from '../../../tests/helpers/render';
|
|
import JourneyMapPickCard from './JourneyMapPickCard';
|
|
import type { JourneyMapMark } from './journeyMapMarks';
|
|
|
|
const PLACE: JourneyMapPlace = {
|
|
place_id: 4,
|
|
trip_id: 2,
|
|
trip_title: 'Venice',
|
|
name: 'Piazza San Marco',
|
|
lat: 45.434,
|
|
lng: 12.3388,
|
|
days: ['2026-05-14', '2026-05-15'],
|
|
time: '10:00',
|
|
category_color: null,
|
|
category_icon: null,
|
|
entry_id: null,
|
|
};
|
|
const STAY: JourneyMapStay = {
|
|
id: 9,
|
|
entry_id: 7,
|
|
name: 'Rialto market',
|
|
lat: 45.438,
|
|
lng: 12.336,
|
|
started_at: '2026-05-14T09:00:00+02:00',
|
|
ended_at: '2026-05-14T10:00:00+02:00',
|
|
};
|
|
const plan = (over: Partial<JourneyMapPlace> = {}): JourneyMapMark => ({
|
|
kind: 'plan',
|
|
key: 'plan:4',
|
|
lat: 45.434,
|
|
lng: 12.3388,
|
|
color: '#64748b',
|
|
place: { ...PLACE, ...over },
|
|
});
|
|
const stay: JourneyMapMark = { kind: 'stay', key: 'stay:9', lat: 45.438, lng: 12.336, color: '#14b8a6', stay: STAY };
|
|
|
|
describe('JourneyMapPickCard', () => {
|
|
it('FE-JOURNEY-MAPPICK-001: a planned place names its trip and days and says when nothing was written about it', () => {
|
|
render(<JourneyMapPickCard marks={[plan()]} onClose={vi.fn()} onOpenEntry={vi.fn()} />);
|
|
|
|
expect(screen.getByRole('dialog', { name: 'Piazza San Marco' })).toBeInTheDocument();
|
|
expect(screen.getByText('Planned')).toBeInTheDocument();
|
|
expect(screen.getByText('Venice')).toBeInTheDocument();
|
|
expect(screen.getByText('10:00')).toBeInTheDocument();
|
|
expect(screen.getByText('Nothing written about it yet.')).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: 'Open entry' })).toBeNull();
|
|
});
|
|
|
|
it('FE-JOURNEY-MAPPICK-002: a place written about and a stay lead to their entry', () => {
|
|
const onOpenEntry = vi.fn();
|
|
const { unmount } = render(
|
|
<JourneyMapPickCard marks={[plan({ entry_id: 12 })]} onClose={vi.fn()} onOpenEntry={onOpenEntry} />
|
|
);
|
|
fireEvent.click(screen.getByRole('button', { name: 'Open entry' }));
|
|
expect(onOpenEntry).toHaveBeenCalledWith('12');
|
|
unmount();
|
|
|
|
render(
|
|
<JourneyMapPickCard
|
|
marks={[stay]}
|
|
onClose={vi.fn()}
|
|
onOpenEntry={onOpenEntry}
|
|
entryTitleOf={() => 'A day in Venice'}
|
|
/>
|
|
);
|
|
expect(screen.getByText('Part of “A day in Venice”')).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: 'Open entry' }));
|
|
expect(onOpenEntry).toHaveBeenLastCalledWith('7');
|
|
});
|
|
|
|
it('FE-JOURNEY-MAPPICK-003: several on one spot come as a list, each reachable, and Escape closes', () => {
|
|
const onClose = vi.fn();
|
|
render(<JourneyMapPickCard marks={[plan(), stay]} onClose={onClose} />);
|
|
|
|
expect(screen.getByRole('dialog', { name: 'At this spot' })).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: /Rialto market/ }));
|
|
expect(screen.getByRole('dialog', { name: 'Rialto market' })).toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole('button', { name: 'Back to the list' }));
|
|
expect(screen.getByRole('button', { name: /Piazza San Marco/ })).toBeInTheDocument();
|
|
|
|
fireEvent.keyDown(window, { key: 'Escape' });
|
|
expect(onClose).toHaveBeenCalled();
|
|
});
|
|
});
|