import { cleanup, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, expect, it, vi } from "vitest"; import { dismissMapNotice, showMapNotice } from "@/features/map/core"; import { NoticeDevTools } from "./notice-dev-tools"; vi.mock("@/features/map/core", () => ({ showMapNotice: vi.fn(), dismissMapNotice: vi.fn() })); afterEach(() => { cleanup(); vi.clearAllMocks(); }); it("previews every tone, completes loading in place and clears only its own notices", async () => { render(); const user = userEvent.setup(); for (const label of ["信息", "成功", "警告", "错误", "加载"]) { await user.click(screen.getByRole("button", { name: `测试${label}通知` })); } expect(vi.mocked(showMapNotice).mock.calls.map(([options]) => options.tone)).toEqual(["info", "success", "warning", "error", "loading"]); await user.click(screen.getByRole("button", { name: "模拟加载完成" })); expect(showMapNotice).toHaveBeenLastCalledWith(expect.objectContaining({ id: "dev-notice:loading", tone: "success" })); await user.click(screen.getByRole("button", { name: "测试报告通知" })); const report = vi.mocked(showMapNotice).mock.lastCall![0]; expect(report.actionLabel).toBe("查看报告"); await user.click(screen.getByRole("button", { name: "连续 6 条通知" })); expect(vi.mocked(showMapNotice).mock.calls.slice(-6).map(([options]) => options.id)).toEqual( Array.from({ length: 6 }, (_, index) => `dev-notice:batch-${index}`) ); await user.click(screen.getByRole("button", { name: "清除测试通知" })); expect(vi.mocked(dismissMapNotice).mock.calls.every(([id]) => typeof id === "string" && id.startsWith("dev-notice:"))).toBe(true); });