/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Adding the last snooze option keeps focus and append order until leaving", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Snooze demo");
  await t3.open("/settings/threads");
  const add = screen.getByRole("button", "Add option", { exact: true });
  await add.tap();
  await add.tap();
  await app.screenshot("seven-options");
  await add.tap();
  await app.screenshot("eighth-option-mid-edit");
  await expect(add).toBeFocused();
  const rows = browser.locator('[role="group"][aria-label^="Snooze option "]');
  await expect(rows).toHaveCount(8);
  await expect(rows.last()).toContainText("In 1 day");
  await browser.keyboard.press("Enter");
  await browser.keyboard.press("Space");
  await app.screenshot("limit-activation-keeps-focus");
  await expect(add).toBeFocused();
  await expect(rows).toHaveCount(8);
  await expect(rows.last()).toContainText("In 1 day");
  await browser.keyboard.press("Tab");
  await app.screenshot("leaving-list-sorts");
  await expect(rows.first()).toContainText("In 30 minutes");
});
