Файли
openidea/src/features/graphql/store.test.ts
T
Nguyen Thinh 3d7768f47f feat(window): graphql window (#1166)
Adds a GraphQL tool window: schema discovery from graphql-config files (or every GraphQL file without one), schema errors and endpoints, running the operation at the caret against a configured endpoint with ${NAME} environment variables, Query Result, and introspection into the schema file. The editor gets a GraphQL toolbar with endpoint selection, variables and run.

The tool window is listed on the stripe once used, so projects without GraphQL get no extra button.

Closes #1168

Co-authored-by: kidp2h <[email protected]>
2026-11-04 13:02:01 +08:00

39 рядки
1.6 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { _addEditor, _removeEditor, type TextEditorHandle } from "@/editor/api";
let onOpen: (path: string) => void = () => {};
const openFile = vi.fn(async (path: string) => onOpen(path));
vi.mock("@/workbench/contributions", async (orig) => {
const actual = await orig<typeof import("@/workbench/contributions")>();
return { ...actual, editorService: () => ({ openFile }) };
});
const { replaceFileText } = await import("./store");
function editorOf(path: string, text: string): TextEditorHandle {
const view = new EditorView({ state: EditorState.create({ doc: text }) });
return { view, ctx: { path } as TextEditorHandle["ctx"] };
}
describe("replaceFileText", () => {
it("replaces the text once the tab just opened has created its editor", async () => {
const editor = editorOf("/p/schema.graphql", "type Query { a: Int }");
// The tab mounts its editor after openFile resolves, as for a file that was not open.
onOpen = () => void setTimeout(() => _addEditor(editor), 10);
try {
expect(await replaceFileText("/p/schema.graphql", "type Query { b: Int }")).toBe(true);
expect(editor.view.state.doc.toString()).toBe("type Query { b: Int }");
} finally {
_removeEditor(editor);
editor.view.destroy();
}
});
it("reports when no editor shows the file", async () => {
onOpen = () => {};
expect(await replaceFileText("/p/missing.graphql", "x", 50)).toBe(false);
});
});