fix: close file picker on outside click and modal dismiss

This commit is contained in:
Luffy
2026-09-09 16:42:26 +08:00
committed by Maurice
parent 41b18f970c
commit e8431d6426
4 changed files with 90 additions and 4 deletions
@@ -1,4 +1,4 @@
// FE-PLANNER-RESMODAL-001 to FE-PLANNER-RESMODAL-093
// FE-PLANNER-RESMODAL-001 to FE-PLANNER-RESMODAL-095
import { render, screen, waitFor, fireEvent, within } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
@@ -558,6 +558,35 @@ describe('ReservationModal', () => {
});
});
it('FE-PLANNER-RESMODAL-094: an outside pointer closes the file picker while an inside pointer keeps it open', async () => {
const res = buildReservation({ id: 5 });
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
render(<ReservationModal {...defaultProps} reservation={res} files={[unattachedFile]} />);
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
const pickerItem = screen.getByText('invoice.pdf');
fireEvent.pointerDown(pickerItem);
expect(screen.getByText('invoice.pdf')).toBeInTheDocument();
fireEvent.pointerDown(document.body);
expect(screen.queryByText('invoice.pdf')).not.toBeInTheDocument();
});
it('FE-PLANNER-RESMODAL-095: closing and reopening the modal resets the file picker', async () => {
const res = buildReservation({ id: 5 });
const unattachedFile = buildTripFile({ id: 99, original_name: 'invoice.pdf' });
const { rerender } = render(<ReservationModal {...defaultProps} reservation={res} files={[unattachedFile]} />);
await userEvent.click(screen.getByRole('button', { name: /Link existing file/i }));
expect(screen.getByText('invoice.pdf')).toBeInTheDocument();
rerender(<ReservationModal {...defaultProps} isOpen={false} reservation={res} files={[unattachedFile]} />);
rerender(<ReservationModal {...defaultProps} reservation={res} files={[unattachedFile]} />);
expect(screen.queryByText('invoice.pdf')).not.toBeInTheDocument();
});
it('FE-PLANNER-RESMODAL-040: removing pending file removes it from list', async () => {
render(<ReservationModal {...defaultProps} reservation={null} />);