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

test("One click reopens the drawer after closing its last terminal", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("terminal-demo");
  const thread = await t3.thread({ project, title: "Terminal reopen", messages: ["Start"] });
  await t3.open(thread);
  const toggle = screen.getByRole("button", "Toggle terminal drawer");
  const close = screen.getByRole("button", /^Close Terminal/);
  await toggle.tap();
  await close.waitFor({ state: "visible" });
  await app.screenshot("initial-terminal");
  await close.tap();
  await screen.getByRole("button", "Confirm", { exact: true }).tap();
  await close.waitFor({ state: "hidden" });
  await toggle.tap();
  await app.screenshot("after-one-reopen-click");
  await expect(close).toBeVisible();
  await app.screenshot("terminal-stays-open");
});
