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

test("Sent user paths preserve single tildes and remain findable", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("tilde-demo");
  await t3.open();
  const prompt = "Install the skill as ~/folder-a/skills/x, then follow the guide (~/folder-a/guide.md).";
  const composer = screen.getByRole("textbox");
  await composer.tap();
  await browser.keyboard.type(prompt);
  await app.screenshot("rich-composer-literal-paths");
  await composer.press("Enter");
  await screen.getByText("This turn is a replay.", { exact: false }).waitFor();
  await browser.locator('[data-user-message-body="true"]').first().scrollIntoView();
  await app.screenshot("sent-single-tildes");
  const rendered = await browser.locator('[data-user-message-body="true"]').first().textContent();
  await composer.tap();
  await browser.keyboard.type("Drop ~~old~~");
  await composer.press("Enter");
  await browser.locator('[data-user-message-body="true"]').filter({ hasText: "Drop" }).waitFor();
  await screen.getByRole("button", "Stop generation").waitFor({ state: "hidden" });
  await browser.locator('[data-user-message-body="true"]').filter({ hasText: "Drop" }).scrollIntoView();
  await app.screenshot("double-tilde-control");

  await browser.keyboard.press("Control+f");
  await screen.getByRole("searchbox", "Find in thread").fill("~/folder-a/skills/x");
  await browser.locator('[data-thread-find-bar] [aria-live="polite"]').filter({ hasText: /^(0\/0|1\/1|0 of 0|1 of 1)$/ }).waitFor();
  await browser.locator('[data-user-message-body="true"]').first().scrollIntoView();
  await app.screenshot("thread-find-literal-path");
  const count = await browser.locator('[data-thread-find-bar] [aria-live="polite"]').textContent();
  expect({ rendered, count }).toEqual({ rendered: prompt, count: "1/1" });
});
