mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
fix(planner): an imported booking with source files saves and opens its expense without file support
Saving an imported booking in the desktop booking dialog when the dialog had no upload handler but the import carried source files rejected the save: the files were handed to the missing handler, the promise rejected with nothing to catch it, and the expense editor the user asked for never opened. The transport dialog already skipped the upload in that case, the booking dialog did not. The shared uploadBookingFiles helper now takes an optional handler and does nothing without one, so every form gets the same guard. Red test: FE-PLANNER-RESMODAL-106 in client/src/components/Planner/ReservationModal.test.tsx failed with "expected spy to be called with arguments" for onOpenExpense, plus the unhandled rejection "TypeError: upload is not a function". The helper case is covered by FE-PLANNER-BOOKINGFORM-008. No existing assertions changed.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-PLANNER-RESMODAL-001 to FE-PLANNER-RESMODAL-105
|
||||
// FE-PLANNER-RESMODAL-001 to FE-PLANNER-RESMODAL-106
|
||||
import { render, screen, waitFor, fireEvent, within, act } from '../../../tests/helpers/render';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
@@ -1409,6 +1409,38 @@ describe('ReservationModal', () => {
|
||||
expect(onSave.mock.calls[0][0].create_budget_entry).toEqual({ total_price: 50, category: 'accommodation' });
|
||||
});
|
||||
|
||||
it('FE-PLANNER-RESMODAL-106: an import with source files but no upload handler still saves and opens the expense editor', async () => {
|
||||
// Without onFileUpload the pending source files cannot go anywhere; the save
|
||||
// used to call the missing handler, reject, and never reach the expense step.
|
||||
budgetEnabled();
|
||||
const onSave = vi.fn().mockResolvedValue({ id: 84 });
|
||||
const onOpenExpense = vi.fn();
|
||||
const prefill = hotelPrefill({
|
||||
type: 'restaurant',
|
||||
metadata: {},
|
||||
_accommodation: undefined,
|
||||
_sourceFiles: [new File(['pdf'], 'voucher.pdf', { type: 'application/pdf' })],
|
||||
});
|
||||
render(
|
||||
<ReservationModal
|
||||
{...defaultProps}
|
||||
onFileUpload={undefined}
|
||||
onSave={onSave}
|
||||
onOpenExpense={onOpenExpense}
|
||||
prefill={prefill}
|
||||
days={reviewDays()}
|
||||
/>
|
||||
);
|
||||
|
||||
await userEvent.click(screen.getByRole('button', { name: /Create expense/i }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
||||
await waitFor(() =>
|
||||
expect(onOpenExpense).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ prefill: expect.objectContaining({ reservationId: 84 }) })
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// ── File error paths ────────────────────────────────────────────────────────
|
||||
|
||||
it('FE-PLANNER-RESMODAL-077: a cancelled file dialog changes nothing', () => {
|
||||
|
||||
Reference in New Issue
Block a user