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

test("Image-wrapped file links retain distinct folder labels", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("repo", { "src/index.ts": "export const a = 1;\n", "lib/index.ts": "export const b = 2;\n" });
  const thread = await t3.thread({ project, title: "Image file links", messages: ["Start"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.fill("[![a](https://example.com/a.png)](src/index.ts) [![b](https://example.com/b.png)](lib/index.ts)");
  await composer.press("Enter");
  await screen.getByText("second fixture turn complete", { exact: false }).waitFor();
  await app.screenshot("image-wrapped-file-labels");
  const labels = await browser.evaluate(() => [...document.querySelectorAll("[data-user-message-body] a")].map(a => a.textContent));
  await browser.keyboard.press("Control+f");
  await screen.getByRole("searchbox", "Find in thread").fill("repo/src");
  try {
    await expect.poll(() => browser.evaluate<string>('document.querySelector("[data-thread-find-bar] span[aria-hidden]")?.textContent ?? ""')).toBe("1/1");
  } finally {
    await app.screenshot("folder-label-search");
  }
  expect(labels).toContain("index.ts · repo/src");
  expect(labels).toContain("index.ts · repo/lib");
});
