Files
openidea/src/ui/SourcePreview.test.tsx
T
Qingandqtvbwfn e5718d41d8 feat(ui): make preview panes selectable and copyable (#1127)
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>
2026-11-04 08:54:25 +08:00

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();
});
});