mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
The workbench disables selection globally, so the read-only preview panes beside result trees (TODO, Usages, Problems…) could not be selected or copied. The pane opts back in (user-select: text) and uses useSelectionBoundary so drags stay inside it; the line-number gutter stays unselectable so copied text is code only. Co-authored-by: qtvbwfn <5848026+qtvbwfn@users.noreply.github.com>
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { SourcePreview } from "./SourcePreview";
|
|
|
|
/** A stable loader reference (a new function reloads, like the real module-level ones). */
|
|
const loadOf = (content: string) => () => Promise.resolve(content);
|
|
|
|
describe("SourcePreview", () => {
|
|
it("renders the loaded lines around the current one", async () => {
|
|
const { container } = render(
|
|
<SourcePreview
|
|
path="/p/a.ts"
|
|
line={1}
|
|
load={loadOf("one\ntwo\nthree")}
|
|
highlights={[{ line: 1, ranges: [[0, 3]] }]}
|
|
/>,
|
|
);
|
|
await screen.findByText("two");
|
|
expect(container.querySelector('[data-line="1"] mark')?.textContent).toBe("two");
|
|
expect(container.querySelector('[data-line="0"]')?.textContent).toContain("one");
|
|
});
|
|
|
|
it("makes its text selectable as a selection boundary", async () => {
|
|
const { container } = render(<SourcePreview path="/p/a.ts" line={0} load={loadOf("// TODO")} />);
|
|
await screen.findByText("// TODO");
|
|
// The scroll pane is a selection scope: drags stay inside, text stays copyable.
|
|
expect(container.querySelector("[data-selection-scope]")).toBeTruthy();
|
|
});
|
|
});
|