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

test("Stashed thread mentions use readable names before truncation", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Authentication");
  const thread = await t3.thread({ project, title: "Refactor authentication middleware", messages: ["Start the authentication refactor"] });
  await t3.open(thread);
  await screen.getByRole("button", "New thread in Authentication", { exact: true }).tap();
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("@Refac");
  await screen.getByRole("option", "Refactor authentication middleware", { exact: false }).waitFor({ state: "visible" });
  await browser.keyboard.press("Enter");
  await composer.pressSequentially(" and then update the session token tests so they cover expiry and refresh paths");
  await app.screenshot("composer-thread-chip");
  await browser.keyboard.press("Control+s");
  await screen.getByRole("button", "Stashed prompts: 1. Open stash.", { exact: true }).tap();
  await app.screenshot("stash-preview");
  const restore = screen.getByRole("button", { name: /^Restore stashed prompt:/ });
  const readable = "Refactor authentication middleware and then update the session token tests so they cover expiry and refresh paths";
  const snippet = `${readable.slice(0, 90)}…`;
  await expect(restore).toHaveAccessibleName(`Restore stashed prompt: ${snippet}`);
  await expect(restore).toContainText(snippet);
});
