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

test("Closed Settings is skipped by thread Back navigation", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Navigation demo");
  const threadA = await t3.thread({ project, title: "Thread A", messages: ["First thread"] });
  await t3.thread({ project, title: "Thread B", messages: ["Second thread"] });
  await t3.open(threadA);
  await screen.getByRole("button", "Thread B", { exact: false }).tap();
  await screen.getByRole("button", "Settings", { exact: true }).tap();
  await browser.waitForURL(/\/settings\/general$/);
  await screen.getByRole("button", "Close", { exact: true }).focus();
  await browser.keyboard.press("Escape");
  await screen.getByRole("button", "Close", { exact: true }).waitFor({ state: "hidden" });
  await browser.waitForURL(/\/mcp(?::|%3A)[^/]+$/);
  await browser.keyboard.press("Control+[");
  await app.screenshot("back-after-closing-settings");
  await expect(browser).toHaveURL(new RegExp(`/${threadA.threadId.replace(":", "(?::|%3A)")}$`));
});
