Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
183 lines
8.6 KiB
TypeScript
183 lines
8.6 KiB
TypeScript
import { useState } from "react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { DateRangePicker, type DateRangeValue } from "./date-range-picker";
|
|
import { pickRange } from "@/test/pickDate";
|
|
|
|
function Harness({ initial = { from: "", to: "" }, onChange = vi.fn(), min, max, freshStart }: { initial?: DateRangeValue; onChange?: (r: DateRangeValue) => void; min?: string; max?: string; freshStart?: boolean }) {
|
|
const [value, setValue] = useState(initial);
|
|
return (
|
|
<>
|
|
<DateRangePicker fromLabel="Date from" toLabel="Date to" value={value} min={min} max={max} freshStart={freshStart}
|
|
onChange={(r) => { setValue(r); onChange(r); }} />
|
|
<button type="button" onClick={() => setValue({ from: "", to: "" })}>reset</button>
|
|
</>
|
|
);
|
|
}
|
|
|
|
describe("DateRangePicker", () => {
|
|
it("ignores typing in either box", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness onChange={onChange} />);
|
|
for (const label of ["Date from", "Date to"]) {
|
|
expect(screen.getByLabelText(label)).toHaveAttribute("readonly");
|
|
fireEvent.change(screen.getByLabelText(label), { target: { value: "01/09/2026" } });
|
|
expect(screen.getByLabelText(label)).toHaveValue("");
|
|
}
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("stays open when a box is clicked while the calendar is open", async () => {
|
|
const user = userEvent.setup();
|
|
render(<Harness />);
|
|
await user.click(screen.getByLabelText("Date from"));
|
|
await user.click(screen.getByLabelText("Date to"));
|
|
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
|
});
|
|
|
|
it("Clear reached from a box click empties the range", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-09-01", to: "2026-09-30" }} onChange={onChange} />);
|
|
fireEvent.click(screen.getByLabelText("Date to"));
|
|
fireEvent.click(screen.getByRole("button", { name: "Clear" }));
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "", to: "" });
|
|
});
|
|
|
|
it("keeps the From and To labels so existing queries work", () => {
|
|
render(<Harness />);
|
|
expect(screen.getByLabelText("Date from")).toBeInTheDocument();
|
|
expect(screen.getByLabelText("Date to")).toBeInTheDocument();
|
|
});
|
|
|
|
it("emits a range picked in the calendar", async () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-09-15", to: "" }} onChange={onChange} />);
|
|
await userEvent.click(screen.getByRole("button", { name: "Open calendar for Date from to Date to" }));
|
|
const dialog = screen.getByRole("dialog");
|
|
await userEvent.click(within(dialog).getByRole("button", { name: /September 1st, 2026/ }));
|
|
await userEvent.click(within(dialog).getByRole("button", { name: /September 30th, 2026/ }));
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-09-01", to: "2026-09-30" });
|
|
});
|
|
|
|
it("keeps a one-day range when its day is clicked again", async () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-09-15", to: "2026-09-15" }} onChange={onChange} />);
|
|
await userEvent.click(screen.getByRole("button", { name: "Open calendar for Date from to Date to" }));
|
|
await userEvent.click(within(screen.getByRole("dialog")).getByRole("button", { name: /September 15th, 2026/ }));
|
|
expect(onChange).not.toHaveBeenCalledWith({ from: "", to: "" });
|
|
expect(screen.getByLabelText("Date from")).toHaveValue("15/09/2026");
|
|
});
|
|
|
|
it("clears both boxes on an external reset", () => {
|
|
render(<Harness initial={{ from: "2026-09-01", to: "2026-09-30" }} />);
|
|
fireEvent.click(screen.getByText("reset"));
|
|
expect(screen.getByLabelText("Date from")).toHaveValue("");
|
|
expect(screen.getByLabelText("Date to")).toHaveValue("");
|
|
});
|
|
|
|
it("the To box opens the calendar when clicked", () => {
|
|
render(<Harness />);
|
|
fireEvent.click(screen.getByLabelText("Date to"));
|
|
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
|
});
|
|
|
|
it("picks a range through the helper", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness onChange={onChange} />);
|
|
pickRange("Date from", "2026-09-01", "2026-09-30");
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-09-01", to: "2026-09-30" });
|
|
});
|
|
|
|
it("Clear emits { from: \"\", to: \"\" }", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-09-01", to: "2026-09-30" }} onChange={onChange} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Open calendar for Date from to Date to" }));
|
|
fireEvent.click(screen.getByRole("button", { name: "Clear" }));
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "", to: "" });
|
|
});
|
|
});
|
|
|
|
// unify-admin-listing-toolbar: in a narrow row the 120px boxes used to shrink and cut "DD/MM/YYYY".
|
|
describe("DateRangePicker box width", () => {
|
|
it("never lets a date box shrink below its width", () => {
|
|
render(<Harness />);
|
|
for (const label of ["Date from", "Date to"]) {
|
|
expect(screen.getByLabelText(label)).toHaveClass("w-[120px]", "shrink-0");
|
|
}
|
|
});
|
|
});
|
|
|
|
// BABYBOO-39: Event Summary limits the range to the event's sales window.
|
|
describe("DateRangePicker min / max", () => {
|
|
const openCalendar = () => {
|
|
fireEvent.click(screen.getByRole("button", { name: "Open calendar for Date from to Date to" }));
|
|
return screen.getByRole("dialog");
|
|
};
|
|
|
|
it("disables days before min and after max", () => {
|
|
render(<Harness initial={{ from: "2026-10-14", to: "2026-10-14" }} min="2026-10-14" max="2026-10-17" />);
|
|
const dialog = openCalendar();
|
|
expect(within(dialog).getByRole("button", { name: /October 13th, 2026/ })).toBeDisabled();
|
|
expect(within(dialog).getByRole("button", { name: /October 18th, 2026/ })).toBeDisabled();
|
|
expect(within(dialog).getByRole("button", { name: /October 14th, 2026/ })).toBeEnabled();
|
|
expect(within(dialog).getByRole("button", { name: /October 17th, 2026/ })).toBeEnabled();
|
|
});
|
|
|
|
it("bounds the calendar's years to the window", () => {
|
|
render(<Harness initial={{ from: "2026-10-14", to: "" }} min="2026-10-14" max="2026-10-17" />);
|
|
const dialog = openCalendar();
|
|
const year = within(dialog).getAllByRole("combobox")[1];
|
|
expect(within(year).getAllByRole("option").map((o) => o.textContent)).toEqual(["2026"]);
|
|
});
|
|
|
|
it("picks a range inside the window and refuses a day outside it", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness onChange={onChange} min="2026-10-14" max="2026-10-17" />);
|
|
pickRange("Date from", "2026-10-14", "2026-10-16");
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-10-14", to: "2026-10-16" });
|
|
expect(() => pickRange("Date from", "2026-10-13", "2026-10-15")).toThrow(/2026-10-13 is not an enabled day/);
|
|
});
|
|
|
|
it("leaves every day enabled and the years open without min / max", () => {
|
|
render(<Harness initial={{ from: "2026-10-14", to: "" }} />);
|
|
const dialog = openCalendar();
|
|
expect(within(dialog).getByRole("button", { name: /October 1st, 2026/ })).toBeEnabled();
|
|
const year = within(dialog).getAllByRole("combobox")[1];
|
|
expect(within(year).getAllByRole("option")[0]).toHaveTextContent("1920");
|
|
});
|
|
});
|
|
|
|
// BABYBOO-39 review: Event Summary shows the server's default day, which is not a choice the next click extends.
|
|
describe("DateRangePicker freshStart", () => {
|
|
const clickDay = (iso: string) => {
|
|
const day = screen.getByRole("dialog").querySelector<HTMLButtonElement>(`[data-day="${iso}"] button`)!;
|
|
fireEvent.click(day);
|
|
};
|
|
|
|
it("starts a one-day range on the clicked day instead of extending the shown one", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-10-15", to: "2026-10-15" }} onChange={onChange} freshStart />);
|
|
fireEvent.click(screen.getByLabelText("Date from"));
|
|
clickDay("2026-10-20");
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-10-20", to: "2026-10-20" });
|
|
});
|
|
|
|
it("picks the shown day itself as a one-day range", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-10-15", to: "2026-10-15" }} onChange={onChange} freshStart />);
|
|
fireEvent.click(screen.getByLabelText("Date from"));
|
|
clickDay("2026-10-15");
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-10-15", to: "2026-10-15" });
|
|
});
|
|
|
|
it("without freshStart a click extends the shown one-day range", () => {
|
|
const onChange = vi.fn();
|
|
render(<Harness initial={{ from: "2026-10-15", to: "2026-10-15" }} onChange={onChange} />);
|
|
fireEvent.click(screen.getByLabelText("Date from"));
|
|
clickDay("2026-10-20");
|
|
expect(onChange).toHaveBeenLastCalledWith({ from: "2026-10-15", to: "2026-10-20" });
|
|
});
|
|
});
|