fix(tests): update code action tests for the interactive apply path (#638)

applyCodeAction now resolves the picked action and executes it (lspResolveCodeAction → lspExecuteCodeAction) instead of calling lspApplyCodeAction, but refactorThis.test.ts and runKind.test.ts still mocked and asserted the old command, so main's frontend tests failed (4 tests). The mocks now follow the new commands; safeDelete.test.ts's negative assertion still holds.

Co-authored-by: a-rookie-of-C-language <[email protected]>
Цей коміт міститься в:
arookieofcтаa-rookie-of-C-language authored and GitHub committed 2026-11-01 11:16:44 +08:00
1 джерело 16033c481b
коміт fa26ba842c
2 files changed
+19 -9

No files matched your search

+8 -5
Переглянути файл
@@ -14,9 +14,11 @@ const lspCodeActionQuery = vi.fn(async (request: number, _doc: number, _range: u
);
const lspPrepareRename = vi.fn(async () => prepare);
let onApply: (() => void) | null = null;
const lspApplyCodeAction = vi.fn(async () => {
// applyCodeAction resolves the picked action, then executes it (interactive command support).
const lspResolveCodeAction = vi.fn(async (_doc: number, action: CodeAction) => ok(action));
const lspExecuteCodeAction = vi.fn(async () => {
onApply?.();
return ok(null);
return ok([]);
});
const lspCodeActions = vi.fn(async () => ok([]));
const cancelRequest = vi.fn(async () => undefined);
@@ -31,7 +33,8 @@ vi.mock("@/platform/ipc", async (orig) => {
...actual.commands,
lspCodeActionQuery,
lspPrepareRename,
lspApplyCodeAction,
lspResolveCodeAction,
lspExecuteCodeAction,
lspCodeActions,
cancelRequest,
languages,
@@ -185,7 +188,7 @@ describe("Refactor This", () => {
const items = (useLspPopup.getState().popup as { items: { label: string; run: () => void }[] }).items;
items.find((i) => i.label === "Inline…")!.run();
await new Promise((r) => setTimeout(r, 0));
expect(lspApplyCodeAction).toHaveBeenCalledOnce();
expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
items.find((i) => i.label === "Rename…")!.run();
expect(rename).toHaveBeenCalledWith(v);
items.find((i) => i.label === "Safe Delete…")!.run();
@@ -240,7 +243,7 @@ describe("Refactor menu actions", () => {
it("apply the single matching action, or offer a choice", async () => {
query = answer([action("Move to a new file", "refactor.move.newFile")]);
await runRefactoring(editor(), "move");
expect(lspApplyCodeAction).toHaveBeenCalledOnce();
expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
expect(lspCodeActionQuery.mock.calls[0]![3]).toEqual(["refactor.move"]);
closePopup();
+11 -4
Переглянути файл
@@ -5,11 +5,17 @@ import type { CodeAction } from "@/bindings";
let answer: () => unknown = () => ({ status: "ok", data: [] });
const lspCodeActions = vi.fn(async () => answer());
const lspApplyCodeAction = vi.fn(async () => ({ status: "ok", data: null }));
// applyCodeAction resolves the picked action, then executes it (interactive command support).
const lspResolveCodeAction = vi.fn(async (_doc: number, action: CodeAction) => ({ status: "ok", data: action }));
const lspExecuteCodeAction = vi.fn(async () => ({ status: "ok", data: [] }));
vi.mock("@/platform/ipc", async (orig) => {
const actual = await orig<typeof import("@/platform/ipc")>();
return { ...actual, isTauri: () => true, commands: { ...actual.commands, lspCodeActions, lspApplyCodeAction } };
return {
...actual,
isTauri: () => true,
commands: { ...actual.commands, lspCodeActions, lspResolveCodeAction, lspExecuteCodeAction },
};
});
const showHint = vi.fn();
vi.mock("@/editor/lsp/hint", () => ({ showHint }));
@@ -32,7 +38,8 @@ let view: EditorView | null = null;
afterEach(() => {
view?.destroy();
showHint.mockClear();
lspApplyCodeAction.mockClear();
lspResolveCodeAction.mockClear();
lspExecuteCodeAction.mockClear();
});
function run(fallback: (reason: "notReady" | "error" | "empty") => Promise<boolean>) {
@@ -56,7 +63,7 @@ describe("runKindAction fallback", () => {
const fallback = vi.fn(async () => true);
await run(fallback);
expect(fallback).not.toHaveBeenCalled();
expect(lspApplyCodeAction).toHaveBeenCalledOnce();
expect(lspExecuteCodeAction).toHaveBeenCalledOnce();
});
it("falls back when the server is not ready or fails", async () => {