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

test("Reopening the When editor shows the expression Save will write", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  await t3.open("/settings/keybindings");
  const trigger = screen.getByRole("button", "Edit when clause for Terminal: Toggle", { exact: true });
  const expression = screen.getByRole("textbox", "When expression", { exact: true });
  await trigger.tap();
  await expression.fill("terminalFocus");
  await browser.keyboard.type(" &&");
  await app.screenshot("invalid-draft-before-close");
  await browser.keyboard.press("Escape");
  await trigger.tap();
  await app.screenshot("immediate-reopen");
  await expect(expression).toHaveValue("terminalFocus");
  await expect(screen.getByRole("button", "Save", { exact: true })).toBeEnabled();
});
