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

test("Settings finds worktree cleanup by its displayed row title", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("search-demo");
  await t3.thread({ project, title: "Settings search demo", messages: ["go"] });
  await t3.open("/settings/worktrees");
  await screen.getByText("Delete worktrees with deleted threads", { exact: true }).waitFor();
  await app.screenshot("worktree-cleanup-row");
  await screen.getByRole("combobox", "Search settings").fill("Delete worktrees with deleted threads");
  try {
    await expect(screen.getByRole("option", /Worktree cleanup/)).toBeVisible();
  } finally {
    await app.screenshot("full-title-search");
  }
  await screen.getByRole("option", /Worktree cleanup/).tap();
  await expect(screen.getByText("Delete worktrees with deleted threads", { exact: true })).toBeVisible();
  await app.screenshot("search-result-opened");
});
