дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
Show Usages and the Find tool window gain the Show Import Statements toggle next to the read/write access filters: a usage on a line that begins an import statement (import ..., from ... import ...) is hidden when it is off. The option defaults to on and persists with read/write; saved settings without it keep showing imports. The popup's Open in Find Tool Window is an icon button with its shortcut in the tooltip. The icon is vendored from intellij-community (Apache-2.0). Co-authored-by: chiyanking <[email protected]>
61 рядки
2.6 KiB
TypeScript
61 рядки
2.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
|
|
vi.mock(import("@/platform/ipc"), async (importOriginal) => ({
|
|
...(await importOriginal()),
|
|
commands: { fsReadText: (path: string) => path } as never,
|
|
call: (async () => "/**\n * Uses foo()\n */\n const x = foo();\n") as never,
|
|
}));
|
|
vi.mock(import("@/editor/api"), async (importOriginal) => ({ ...(await importOriginal()), editorsFor: () => [] }));
|
|
|
|
const { UsagePreview, UsagesView } = await import("./UsagesView");
|
|
|
|
describe("UsagePreview", () => {
|
|
it("colours the usage line with its file as context", async () => {
|
|
const { container } = render(
|
|
<UsagePreview usage={{ path: "/p/a.ts", line: 3, col: 12, endCol: 15, text: " const x = foo();" }} />,
|
|
);
|
|
await waitFor(() => expect(container.querySelector(".tok-keyword")?.textContent).toBe("const"));
|
|
expect(container.querySelector("mark")?.textContent).toBe("foo");
|
|
expect(container.querySelector("mark")?.childElementCount).toBe(0);
|
|
expect(container.textContent).toBe("const x = foo();");
|
|
});
|
|
|
|
it("keeps comment colours outside the match and the search foreground inside it", async () => {
|
|
const { container } = render(
|
|
<UsagePreview usage={{ path: "/p/a.ts", line: 1, col: 8, endCol: 11, text: " * Uses foo()" }} />,
|
|
);
|
|
await waitFor(() => expect(container.querySelector(".tok-comment")?.textContent).toBe("* Uses "));
|
|
expect(container.querySelector("mark")?.textContent).toBe("foo");
|
|
expect(container.querySelector("mark")?.childElementCount).toBe(0);
|
|
});
|
|
});
|
|
|
|
it("shows a plain count for unclassified searches after a Java access mode was selected", async () => {
|
|
const { useUsages } = await import("./usages");
|
|
const { useUsageAccessOptions } = await import("./UsageAccessFilter");
|
|
const rows = [0, 1].map((line) => ({ path: "/p/a.ts", line, col: 0, endCol: 3, text: "foo()" }));
|
|
useUsageAccessOptions.setState({ read: true, write: false, imports: true });
|
|
useUsages.setState({
|
|
tabs: [
|
|
{
|
|
id: 123,
|
|
symbol: "foo",
|
|
groups: [{ path: "/p/a.ts", usages: rows }],
|
|
loading: false,
|
|
error: null,
|
|
rerun: null,
|
|
note: null,
|
|
pinned: false,
|
|
},
|
|
],
|
|
active: 123,
|
|
});
|
|
const view = render(<UsagesView />);
|
|
expect(screen.getByText("2 results")).toBeInTheDocument();
|
|
expect(screen.queryByRole("group", { name: "Usage access filters" })).toBeNull();
|
|
view.unmount();
|
|
useUsageAccessOptions.setState({ read: true, write: true, imports: true });
|
|
useUsages.setState({ tabs: [], active: null });
|
|
});
|