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

test("Back from an unsent draft reveals the reopened conversation", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("first-project");
  await t3.project("other-project");
  const thread = await t3.thread({ project, model: "default", title: "First project conversation", messages: ["Resume earlier work"] });
  await t3.open(thread);
  await screen.getByText("Resume earlier work", { exact: true }).waitFor({ timeout: 120_000 });
  await screen.getByRole("link", "T3 Code home").tap();
  await screen.getByRole("textbox", "Message New thread").waitFor({ timeout: 120_000 });
  await screen.getByRole("combobox", "Projects", { exact: true }).tap();
  await screen.getByRole("option", /other-project/).tap();
  await screen.getByText("No threads in other-project yet", { exact: true }).waitFor({ timeout: 120_000 });
  await browser.evaluate(() => { history.back(); return null; });
  await screen.getByText("Resume earlier work", { exact: true }).waitFor({ timeout: 120_000 });
  await app.screenshot("returned-conversation-sidebar");
  await expect(browser.locator(`[data-thread-item$="${thread.threadId}"]`)).toBeVisible();
});
