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

test("Inline triple backticks preserve distinguishing file folders and thread search", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("repo", {
    "a/shared.ts": "export const a = 1;\n",
    "b/shared.ts": "export const b = 2;\n",
  });
  const thread = await t3.thread({
    project,
    title: "Inline fence file labels",
    messages: [
      "Use `` ``` `` to open a fence, then edit `./a/shared.ts` and `./b/shared.ts`",
      "Control: edit `./a/shared.ts` and `./b/shared.ts`",
    ],
  });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent Use/).tap();
  await screen.getByRole("button", /^Agent Control/).tap();
  await app.screenshot("inline-fence-folder-labels");
  await browser.keyboard.press("Control+f");
  await screen.getByRole("searchbox", "Find in thread").fill("repo/a");
  try {
    await expect.poll(() => browser.evaluate(() => ({
      messages: Array.from(document.querySelectorAll("[data-user-message-body]")).map((node) => node.textContent),
      matches: document.querySelector("[data-thread-find-bar] span[aria-hidden]")?.textContent,
    })), { message: "Both messages display repo/a and repo/b, and Find matches both" }).toEqual({
      messages: [
        "Use ``` to open a fence, then edit shared.ts · repo/a and shared.ts · repo/b",
        "Control: edit shared.ts · repo/a and shared.ts · repo/b",
      ],
      matches: "1/2",
    });
  } finally {
    await app.screenshot("folder-find-result");
  }
});
