fix(tours): tidy the day times of a tour after review

The get_tour_plan description named the estimate of a tour "such a field"
right after the values of a recording, so it could be read as one of them.
It now follows the sentence on derived fields and says outright that it is
one of them, worked out from distance and heights or the pace of a run.

The arrow between a tour's start and end points from the start to the end
in a right-to-left language as well. A tour just added to a day, which
carries no tour_place_id until the next refresh, now says its overrun like
the row above it. A phone row of an import with a total the travellers
entered shows that one time, the estimate joining its words as on the
desktop. The German overrun line reads naturally without an item name.
This commit is contained in:
Maurice
2026-10-20 20:51:09 +02:00
parent 9765cf3fee
commit 7f14dde362
10 changed files with 109 additions and 19 deletions
@@ -1,5 +1,6 @@
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -124
// FE-COMP-PLACEFORM-001 to FE-COMP-PLACEFORM-036, FE-PLANNER-PLACEFORM-016 to FE-PLANNER-PLACEFORM-067, plus FE-PLANNER-PLACEFORM-068 to -125
import { render, screen, waitFor, fireEvent, within, act } from '../../../tests/helpers/render';
import type { TourListItem } from '@trek/shared';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '../../../tests/helpers/msw/server';
@@ -878,6 +879,37 @@ describe('PlaceFormModal', () => {
expect(screen.getByDisplayValue('20:34')).toBeInTheDocument();
});
it('FE-PLANNER-PLACEFORM-125: a tour with a start and no end says below its times the end it works out to (TIME-02)', () => {
const place = buildPlace({ id: 7, name: 'Ridge', place_time: '09:00', end_time: null });
const assignment = buildAssignment({ id: 42, day_id: 3, place });
const tour: TourListItem = {
place_id: 7,
name: 'Ridge',
tour_type: 'hike',
distance: 8,
elevation_gain: 300,
elevation_loss: 300,
duration: 150,
planned_duration_minutes: null,
break_additional_minutes: 30,
difficulty: null,
wanderer_ref: null,
match_confidence: 1,
max_hiking_difficulty: 2,
planned: true,
caution: false,
};
const { unmount } = render(
<PlaceFormModal {...defaultProps} place={place} assignmentId={42} dayAssignments={[assignment]} tour={tour} />
);
expect(screen.getByTestId('tour-day-end-hint')).toHaveTextContent(
'Left empty, the end is worked out: 12:00, the start plus the tour time of 3 h.'
);
unmount();
render(<PlaceFormModal {...defaultProps} place={place} assignmentId={42} dayAssignments={[assignment]} />);
expect(screen.queryByTestId('tour-day-end-hint')).not.toBeInTheDocument();
});
it('FE-PLANNER-PLACEFORM-086: on a road trip the End says the drive leaves at it', () => {
const place = buildPlace({ name: 'Test', place_time: '09:00', end_time: '14:00' });
const assignment = buildAssignment({ id: 10, day_id: 5, place });
@@ -265,6 +265,15 @@ describe('TIME-01: the estimated time of an import on a row', () => {
expect(screen.queryByTestId('trip-plan-tour-estimate')).not.toBeInTheDocument();
});
it('TIME-01-FE-006: with a total the travellers entered a phone row shows that one time, the estimate in its words', () => {
render(<TourDayRowFacts tour={{ ...imported, planned_duration_minutes: 300 }} mobile />);
expect(screen.queryByTestId('trip-plan-tour-estimate')).not.toBeInTheDocument();
const total = screen.getByTestId('trip-plan-tour-planned-duration');
expect(total).toHaveTextContent('5 h');
expect(total).not.toHaveTextContent('≈');
expect(total.getAttribute('aria-label')).toMatch(/: 5 h\. Estimated time: 4 h\. Worked out/);
});
it('TIME-01-FE-004: a tour the planner timed shows its own time and no estimate', () => {
render(<TourDayRowFacts tour={tour} />);
expect(screen.queryByTestId('trip-plan-tour-estimate')).not.toBeInTheDocument();
@@ -298,9 +298,10 @@ export default function TourDayRowFacts({
movingTimeLabel(tour, t('tours.planner.inspector.duration'), t),
'trip-plan-tour-walking-time'
);
// TIME-01: an import's estimate, said in full where it is opened.
// TIME-01: an import's estimate, said in full where it is opened. A total
// the travellers entered is the time shown; the estimate then only joins its words.
const estimate = estimateFact(times, t);
if (estimate.value && estimate.label)
if (estimate.value && estimate.label && times.plannedTotalMinutes == null)
add(
tourDayRowIcon(movingIconType(tour.tour_type)),
estimate.value,
@@ -318,13 +319,11 @@ export default function TourDayRowFacts({
'trip-plan-tour-breaks'
);
const total = plannedTotalText(times, t, true);
if (total)
add(
Clock,
total,
`${t('tours.planner.plannedTotalDuration')}${times.manuallyOverridden ? `, ${t('tours.planner.plannedTotalManual')}` : ''}`,
'trip-plan-tour-planned-duration'
);
if (total) {
const label = `${t('tours.planner.plannedTotalDuration')}${times.manuallyOverridden ? `, ${t('tours.planner.plannedTotalManual')}` : ''}`;
const said = estimate.label ? `${label}: ${total}. ${estimate.label}` : undefined;
add(Clock, total, label, 'trip-plan-tour-planned-duration', said);
}
const check = paddleCheckOf(tour, t);
if (check) add(check.icon, check.value, t('tours.paddle.check.title'), 'plan-tour-paddle-check');
return (
@@ -1,4 +1,4 @@
// TIME-02-011 to TIME-02-016: how the day plan says a tour's time, its overrun and the hint below its time fields.
// TIME-02-011 to TIME-02-016, TIME-02-021 and TIME-02-022: how the day plan says a tour's time, its overrun and the hint below its time fields.
import type { TourListItem } from '@trek/shared';
import { beforeEach, describe, expect, it } from 'vitest';
import { render, screen } from '../../../tests/helpers/render';
@@ -53,6 +53,9 @@ describe('TourDayTimeText', () => {
unmount();
render(<TourDayTimeText entry={{ start: '22:30', end: null }} tour={tour} />);
expect(screen.getByTestId('tour-day-end-worked-out')).toHaveTextContent('01:30 +1');
expect(screen.getByTestId('tour-day-end-worked-out')).toHaveAccessibleName(
'Ends at 01:30 on the next day, worked out from the start and the tour time of 3 h'
);
});
it('TIME-02-013: an end typed by hand shows as typed, and without an end only the start shows', () => {
@@ -64,6 +67,33 @@ describe('TourDayTimeText', () => {
const plain = render(<TourDayTimeText entry={{ start: '09:00', end: null }} tour={unknown} />);
expect(plain.container.textContent).toBe('09:00');
});
it('TIME-02-021: a city walk with a stay nobody entered ends then at the earliest, marked with ≥', () => {
// 2 h 15 min on foot and 1 h of stays entered, one station of four without one.
const walk: TourListItem = {
...tour,
tour_type: 'walk',
duration: 135,
max_hiking_difficulty: null,
station_count: 4,
station_stay_minutes: 60,
station_stays_unknown: 1,
};
render(<TourDayTimeText entry={{ start: '09:00', end: null }} tour={walk} />);
const end = screen.getByTestId('tour-day-end-worked-out');
expect(end).toHaveTextContent('≥ 12:15');
expect(end).toHaveAccessibleName('Ends at 12:15, worked out from the start and the tour time of ≥ 3 h 15 min');
});
it('TIME-02-022: in a right-to-left language the arrow points from the start on the right to the end', () => {
seedStore(useSettingsStore, { settings: { time_format: '24h', language: 'ar' } });
const { container, unmount } = render(<TourDayTimeText entry={{ start: '09:00', end: '15:00' }} tour={tour} />);
expect(container.textContent).toBe('09:00 ← 15:00');
unmount();
const worked = render(<TourDayTimeText entry={{ start: '09:00', end: null }} tour={tour} />);
expect(worked.container).toHaveTextContent('09:00 ← 12:00');
expect(worked.container.textContent).not.toContain('→');
});
});
describe('TourOverrunLine', () => {
@@ -74,6 +104,11 @@ describe('TourOverrunLine', () => {
render(<TourOverrunLine overrun={{ name: 'Lunch', time: '12:00', end: '13:00' }} />);
expect(screen.getByTestId('tour-day-overrun')).toHaveTextContent('Ends at 13:00, after Lunch starts at 12:00');
});
it('TIME-02-014b: an item without a name is called the next item', () => {
render(<TourOverrunLine overrun={{ name: '', time: '12:00', end: '13:00' }} />);
expect(screen.getByTestId('tour-day-overrun')).toHaveTextContent('Ends at 13:00, after the next item starts at 12:00');
});
});
describe('workedOutEndHint', () => {
@@ -1,6 +1,6 @@
import type { TourListItem } from '@trek/shared';
import { Clock } from 'lucide-react';
import { useTranslation } from '../../i18n';
import { isRtlLanguage, useTranslation } from '../../i18n';
import { useSettingsStore } from '../../store/settingsStore';
import type { Assignment } from '../../types';
import { formatTime } from '../../utils/formatters';
@@ -46,18 +46,20 @@ export function TourDayTimeText({
tour: TourListItem;
mobile?: boolean;
}) {
const { t, locale } = useTranslation();
const { t, locale, language } = useTranslation();
const timeFormat = useSettingsStore((state) => state.settings.time_format) ?? '24h';
const time = tourDayTimeOf(entry, tour);
if (!time) return null;
const clock = (value: string) => formatTime(value, locale, timeFormat);
// The arrow is not mirrored by the bidi rules: in a right-to-left row the start sits on the right.
const arrow = isRtlLanguage(language) ? '←' : '→';
if (!time.end) return <>{clock(time.start)}</>;
if (!time.workedOut) return <>{`${clock(time.start)} → ${clock(time.end)}`}</>;
if (!time.workedOut) return <>{`${clock(time.start)} ${arrow} ${clock(time.end)}`}</>;
const label = workedOutLabel(time, t, clock);
const mark = time.estimated ? '≈ ' : time.atLeast ? '≥ ' : '';
return (
<>
{`${clock(time.start)} → `}
{`${clock(time.start)} ${arrow} `}
<Tooltip label={label}>
<span
data-testid="tour-day-end-worked-out"
@@ -148,5 +148,12 @@ describe('dayItemOverrun', () => {
expect(dayItemOverrun(items, 1, 3, tourOf)).toBeNull();
expect(dayItemOverrun(items, 0, 3, () => undefined)).toBeNull();
expect(dayItemOverrun([note('09:00', 'Wake'), ...items], 0, 3, tourOf)).toBeNull();
// A tour just added to the day, online or offline, carries no tour_place_id yet and still runs over.
const fresh = placeItem(7, 'Ridge', '10:00', { assignment_time: '10:00' });
expect(dayItemOverrun([fresh, placeItem(2, 'Lunch', '12:00')], 0, 3, tourOf)).toEqual({
name: 'Lunch',
time: '12:00',
end: '13:00',
});
});
});
+2 -1
View File
@@ -135,7 +135,8 @@ export function dayItemOverrun(
const item = items[index];
if (item?.type !== 'place') return null;
const assignment: Assignment = item.data;
const tour = assignment.tour_place_id === assignment.place_id ? tourOf(assignment.place_id) : undefined;
// By the trip's tours alone, as the rows are: an entry added a moment ago carries no tour_place_id yet.
const tour = tourOf(assignment.place_id);
if (!tour) return null;
return tourOverrunOf(items.slice(index + 1), dayId, tourDayTimeOf(tourDayEntryOf(assignment), tour));
}