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

test("Repository groups preserve spaces and case from remote paths", WEB, async ({ t3, app, screen }) => {
  const projects: string[] = [];
  for (const [title, remote] of [
    ["my-app", "ssh://git@git.example.test/Team Repos/My App.git"],
    ["my-app-review", "ssh://git@git.example.test/Team Repos/My App.git"],
    ["ctl-a", "ssh://git@git.example.test/Team-Repos/My-App.git"],
    ["ctl-b", "ssh://git@git.example.test/Team-Repos/My-App.git"],
  ]) {
    const project = await t3.project(title!);
    execFileSync("git", ["remote", "add", "origin", remote!], { cwd: project });
    projects.push(project);
  }
  const thread = await t3.thread({ project: projects[0]!, title: "Repository display names", messages: ["Ready"] });
  await t3.open(thread);
  await screen.getByRole("combobox", "Projects", { exact: true }).click();
  await screen.getByRole("option", "Team-Repos/My-App", { exact: true }).waitFor();
  await app.screenshot("repository-group-names");
  await expect(screen.getByRole("option", "Team Repos/My App", { exact: true })).toBeVisible();
});
