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

test("A top-level colon filename becomes a chip and opens the exact file", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("colon-demo", {
    "reports:final.md": "Colon fixture\n",
    "notes.md": "plain\n",
  });
  const thread = await t3.thread({ project, title: "Review files", messages: ["Start"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("Review @reports");
  await screen.getByRole("option", "reports:final.md", { exact: false }).tap();
  await composer.pressSequentially(" and @notes");
  await screen.getByRole("option", "notes.md", { exact: false }).tap();
  await app.screenshot("draft-file-mentions");
  const draft = await composer.textContent();
  await browser.keyboard.press("Enter");
  const colon = browser.locator("a").getByText("reports:final.md", { exact: true });
  await colon.waitFor();
  await app.screenshot("sent-file-mentions");
  await colon.tap();
  await app.screenshot("after-clicking-colon-file");
  await expect.poll(() => browser.evaluate(() => {
    for (const host of document.querySelectorAll("*")) {
      const content = host.shadowRoot?.querySelector("[data-content]");
      if (content) return content.textContent ?? "";
    }
    return null;
  })).toContain("Colon fixture");
  await app.screenshot("colon-file-opened");
  expect(draft).not.toContain("[reports:final.md]");
});
