import { execFileSync } from "node:child_process";
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Azure Issues lists work items when the organization has no profile area", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Azure issue viewer proof");
  const remote = execFileSync("az", ["repos", "list", "--organization", process.env.AZURE_DEVOPS_TEST_ORG!, "--project", process.env.AZURE_DEVOPS_TEST_PROJECT!, "--query", "[0].remoteUrl", "-o", "tsv"], { encoding: "utf8" }).trim();
  execFileSync("git", ["remote", "add", "origin", remote], { cwd: project });
  const thread = await t3.thread({ project, title: "Azure issue viewer proof", messages: ["Prepare issue viewer verification"] });
  await t3.open(thread);
  await t3.open("/issues?who=all&status=open");
  await screen.getByRole("button", "Refresh issues").tap();
  await expect(screen.getByRole("button", "Refresh issues")).toBeEnabled();
  await app.screenshot("azure-issues-refreshed");
  await expect(screen.getByText("Azure issue viewer proof 38069 round 2", { exact: true })).toBeVisible();
});
