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

test("Malformed repository and host URL values do not crash Pull Requests", WEB, async ({ t3, app, screen }) => {
  await t3.project("url-proof");
  const failures: string[] = [];
  const cases = [
    ["numeric-repository", "repository=123"],
    ["null-repository", "repository=null"],
    ["numeric-host", "repository=a%2Fb&host=8080"],
    ["numeric-selected-host", "repository=a%2Fb&selectedHost=1"],
    ["valid-control", "repository=a%2Fb&host=github.com"],
  ];
  for (const [label, query] of cases) {
    await t3.open(`/pull-requests?${query}`);
    try {
      await expect(screen.getByRole("searchbox", "Search pull requests", { exact: true })).toBeVisible();
    } catch {
      failures.push(label!);
    }
    await app.screenshot(label!);
  }
  expect(failures).toEqual([]);
});
