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

test("Restore device defaults resets Auto-settle after selecting a project", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Sample");
  await t3.open();
  await screen.getByText("Sample", { exact: true }).first().waitFor({ state: "visible" });
  await app.open("/settings/threads");
  await screen.getByRole("switch", "Auto-settle inactive threads").tap();
  await screen.getByRole("button", "Project scope: All projects").tap();
  await screen.getByRole("menuitemradio", "Sample").tap();
  await screen.getByRole("button", "General", { exact: true }).tap();
  await screen.getByRole("button", "Restore device defaults").tap();
  await screen.getByRole("button", "Confirm", { exact: true }).waitFor({ state: "visible" });
  await browser.evaluate(async () => { await Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {}))); });
  await app.screenshot("restore-confirmation");
  await screen.getByRole("button", "Confirm", { exact: true }).tap();
  await screen.getByRole("button", "Confirm", { exact: true }).waitFor({ state: "hidden" });
  await app.open("/settings/threads");
  await screen.getByRole("switch", "Auto-settle inactive threads").waitFor({ state: "visible" });
  await screen.getByRole("switch", "Auto-settle inactive threads").scrollIntoView();
  await browser.evaluate(async () => { await Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {}))); });
  await app.screenshot("auto-settle-after-restore");
  await expect(screen.getByRole("switch", "Auto-settle inactive threads")).toBeChecked();
  await expect(screen.getByRole("spinbutton", "Days of inactivity before auto-settle")).toHaveValue("7");
});
