mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
Usage previews rendered the matched occurrence through tokenSpans, so the token colour rules outranked the inherited --fg-search-match and left syntax colours on the search-match background (about 1.1:1 in Islands Light). Render the match as plain text so it takes the search-match foreground; syntax colours stay on the surrounding code. Covered by unit tests and a Playwright contrast check across light, dark, high-contrast and mixed editor schemes. Fixes #851 Co-authored-by: kkMihai <[email protected]>
61 lines
2.5 KiB
TypeScript
61 lines
2.5 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 });
|
|
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("toolbar", { name: "Usage access filters" })).toBeNull();
|
|
view.unmount();
|
|
useUsageAccessOptions.setState({ read: true, write: true });
|
|
useUsages.setState({ tabs: [], active: null });
|
|
});
|