mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +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:
@@ -6,7 +6,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
|
||||
import { resetAllStores } from '../../../helpers/store'
|
||||
import { fireEvent, render, screen } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-DAYSS-001 to FE-MOB-DAYSS-012
|
||||
// FE-MOB-DAYSS-001 to FE-MOB-DAYSS-015
|
||||
//
|
||||
// The sheet reads its copy from the real TranslationProvider (useTranslation),
|
||||
// not from planner.t — assertions therefore go against the English strings.
|
||||
@@ -120,4 +120,27 @@ describe('MDaysSheet', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
|
||||
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-MOB-DAYSS-013: each row asks the planner to delete its own day', () => {
|
||||
const { planner } = renderSheet()
|
||||
const buttons = screen.getAllByRole('button', { name: 'Delete day' })
|
||||
expect(buttons).toHaveLength(3)
|
||||
// Rows run in day_number order: the second one is day 2.
|
||||
fireEvent.click(buttons[1])
|
||||
expect(planner.handleDeleteDay).toHaveBeenCalledWith(2)
|
||||
})
|
||||
|
||||
it('FE-MOB-DAYSS-014: a read-only member gets no delete buttons', () => {
|
||||
renderSheet({ can: vi.fn(() => false) })
|
||||
expect(screen.queryByRole('button', { name: 'Delete day' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-DAYSS-015: while the planner blocks deleting, the buttons are off and the sheet says why', () => {
|
||||
const { planner } = renderSheet({ deleteDayBlocked: 'A trip needs at least one day' })
|
||||
const buttons = screen.getAllByRole('button', { name: 'Delete day' })
|
||||
expect(buttons.every(b => (b as HTMLButtonElement).disabled)).toBe(true)
|
||||
fireEvent.click(buttons[0])
|
||||
expect(planner.handleDeleteDay).not.toHaveBeenCalled()
|
||||
expect(screen.getByText('A trip needs at least one day')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { ReactNode } from 'react'
|
||||
import { BedDouble, MapPin } from 'lucide-react'
|
||||
import type { BookingExpenseRequest } from '../../../../src/components/Planner/BookingCostsSection.types'
|
||||
import type { ExpensePrefill } from '../../../../src/components/Budget/CostsPanel'
|
||||
import type { MTripShellApi, TripPlanner } from '../../../../src/mobile/screens/trip/MTripShell'
|
||||
@@ -11,7 +12,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
|
||||
import { resetAllStores, seedStore } from '../../../helpers/store'
|
||||
import { fireEvent, render, screen, waitFor } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-SHOST-001 to FE-MOB-SHOST-029
|
||||
// FE-MOB-SHOST-001 to FE-MOB-SHOST-030
|
||||
//
|
||||
// Every child sheet is stubbed: this file is about the host — which sheet is
|
||||
// mounted for which shell.sheet id, and how the host's own callbacks wire the
|
||||
@@ -101,12 +102,14 @@ vi.mock('../../../../src/mobile/screens/trip/sheets/MCostSheet', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('../../../../src/mobile/screens/settings/MConfirmSheet', () => ({
|
||||
default: ({ open, title, message, onClose, onConfirm }: {
|
||||
default: ({ open, title, message, onClose, onConfirm, danger, confirmLabel, children }: {
|
||||
open: boolean; title: string; message: ReactNode; onClose: () => void; onConfirm?: () => void
|
||||
danger?: boolean; confirmLabel?: string; children?: ReactNode
|
||||
}) =>
|
||||
open ? (
|
||||
<div data-testid="stub-confirm" data-title={title}>
|
||||
<div data-testid="stub-confirm" data-title={title} data-danger={String(!!danger)} data-confirm={confirmLabel}>
|
||||
<span>{message}</span>
|
||||
{children}
|
||||
<button type="button" onClick={onConfirm}>confirm delete</button>
|
||||
<button type="button" onClick={onClose}>cancel delete</button>
|
||||
</div>
|
||||
@@ -444,6 +447,28 @@ describe('MTripSheets', () => {
|
||||
expect(planner.setDeletePlaceId).toHaveBeenCalledWith(null)
|
||||
})
|
||||
|
||||
it('FE-MOB-SHOST-030: the delete-day confirm names the day, lists what goes with it and runs the planner confirmation', () => {
|
||||
const lines = [
|
||||
{ key: 'stay-9', icon: BedDouble, tone: 'danger' as const, text: 'Stay at Harbour Hotel', hint: 'Cancelled with its booking.' },
|
||||
{ key: 'places', icon: MapPin, tone: 'neutral' as const, text: 'Planned places: 2' },
|
||||
]
|
||||
const { planner } = renderHost({ deleteDayId: 12, deleteDayTitle: 'Delete Tue, Oct 13?', deleteDayLines: lines })
|
||||
|
||||
const confirm = screen.getByTestId('stub-confirm')
|
||||
expect(confirm).toHaveAttribute('data-title', 'Delete Tue, Oct 13?')
|
||||
expect(confirm).toHaveAttribute('data-danger', 'true')
|
||||
expect(confirm).toHaveAttribute('data-confirm', 'dayplan.deleteDay')
|
||||
expect(confirm).toHaveTextContent('dayplan.deleteDayBody')
|
||||
const list = screen.getByRole('list', { name: 'Delete Tue, Oct 13?' })
|
||||
expect(list).toHaveTextContent('Stay at Harbour Hotel')
|
||||
expect(list).toHaveTextContent('Planned places: 2')
|
||||
|
||||
fireEvent.click(screen.getByText('confirm delete'))
|
||||
expect(planner.confirmDeleteDay).toHaveBeenCalledTimes(1)
|
||||
fireEvent.click(screen.getByText('cancel delete'))
|
||||
expect(planner.setDeleteDayId).toHaveBeenCalledWith(null)
|
||||
})
|
||||
|
||||
it('FE-MOB-SHOST-027: the place edit sheet owns the confirm while its own form is open', () => {
|
||||
renderHost({ deletePlaceId: 101, showPlaceForm: true })
|
||||
expect(screen.queryByTestId('stub-confirm')).not.toBeInTheDocument()
|
||||
|
||||
@@ -78,6 +78,47 @@ describe('remoteEventHandler > days', () => {
|
||||
expect('20' in dayNotes).toBe(true);
|
||||
});
|
||||
|
||||
// A delete now closes the gap on the server and keeps the dates on their slots;
|
||||
// the collaborators run the same reducer the deleting tab ran optimistically.
|
||||
it('FE-WSEVT-DAY-014: day:deleted then day:reordered leaves the same numbering and dates as the server', () => {
|
||||
useTripStore.setState({
|
||||
trip: buildTrip({ id: 7 }),
|
||||
selectedDayId: 20,
|
||||
days: [
|
||||
buildDay({ id: 10, day_number: 1, date: '2026-06-01' }),
|
||||
buildDay({ id: 20, day_number: 2, date: '2026-06-02' }),
|
||||
buildDay({ id: 30, day_number: 3, date: '2026-06-03' }),
|
||||
buildDay({ id: 40, day_number: 4, date: null }),
|
||||
],
|
||||
refreshDays: vi.fn(async () => {}),
|
||||
loadReservations: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
useTripStore.getState().handleRemoteEvent({ type: 'day:deleted', dayId: 20 });
|
||||
const afterDelete = useTripStore.getState();
|
||||
expect(afterDelete.days.map(d => [d.id, d.day_number, d.date])).toEqual([
|
||||
[10, 1, '2026-06-01'], [30, 2, '2026-06-02'], [40, 3, '2026-06-03'],
|
||||
]);
|
||||
expect(afterDelete.selectedDayId).toBeNull();
|
||||
|
||||
useTripStore.getState().handleRemoteEvent({ type: 'day:reordered', orderedIds: [10, 30, 40] });
|
||||
expect(useTripStore.getState().days.map(d => [d.id, d.day_number])).toEqual([[10, 1], [30, 2], [40, 3]]);
|
||||
});
|
||||
|
||||
it('FE-WSEVT-DAY-015: day:deleted asks the planner to reload its stays, which a deleted day can cancel', () => {
|
||||
seedData();
|
||||
const refresh = vi.fn();
|
||||
window.addEventListener('accommodations:refresh', refresh);
|
||||
try {
|
||||
useTripStore.getState().handleRemoteEvent({ type: 'day:deleted', dayId: 10 });
|
||||
expect(refresh).toHaveBeenCalledTimes(1);
|
||||
useTripStore.getState().handleRemoteEvent({ type: 'day:updated', day: buildDay({ id: 20 }) });
|
||||
expect(refresh).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
window.removeEventListener('accommodations:refresh', refresh);
|
||||
}
|
||||
});
|
||||
|
||||
// The reorder is applied optimistically from orderedIds, then the authoritative
|
||||
// dates + re-stamped booking times are pulled (#589).
|
||||
describe('day:reordered', () => {
|
||||
|
||||
Reference in New Issue
Block a user