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

test("A hostless issue link marks the displayed row current", WEB, async ({t3, app, browser, screen}) => {
  const project = await t3.project("issue-selection");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], {cwd:project}));
  await t3.open("/issues?q=Mobile");
  const row = screen.getByRole("button", {name: /Mobile: deleting an open thread elsewhere/});
  await row.waitFor({timeout:60000});
  await row.tap();
  await app.screenshot("explicit-host");
  await expect(row).toHaveAttribute("aria-current", "true");
  const url = new URL(await browser.url());
  url.searchParams.delete("selectedHost");
  await t3.open(url.pathname + url.search);
  await row.waitFor({timeout:60000});
  await app.screenshot("hostless-current-issue");
  await expect(row).toHaveAttribute("aria-current", "true");
  await expect(browser.locator('[aria-current="true"]')).toHaveCount(1);
});
