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

test("Stashing and restoring preserves a trailing selected file chip", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Stash chip demo", { "README.md": "Synthetic stash reproduction.\n" });
  await t3.thread({ project, title: "Stash chip reproduction", messages: ["Ready"] });
  await t3.open();
  await screen.getByRole("button", "Stash chip reproduction, Done, Stash chip demo").tap();
  const editor = screen.getByRole("textbox");
  await editor.fill("Review @Rea");
  await screen.getByRole("option", { name: /README.md/ }).first().tap();
  await screen.getByRole("button", "Preview README.md").waitFor();
  await app.screenshot("selected-file-chip");
  await editor.press("Control+s");
  await editor.press("Control+s");
  await app.screenshot("restored-file-chip");
  await expect.soft(screen.getByRole("button", "Preview README.md")).toBeVisible();
  await editor.fill("Review @Rea");
  await editor.press("Escape");
  await editor.press("Control+s");
  await editor.press("Control+s");
  await app.screenshot("restored-unfinished-query");
  await expect(editor).toContainText("Review @Rea");
  await expect(browser.locator('[data-composer-mention-chip="true"]')).toHaveCount(0);
});
