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

test("Copy relative path strips repeated workspace separators", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("repo", { "src/app.ts": "export {};\n" });
  const thread = await t3.thread({ project, title: "Copy relative file path", messages: [`Please review the application source file linked below. Use the file chip context menu to copy its path relative to this workspace, then paste the result into the empty composer.\n\n[app](${project}//src/app.ts)`] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent/).tap();
  await screen.getByRole("link", "app.ts", { exact: true }).waitFor();
  await browser.evaluate(() => {
    const link = [...document.querySelectorAll("a")].find(a => a.getAttribute("href")?.includes("//src/app.ts"));
    if (!link) throw new Error("Repeated-separator file chip missing");
    const r = link.getBoundingClientRect();
    link.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: r.x + 10, clientY: r.y + 10 }));
  });
  await screen.getByText("Copy relative path", { exact: true }).tap();
  await screen.getByRole("textbox").tap();
  await browser.keyboard.press("ControlOrMeta+V");
  await app.screenshot("copied-relative-path");
  await expect(screen.getByRole("textbox")).toHaveText("src/app.ts");
});
