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

test("Escape discards an unsaved saved retention age and keeps Settings open", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("retention-demo");
  const thread = await t3.thread({ project, title: "Retention evidence", messages: ["Hello"] });
  await t3.open(thread);
  await t3.open("/settings/maintenance");
  await screen.getByRole("switch", "Delete old browser artifacts", { exact: true }).tap();
  const age = screen.getByRole("textbox", "Delete old browser artifacts in days", { exact: true });
  await age.fill("30");
  await age.press("Enter");
  await age.fill("1");
  await app.screenshot("saved-30-edited-to-1");
  await age.press("Escape");
  await app.screenshot("after-escape");
  await expect(age).toBeVisible();
  await expect(age).toHaveValue("30");
  await expect(age).toBeFocused();
  await age.fill("");
  await age.press("Escape");
  await app.screenshot("empty-draft-after-escape");
  await expect(age).toHaveValue("30");
  await expect(age).toBeFocused();
  await age.fill("+");
  await age.press("Escape");
  await app.screenshot("plus-draft-after-escape");
  await expect(age).toHaveValue("30");
  await expect(age).toBeFocused();
  await age.press("Escape");
  await expect(age).toBeHidden();
  await t3.open("/settings/maintenance");
  await expect(age).toHaveValue("30");
  await app.screenshot("reopened-saved-age");
});
