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

test("Initial worktree retention is saved only after committing its age", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Retention demo");
  await t3.open();
  await screen.getByText("Retention demo", { exact: true }).first().waitFor({ timeout: 120_000 });
  await app.open("/settings/worktrees");
  const toggle = screen.getByRole("switch", "Delete inactive worktrees", { exact: true });
  const age = screen.getByRole("textbox", "Delete inactive worktrees in days", { exact: true });
  await toggle.tap();
  await age.waitFor();
  await app.screenshot("enabled-before-commit");
  await browser.keyboard.press("Escape");
  await app.open("/settings/worktrees");
  await toggle.waitFor();
  await toggle.scrollIntoView();
  await app.screenshot("cancelled-and-reopened");
  await expect(toggle).not.toBeChecked();
  await toggle.tap();
  await age.fill("30");
  await browser.keyboard.press("Enter");
  await app.open("/settings/worktrees");
  await toggle.waitFor();
  await toggle.scrollIntoView();
  await app.screenshot("committed-30-days");
  await expect(age).toHaveValue("30");
});
