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

test("Content search marks omitted matches beyond the per-file cap", WEB, async ({ t3, app, screen, browser }) => {
  const files = (count: number) => ({
    "dense.ts": Array.from({ length: count }, (_, i) => `// searchneedle line ${i + 1}`).join("\n") + "\n",
    "other.ts": "// searchneedle\n",
  });
  const exact = await t3.project("exact100", files(100));
  const dense = await t3.project("searchproj", files(150));
  const controlThread = await t3.thread({ project: exact, title: "Exact count control", messages: ["Start"] });
  const denseThread = await t3.thread({ project: dense, title: "Per-file cap", messages: ["Start"] });
  await t3.open(controlThread);
  await screen.getByRole("textbox").click();
  await browser.keyboard.press("Control+Shift+f");
  await screen.getByPlaceholder("Search in exact100").fill("searchneedle");
  await screen.getByText("101 results in 2 files", { exact: true }).waitFor();
  await app.screenshot("exactly-100-matching-lines");
  await browser.keyboard.press("Escape");
  await t3.open(denseThread);
  await screen.getByRole("textbox").click();
  await browser.keyboard.press("Control+Shift+f");
  await screen.getByPlaceholder("Search in searchproj").fill("searchneedle");
  await screen.getByText(/^101\+? results in 2 files$/).waitFor();
  await app.screenshot("150-matching-lines");
  await expect(screen.getByText("101+ results in 2 files", { exact: true })).toBeVisible();
});
