/// <reference lib="dom" />
import { expect } from "e2e";
import { T3_HOME } from "../e2e.config.ts";
import { makeState, runPromise, test, WEB } from "./t3.ts";

test("File citation keeps its size after workspace search", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project(`../../../../../../../../tmp/factory-pr-39012-evidence-1/run-${Date.now()}/quarterly-report`, { "quarterly-figures.md": "x".repeat(2048) });
  await runPromise(makeState(T3_HOME).cli(["project", "rename", project, "Quarterly report"]));
  const thread = await t3.thread({ project, title: "Quarterly report", messages: ["Please review [quarterly-figures.md](quarterly-figures.md)."] });
  await t3.open(thread);
  await screen.getByRole("textbox").fill("@quarterly-figures.md");
  await screen.getByRole("option", "quarterly-figures.md", { exact: false }).waitFor();
  await browser.keyboard.press("Escape");
  await screen.getByRole("button", /^Agent Please review/).tap();
  await screen.getByRole("link", "quarterly-figures.md", { exact: false }).hover();
  await browser.locator('[data-slot="tooltip-popup"]').waitFor();
  await browser.evaluate(async () => {
    await Promise.all(document.getAnimations().map((animation) => animation.finished.catch(() => {})));
    return null;
  });
  await app.screenshot("file-tooltip");
  await expect(browser.locator('[data-slot="tooltip-popup"]')).toContainText("2 KB");
});
