Files
TREK/client/src/components/Budget/useExpenseDeleteConfirm.test.tsx
T
Maurice 31859651d7 feat(help): rewrite the help center for v5 with a Tours section, new pictures in every language, and fix the tour planner bugs it surfaced
Every help screen checked against the v5 redesign. Tours is documented for
the first time, as a screen of its own with twelve screens under it, and
notifications get help of their own. All pictures are taken again on a
realistic demo trip, with short loops where a still cannot show the motion.
The English is plain and every language is written naturally rather than
word for word.

The switcher shows two levels at most, a screen's overview lists its
sub-screens as cards above its guides, each wiki page is linked once, and
the help sidebar is wider.

Fixes found along the way: Save to Collection keeps a tour's route, a track
dropped on the places column opens the Tours import, tour Share on desktop,
the unsaved tour draft lives on the account, a route click no longer adds
an end point, Trip places leaves the trip's tours out, Escape closes a
stage's day menu, confirms before destructive deletes, DWD warnings sharing
one id kept apart, a booking's date moves with it, and smaller fixes across
notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and
the admin screens.
2026-10-22 22:29:35 +02:00

64 lines
2.6 KiB
TypeScript

import { buildBudgetItem } from '../../../tests/helpers/factories';
import { fireEvent, render, screen } from '../../../tests/helpers/render';
import type { BudgetItem } from '../../types';
import { useExpenseDeleteConfirm } from './useExpenseDeleteConfirm';
const item = (over: Partial<BudgetItem>): BudgetItem => ({ ...buildBudgetItem({ trip_id: 1 }), ...over }) as BudgetItem;
const taxi = item({ id: 7, name: 'Taxi', receipts: [] });
const hotel = item({ id: 8, name: 'Hotel', receipts: [{ id: 1 }] as unknown as BudgetItem['receipts'] });
// The harness drives the hook through buttons, so no handle leaks out of render.
function Harness({ onDelete }: { onDelete: (id: number) => Promise<unknown> }) {
const { ask, askById, dialog } = useExpenseDeleteConfirm([taxi, hotel], onDelete);
return (
<>
<button onClick={() => ask(taxi)}>ask taxi</button>
<button onClick={() => askById(8)}>ask hotel</button>
<button onClick={() => askById(999)}>ask unknown</button>
{dialog}
</>
);
}
const press = (name: string) => fireEvent.click(screen.getByRole('button', { name }));
describe('useExpenseDeleteConfirm', () => {
it('asks first and deletes only once the dialog is confirmed', () => {
const onDelete = vi.fn(() => Promise.resolve());
render(<Harness onDelete={onDelete} />);
expect(screen.queryByText('Delete expense?')).not.toBeInTheDocument();
press('ask taxi');
expect(screen.getByText('Delete expense?')).toBeInTheDocument();
expect(screen.getByText('"Taxi" will be permanently deleted.')).toBeInTheDocument();
expect(onDelete).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
expect(onDelete).toHaveBeenCalledWith(7);
expect(screen.queryByText('Delete expense?')).not.toBeInTheDocument();
});
it('looks a row up by its id and says the receipt files stay', () => {
render(<Harness onDelete={vi.fn(() => Promise.resolve())} />);
press('ask hotel');
expect(
screen.getByText('"Hotel" will be permanently deleted. Its receipt files stay in Files.')
).toBeInTheDocument();
});
it('sends nothing when the dialog is cancelled or the id is unknown', () => {
const onDelete = vi.fn(() => Promise.resolve());
render(<Harness onDelete={onDelete} />);
press('ask taxi');
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(screen.queryByText('Delete expense?')).not.toBeInTheDocument();
press('ask unknown');
expect(screen.queryByText('Delete expense?')).not.toBeInTheDocument();
expect(onDelete).not.toHaveBeenCalled();
});
});