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
115 lines
4.0 KiB
TypeScript
115 lines
4.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
import DobPicker from "./DobPicker";
|
|
|
|
const click = (name: string) => fireEvent.click(screen.getByRole("button", { name }));
|
|
const dialog = (name: string) => screen.getByRole("dialog", { name });
|
|
|
|
function open(value = "") {
|
|
const onChange = vi.fn();
|
|
render(<DobPicker value={value} onChange={onChange} />);
|
|
fireEvent.click(screen.getByRole("button", { name: /Select your date of birth|10 May 1990/ }));
|
|
return onChange;
|
|
}
|
|
|
|
describe("DobPicker", () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers({ toFake: ["Date"] });
|
|
vi.setSystemTime(new Date("2026-11-06T12:00:00"));
|
|
});
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("shows the placeholder when empty", () => {
|
|
render(<DobPicker value="" onChange={vi.fn()} />);
|
|
expect(screen.getByRole("button", { name: "Select your date of birth" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the date as day, full month, year", () => {
|
|
render(<DobPicker value="1990-05-10" onChange={vi.fn()} />);
|
|
expect(screen.getByRole("button", { name: "10 May 1990" })).toHaveAttribute("aria-haspopup", "dialog");
|
|
});
|
|
|
|
it("titles the three steps in order", () => {
|
|
open();
|
|
expect(dialog("Choose your birth year")).toHaveAttribute("aria-modal", "true");
|
|
click("1990");
|
|
expect(dialog("Choose your birth month")).toBeInTheDocument();
|
|
click("May");
|
|
expect(dialog("Choose your birth day")).toBeInTheDocument();
|
|
});
|
|
|
|
it("emits YYYY-MM-DD for year, month, day and closes", async () => {
|
|
const onChange = open();
|
|
click("1990");
|
|
click("May");
|
|
click("10");
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
expect(onChange).toHaveBeenCalledWith("1990-05-10");
|
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
|
});
|
|
|
|
it("Back from month step returns to year step", () => {
|
|
open();
|
|
click("1990");
|
|
click("Back");
|
|
expect(dialog("Choose your birth year")).toBeInTheDocument();
|
|
});
|
|
|
|
it("Back from day step returns to month step", () => {
|
|
open();
|
|
click("1990");
|
|
click("May");
|
|
click("Back");
|
|
expect(dialog("Choose your birth month")).toBeInTheDocument();
|
|
});
|
|
|
|
it("Cancel closes without calling onChange", async () => {
|
|
const onChange = open();
|
|
click("1990");
|
|
click("Cancel");
|
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("Escape closes without calling onChange", async () => {
|
|
const onChange = open();
|
|
fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" });
|
|
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("offers no year after the 18-year cutoff and none before 107 years ago", () => {
|
|
open();
|
|
expect(screen.queryByRole("button", { name: "2009" })).not.toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "2008" })).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: "1919" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "1918" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("disables days after the cutoff day in the cutoff month", () => {
|
|
open();
|
|
click("2008");
|
|
click("November");
|
|
expect(screen.getByRole("button", { name: "7" })).toBeDisabled();
|
|
expect(screen.getByRole("button", { name: "6" })).toBeEnabled();
|
|
});
|
|
|
|
it("offers 29 days for Feb 2000", () => {
|
|
open();
|
|
click("2000");
|
|
click("February");
|
|
expect(screen.getByRole("button", { name: "29" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "30" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("offers 28 days for Feb 1990", () => {
|
|
open();
|
|
click("1990");
|
|
click("February");
|
|
expect(screen.getByRole("button", { name: "28" })).toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "29" })).not.toBeInTheDocument();
|
|
});
|
|
});
|