Adds react-day-picker 10.0.1 (it brings date-fns). The portal bans native date inputs, and the events and leads forms need a date field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { fireEvent, screen, within } from "@testing-library/react";
|
||
|
||
function topPopover() {
|
||
const dialogs = screen.getAllByRole("dialog");
|
||
return dialogs[dialogs.length - 1];
|
||
}
|
||
|
||
/** Shows `iso`'s month in the popover's first calendar month and clicks the day. */
|
||
function clickDay(pop: HTMLElement, iso: string) {
|
||
const [month, year] = within(pop).getAllByRole("combobox");
|
||
const [y, m] = iso.split("-").map(Number);
|
||
fireEvent.change(year, { target: { value: String(y) } });
|
||
fireEvent.change(month, { target: { value: String(m - 1) } });
|
||
const day = pop.querySelector<HTMLButtonElement>(`[data-day="${iso}"] button`);
|
||
// A disabled day ignores the click, so fail loudly instead of letting the test pass vacuously.
|
||
if (!day || day.disabled) throw new Error(`pickDate: ${iso} is not an enabled day in the calendar`);
|
||
fireEvent.click(day);
|
||
}
|
||
|
||
/** Picks `iso` (yyyy-MM-dd) in the calendar of the date box labelled `label`. */
|
||
export function pickDate(label: string | RegExp | HTMLElement, iso: string) {
|
||
fireEvent.click(label instanceof HTMLElement ? label : screen.getByLabelText(label));
|
||
clickDay(topPopover(), iso);
|
||
}
|
||
|
||
/** Picks the range `from`–`to` in the calendar of the range box labelled `fromLabel`. */
|
||
export function pickRange(fromLabel: string | RegExp, from: string, to: string) {
|
||
fireEvent.click(screen.getByLabelText(fromLabel));
|
||
const pop = topPopover();
|
||
clickDay(pop, from);
|
||
clickDay(pop, to);
|
||
}
|