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

test("Reopening a GitHub-filtered list retains GitLab in the workspace provider menu", WEB, async ({ t3, app, screen, browser }) => {
  const config = (url: string) => ({ ".git/config": `[core]\nrepositoryformatversion = 0\nbare = false\n[remote "origin"]\nurl = ${url}\nfetch = +refs/heads/*:refs/remotes/origin/*\n` });
  await t3.project("github-project", config("https://github.com/pingdotgg/t3code.git"));
  await t3.project("gitlab-project", config("https://gitlab.com/julius54/t3-proof-48090.git"));
  await t3.open("/pull-requests");
  await screen.getByText("Loading pull requests…", { exact: true }).waitFor({ state: "hidden", timeout: 120000 });
  await screen.getByRole("button", "Filter by provider: All", { exact: true }).click();
  await screen.getByRole("menuitemradio", "GitLab", { exact: true }).waitFor();
  await screen.getByRole("menuitemradio", "GitHub", { exact: true }).waitFor();
  await browser.keyboard.press("Escape");
  await screen.getByText("Loading pull requests…", { exact: true }).waitFor({ state: "hidden", timeout: 120000 });
  await screen.getByRole("button", "Filter by provider: All", { exact: true }).click();
  await app.screenshot("initial-workspace-providers");
  await screen.getByRole("menuitemradio", "GitHub", { exact: true }).click();
  await browser.keyboard.press("Escape");
  await screen.getByText("Loading pull requests…", { exact: true }).waitFor({ state: "hidden", timeout: 120000 });
  await screen.getByRole("button", "Back", { exact: true }).click();
  await screen.getByRole("button", "Pull requests", { exact: true }).click();
  await screen.getByRole("button", "Filter by provider: GitHub", { exact: true }).waitFor();
  await screen.getByText("Loading pull requests…", { exact: true }).waitFor({ state: "hidden", timeout: 120000 });
  await screen.getByRole("button", "Filter by provider: GitHub", { exact: true }).click();
  await app.screenshot("reopened-filtered-workspace-providers");
  await expect(screen.getByRole("menuitemradio", "GitLab", { exact: true })).toBeVisible();
});
