feat(workbench): integrate runtime data and map tooling

This commit is contained in:
2026-09-22 10:45:46 +08:00
parent bf44cc0f25
commit bebcf2a06c
163 changed files with 15642 additions and 1312 deletions
+70
View File
@@ -0,0 +1,70 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { DateTimeField } from "@/shared/ui/date-time-field";
import "@/test/radix-select-test-setup";
describe("DateTimeField", () => {
it("does not change the controlled value when opening and cancelling", async () => {
const onChange = vi.fn();
const user = userEvent.setup();
render(<DateTimeField label="时窗开始" value="2026-09-17T08:00" onChange={onChange} />);
await user.click(screen.getByRole("button", { name: "时窗开始" }));
expect(screen.getByRole("dialog", { name: "选择时窗开始" })).toBeVisible();
await user.click(screen.getByRole("button", { name: "取消" }));
expect(onChange).not.toHaveBeenCalled();
expect(screen.getByRole("button", { name: "时窗开始" })).toHaveFocus();
});
it("emits a minute-precision local datetime only after confirmation", async () => {
const onChange = vi.fn();
const user = userEvent.setup();
render(<DateTimeField label="时窗开始" value="2024-02-28T09:30" onChange={onChange} />);
await user.click(screen.getByRole("button", { name: "时窗开始" }));
await user.click(screen.getByRole("gridcell", { name: "2024年2月29日" }));
expect(onChange).not.toHaveBeenCalled();
await user.click(screen.getByRole("button", { name: "确认" }));
expect(onChange).toHaveBeenCalledOnce();
expect(onChange).toHaveBeenCalledWith("2024-02-29T09:30");
});
it.each(["2025-02-29T12:00", "2024-04-31T12:00", "2024-02-29T12:00:30"])(
"rejects invalid or unexpected source value %s",
async (value) => {
const user = userEvent.setup();
render(<DateTimeField label="时窗开始" value={value} onChange={vi.fn()} />);
await user.click(screen.getByRole("button", { name: "时窗开始" }));
expect(screen.getByRole("alert")).toHaveTextContent("当前值格式无效");
expect(screen.getByRole("button", { name: "确认" })).toBeDisabled();
}
);
it("renders the correct leap-month day count", async () => {
const user = userEvent.setup();
render(<DateTimeField label="时窗开始" value="2024-02-01T00:00" onChange={vi.fn()} />);
await user.click(screen.getByRole("button", { name: "时窗开始" }));
expect(screen.getAllByRole("gridcell")).toHaveLength(29);
expect(screen.getByRole("gridcell", { name: "2024年2月29日" })).toBeVisible();
});
it("cannot open or confirm while disabled", async () => {
const onChange = vi.fn();
const user = userEvent.setup();
render(
<DateTimeField label="时窗开始" value="2026-09-17T08:00" onChange={onChange} disabled />
);
const trigger = screen.getByRole("button", { name: "时窗开始" });
expect(trigger).toBeDisabled();
await user.click(trigger);
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
expect(onChange).not.toHaveBeenCalled();
});
});