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

test("Undo archive reopens the open conversation", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("alpha");
  const thread = await t3.thread({ project, title: "Old alpha thread", messages: ["Hello"] });
  await t3.open(thread);
  await screen.getByRole("textbox", "Message Old alpha thread", { exact: true }).waitFor();
  await app.screenshot("open-thread-before-archive");
  await screen.getByRole("button", "Old alpha thread, alpha", { exact: true }).secondaryTap();
  await screen.getByRole("menuitem", "Archive thread", { exact: true }).tap();
  await screen.getByRole("textbox", "Message New thread", { exact: true }).waitFor();
  await browser.evaluate(() => { (document.activeElement as HTMLElement)?.blur(); return null; });
  await browser.keyboard.press("Control+z");
  await browser.locator("[data-thread-item]").waitFor();
  try {
    await expect(screen.getByRole("textbox", "Message Old alpha thread", { exact: true })).toBeVisible();
  } finally {
    await app.screenshot("after-archive-undo");
  }
});
