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

test("Sent file mentions preserve paired backticks as one literal file chip", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("proj", { "src/a` b `.txt": "" });
  const thread = await t3.thread({ project, title: "File mention", messages: ["Show me around"], model: "default" });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("look at @a");
  await screen.getByRole("option", "a` b `.txt", { exact: false }).tap();
  await app.screenshot("composer-file-chip");
  await browser.keyboard.press("Enter");
  await screen.getByRole("link", "a` b `.txt", { exact: true }).waitFor();
  await app.screenshot("sent-file-mention");
  const rendered = await browser.evaluate(() => {
    const bodies = [...document.querySelectorAll("[data-user-message-body]")];
    const body = bodies.find(el => el.textContent?.includes("look at"));
    return { text: body?.textContent, code: body?.querySelectorAll("code").length, chips: body?.querySelectorAll('a').length };
  });
  expect(rendered.text).toBe("look at a` b `.txt");
  expect(rendered.code).toBe(0);
  expect(rendered.chips).toBe(1);
});
