mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
feat(dayplan): a day can be deleted from the reorder dialog, after a warning that says what goes with it
Every row of the reorder dialog, and of the days sheet on a phone, now has a delete button. It first asks, and the question lists what goes with the day: planned places stay in the place list, notes and day texts are deleted, bookings stay without a day, a stay that checks in or out on the day is cancelled with its booking and expense (shown in the danger tone), and on a dated trip the later days and their bookings move one date earlier or the trip ends a day earlier. The server side moved from a bare DELETE into DayRemovalService, which REST, the delete_day tool and the plugin RPC all use. It closes the numbering, keeps the dates on their positions like a reorder, re-stamps the moved bookings, shifts the road trip boundaries, cancels touching stays through the accommodations domain, refuses the last day of a trip, and fans out day:deleted, day:reordered and trip:updated so collaborators renumber and see the new day count and end date. The trip query moved into a leaf file so the days domain can read it without a module cycle. On the client the delete is online only, runs optimistically through the days slice with the same reducer collaborators apply, and the ConfirmDialog gained a slot for extra content, an Escape that only closes itself, and the danger and accent tokens.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { render, screen, fireEvent } from '../../../tests/helpers/render';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import ConfirmDialog from './ConfirmDialog';
|
||||
import Modal from './Modal';
|
||||
|
||||
describe('ConfirmDialog', () => {
|
||||
const onClose = vi.fn();
|
||||
@@ -91,6 +92,44 @@ describe('ConfirmDialog', () => {
|
||||
process.off('unhandledRejection', unhandled);
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-010: extra content renders under the message, and the card widens for it', () => {
|
||||
render(
|
||||
<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} message="Delete it?">
|
||||
<ul aria-label="consequences"><li>Stay at Harbour Hotel</li></ul>
|
||||
</ConfirmDialog>
|
||||
);
|
||||
const list = screen.getByRole('list', { name: 'consequences' });
|
||||
expect(list).toHaveTextContent('Stay at Harbour Hotel');
|
||||
expect(screen.getByText('Delete it?').compareDocumentPosition(list) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(document.querySelector('.max-w-md')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-011: Escape takes back the question only, not the dialog it was asked from', () => {
|
||||
const closeModal = vi.fn();
|
||||
render(
|
||||
<>
|
||||
<Modal isOpen={true} onClose={closeModal} title="Reorder days">rows</Modal>
|
||||
<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} message="Delete it?" />
|
||||
</>
|
||||
);
|
||||
fireEvent.keyDown(document.body, { key: 'Escape' });
|
||||
expect(onClose).toHaveBeenCalledOnce();
|
||||
expect(closeModal).not.toHaveBeenCalled();
|
||||
// Other keys pass through untouched.
|
||||
fireEvent.keyDown(document.body, { key: 'Enter' });
|
||||
expect(onClose).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-012: the danger look comes from the danger tokens, the plain one from the accent', () => {
|
||||
const { unmount } = render(<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} />);
|
||||
expect(screen.getByRole('button', { name: /delete/i })).toHaveClass('bg-danger');
|
||||
expect(document.querySelector('.bg-danger-soft')).not.toBeNull();
|
||||
unmount();
|
||||
render(<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} danger={false} confirmLabel="Keep" />);
|
||||
expect(screen.getByRole('button', { name: 'Keep' })).toHaveClass('bg-accent', 'text-accent-text');
|
||||
expect(document.querySelector('.bg-danger-soft')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-COMP-CONFIRM-008: clicking backdrop calls onClose', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<ConfirmDialog isOpen={true} onClose={onClose} onConfirm={onConfirm} message="msg" />);
|
||||
|
||||
Reference in New Issue
Block a user