refactor(planner): share the booking form and its hotel stay between desktop and phone

The booking dialog and the phone booking sheet keep their markup and run on useReservationForm: how a saved booking or an import fills the form, the end before start check, the start date and time, the place and hotel picks, the stay range and the request body with the stay a hotel booking creates come from reservationFormModel. The desktop's check-in window, its link to a stop inside the form and its imported price stay its own, behind options where the code is shared.
This commit is contained in:
Maurice
2026-10-09 10:43:50 +02:00
parent 203e425e7e
commit fc3cc1bbbe
14 changed files with 1360 additions and 571 deletions
@@ -0,0 +1,54 @@
// FE-PLANNER-BOOKINGEXPENSE-001 to -004: the expense wish of the booking and
// transport forms, desktop and phone alike.
import { act, renderHook } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { buildBudgetItem } from '../../../tests/helpers/factories';
import { useBookingExpenseIntent } from './useBookingExpenseIntent';
describe('useBookingExpenseIntent', () => {
it('FE-PLANNER-BOOKINGEXPENSE-001: create notes the wish before the save it starts reads it', () => {
const seen: unknown[] = [];
const { result } = renderHook(() =>
useBookingExpenseIntent(async () => {
seen.push(result.current.take());
})
);
act(() => result.current.create());
expect(seen).toEqual([{ create: true }]);
expect(result.current.take()).toBeNull();
});
it('FE-PLANNER-BOOKINGEXPENSE-002: edit saves first with the linked item, and reset forgets an old wish', () => {
const submit = vi.fn(async () => undefined);
const item = buildBudgetItem({ id: 7 });
const { result } = renderHook(() => useBookingExpenseIntent(submit));
act(() => result.current.edit(item));
expect(submit).toHaveBeenCalledTimes(1);
expect(result.current.take()).toEqual({ editItem: item });
expect(result.current.take()).toBeNull();
act(() => result.current.create());
result.current.reset();
expect(result.current.take()).toBeNull();
});
it('FE-PLANNER-BOOKINGEXPENSE-003: remove deletes the linked expense and reports a failure', async () => {
const remove = vi.fn().mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error('nope'));
const onError = vi.fn();
const item = buildBudgetItem({ id: 3 });
const { result } = renderHook(() => useBookingExpenseIntent(async () => undefined, { remove, onError }));
await result.current.remove(item);
expect(remove).toHaveBeenCalledWith(item);
expect(onError).not.toHaveBeenCalled();
await result.current.remove(item);
expect(onError).toHaveBeenCalledTimes(1);
});
it('FE-PLANNER-BOOKINGEXPENSE-004: without a removal, as on the phone, remove does nothing', async () => {
const submit = vi.fn(async () => undefined);
const { result } = renderHook(() => useBookingExpenseIntent(submit));
await expect(result.current.remove(buildBudgetItem())).resolves.toBeUndefined();
expect(submit).not.toHaveBeenCalled();
});
});