Файли
openidea/src/ui/SourcePreview.test.tsx
T
l0ng-ai eaca68f263 test: retry first edit-path calls and wait for effects in flaky tests (#1271)
A provider call that starts a plugin instance (or reads files) can run past
the edit-path soft deadline on a slow runner and returns nothing; the tests
now ask again, as the editor does. The AI completion test cancels the slow
request only once the server has it, and measures from the cancel. The
SourcePreview test waits for the effect that marks the selection scope.

Closes #1269
2026-11-04 21:07:03 +08:00

31 рядки
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { render, screen, waitFor } 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.
// Set by an effect, which can run after the text is on screen.
await waitFor(() => expect(container.querySelector("[data-selection-scope]")).toBeTruthy());
});
});