import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Whole-word search finds line 151 during content index warm-up", WEB, async ({ t3, app, browser, screen }) => {
  const files: Record<string, string> = {
    "a.ts": Array.from({ length: 150 }, (_, i) => `const needleSuffix${i + 1} = 1;`).join("\n") + "\nneedle();\n",
  };
  // A large real repository keeps the first content search on the git fallback.
  const filler = "export const filler = 1234567890;\n".repeat(2000);
  for (let i = 0; i < 12000; i++) files[`filler/file-${i}.ts`] = filler;
  const project = await t3.project("Whole word search", files);
  const thread = await t3.thread({ project, title: "Search warm-up", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("textbox", "Message Search warm-up").waitFor();
  await browser.keyboard.press("Control+Shift+f");
  await screen.getByRole("button", "Match whole word", { exact: true }).click();
  await screen.getByPlaceholder("Search in Whole word search").fill("needle");
  await screen.getByText(/results in .* files/).waitFor({ timeout: 120000 });
  await app.screenshot("whole-word-search");
  await expect(screen.getByText("needle();", { exact: true })).toBeVisible();
});
