Files
TREK/client/src/components/Planner/dayDetailModel.test.ts
T
Maurice 3b933470d3 fix(planner): a booking pinned to a stop on another day is shown at that stop only, not on two days
A booking linked to a stop has two days to go by, its own date and the
stop's. They part when the stop is moved to another day or the trip is
shifted with "keep bookings on their dates", and the plan then listed the
booking at the stop and again in the timeline of its own day. The stop now
wins wherever both are drawn: the desktop day plan and day detail, the
phone's plan tab and day sheet, and the road trip rail on both. The
booking's date is left as it is; a stop on one of the booking's own days
changes nothing, so a rental picked up at a stop still runs across its
other days.

Refs #2604
2026-10-12 20:42:30 +02:00

58 lines
2.8 KiB
TypeScript

// FE-PLANNER-DAYDETAILMODEL-001 to -006: the day detail derivations the desktop day
// panel and the phone day sheet share.
import { describe, expect, it } from 'vitest';
import { buildReservation } from '../../../tests/helpers/factories';
import { dayBookings, stayDayLabel, toDisplayTemp } from './dayDetailModel';
const t = (key: string) => `t:${key}`;
describe('dayBookings', () => {
it('FE-PLANNER-DAYDETAILMODEL-001: the day keeps what hangs on its stops and what is booked on it, hotels aside', () => {
const onStop = buildReservation({ id: 1, type: 'restaurant', assignment_id: 11, day_id: 9 });
const onDay = buildReservation({ id: 2, type: 'event', assignment_id: null, day_id: 4 });
const hotel = buildReservation({ id: 3, type: 'hotel', assignment_id: 11, day_id: 4 });
const otherDay = buildReservation({ id: 4, type: 'tour', assignment_id: 99, day_id: 5 });
const result = dayBookings(4, [{ id: 11 }, { id: 12 }], [onStop, onDay, hotel, otherDay]);
expect(result.map((r) => r.id)).toEqual([1, 2]);
});
it('FE-PLANNER-DAYDETAILMODEL-002: a booking on a stop of another day falls back to its own day', () => {
const moved = buildReservation({ id: 5, type: 'event', assignment_id: 77, day_id: 4 });
expect(dayBookings(4, [{ id: 11 }], [moved]).map((r) => r.id)).toEqual([5]);
expect(dayBookings(6, [{ id: 11 }], [moved])).toEqual([]);
});
it('FE-PLANNER-DAYDETAILMODEL-006: a booking whose stop moved to another day is listed at the stop only (#2604)', () => {
const dinner = buildReservation({ id: 5, type: 'restaurant', assignment_id: 77, day_id: 4 });
const away = (r: { assignment_id?: number | null }) => r.assignment_id === 77;
expect(dayBookings(4, [{ id: 11 }], [dinner], away)).toEqual([]);
expect(dayBookings(6, [{ id: 77 }], [dinner], away).map((r) => r.id)).toEqual([5]);
});
});
describe('toDisplayTemp', () => {
it('FE-PLANNER-DAYDETAILMODEL-003: rounds in the user unit, and a missing value stays unreadable', () => {
expect(toDisplayTemp(21.4, false)).toBe(21);
expect(toDisplayTemp(21.4, true)).toBe(71);
expect(toDisplayTemp(-0.6, false)).toBe(-1);
expect(toDisplayTemp(undefined, false)).toBeNaN();
expect(toDisplayTemp(undefined, true)).toBeNaN();
});
});
describe('stayDayLabel', () => {
const stay = { start_day_id: 2, end_day_id: 4 };
it('FE-PLANNER-DAYDETAILMODEL-004: names the check-in and the check-out day', () => {
expect(stayDayLabel(stay, 2, t)).toBe('t:day.checkIn');
expect(stayDayLabel(stay, 4, t)).toBe('t:day.checkOut');
expect(stayDayLabel({ start_day_id: 3, end_day_id: 3 }, 3, t)).toBe('t:day.checkIn & t:day.checkOut');
});
it('FE-PLANNER-DAYDETAILMODEL-005: a night in between, or no day at all, has no label', () => {
expect(stayDayLabel(stay, 3, t)).toBeNull();
expect(stayDayLabel(stay, undefined, t)).toBeNull();
});
});