import { QueryClient } from "@tanstack/react-query"; import { afterEach, describe, expect, it, vi } from "vitest"; const state = vi.hoisted(() => ({ client: null as QueryClient | null, onSuccess: null as (() => void) | null })); vi.mock("@tanstack/react-query", async (original) => ({ ...(await original()), useQueryClient: () => state.client, useMutation: (options: { onSuccess: () => void }) => { state.onSuccess = options.onSuccess; return {}; }, })); import { useResolveDecision } from "./decisions.ts"; afterEach(() => { state.client?.clear(); state.client = null; state.onSuccess = null; }); describe("事项处理后的业务状态刷新", () => { it("指定作品或确认映射后,记录、统计、关注汇总和规则预览都会重新读取", () => { const client = new QueryClient(); state.client = client; const keys = [ ["decisions", "list"], ["identity", "entity"], ["records", "one", "record"], ["records", "list", { attention: true }], ["records", "stats", {}], ["attention"], ["episode-mapping", "words", "entity"], ["episode-mapping", "preview", "entity", {}], ]; for (const key of keys) client.setQueryData(key, { previous: true }); client.setQueryData(["settings"], { unrelated: true }); useResolveDecision(); state.onSuccess!(); for (const key of keys) expect(client.getQueryState(key)?.isInvalidated, JSON.stringify(key)).toBe(true); expect(client.getQueryState(["settings"])?.isInvalidated).toBe(false); }); });