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

test("Project palette skips settled and snoozed threads", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("acme-demo");
  const alpha = await t3.thread({ project, title: "Alpha", messages: ["alpha"] });
  const bravo = await t3.thread({ project, title: "Bravo", messages: ["bravo"] });
  await t3.open(bravo);
  await screen.getByRole("button", /^Bravo,/).hover();
  await screen.getByRole("button", "Settle thread", { exact: true }).first().tap();
  await browser.keyboard.press("Control+k");
  await screen.getByPlaceholder("Search commands, projects, and threads...").fill("acme-demo");
  await screen.getByRole("option", "acme-demo", { exact: false }).first().tap();
  await expect.soft(browser).toHaveURL(new RegExp(encodeURIComponent(alpha.threadId)), { timeout: 2000 });
  await screen.getByPlaceholder("Search commands, projects, and threads...").waitFor({ state: "detached" });
  await app.screenshot("settled-project-result");
  await t3.open(bravo);
  await screen.getByRole("button", "Un-settle", { exact: true }).tap();
  await t3.open(alpha);
  await screen.getByRole("button", /^Bravo,/).hover();
  await screen.getByRole("button", /^Bravo,/).getByRole("button", "Snooze thread").tap();
  await screen.getByRole("menuitem", /^Tomorrow/).first().tap();
  await browser.keyboard.press("Control+k");
  await screen.getByPlaceholder("Search commands, projects, and threads...").fill("acme-demo");
  await screen.getByRole("option", "acme-demo", { exact: false }).first().tap();
  await expect.soft(browser).toHaveURL(new RegExp(encodeURIComponent(alpha.threadId)), { timeout: 2000 });
  await screen.getByPlaceholder("Search commands, projects, and threads...").waitFor({ state: "detached" });
  await app.screenshot("snoozed-project-result");
  await t3.open(alpha);
  await screen.getByRole("button", /^Alpha,/).hover();
  await screen.getByRole("button", /^Alpha,/).getByRole("button", "Settle thread").tap();
  await browser.keyboard.press("Control+k");
  await screen.getByPlaceholder("Search commands, projects, and threads...").fill("acme-demo");
  await screen.getByRole("option", "acme-demo", { exact: false }).first().tap();
  await screen.getByPlaceholder("Search commands, projects, and threads...").waitFor({ state: "detached" });
  await expect.soft(browser).toHaveURL(/\/draft\//, { timeout: 2000 });
  await app.screenshot("all-parked-project-result");
});
