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

test("ghq clone destinations decode HTTPS and SSH URI paths", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  await t3.open("/settings/threads");
  await screen.getByRole("textbox", "Add project base directory").fill("~/ghq");
  await browser.keyboard.press("Tab");
  await screen.getByRole("switch", "Clone into host folders").check();
  await app.screenshot("ghq-settings");
  await t3.open();
  const destinations: string[] = [];
  for (const [label, url] of [
    ["https-destination", "https://example.invalid/Research%20Tools/cli.git"],
    ["ssh-destination", "ssh://git@example.invalid/Research%20Tools/cli.git"],
  ]) {
    await screen.getByRole("button", "Add project").tap();
    await screen.getByText("Git URL").tap();
    await screen.getByRole("combobox").fill(url);
    await browser.keyboard.press("Enter");
    await screen.getByRole("button", { name: "Create & Clone", exact: false }).waitFor();
    await app.screenshot(label);
    destinations.push(await screen.getByRole("combobox").inputValue());
    await browser.keyboard.press("Escape");
  }
  expect(destinations).toEqual([
    "~/ghq/example.invalid/Research Tools/cli",
    "~/ghq/example.invalid/Research Tools/cli",
  ]);
});
