/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Long author and label filters preserve whole Unicode code points", WEB, async ({ t3, app, browser, screen }) => {
  await browser.setViewport({ width: 1920, height: 900 });
  await t3.project("demo");
  const query = new URLSearchParams({ author: "a".repeat(199) + "😀", labels: "b".repeat(199) + "🐛" });
  await t3.open(`/pull-requests?${query}`);
  await screen.getByRole("button", "Filters", { exact: false }).tap();
  await screen.getByRole("menuitem", "Author", { exact: false }).tap();
  await screen.getByPlaceholder("Search authors").waitFor();
  const author = await browser.evaluate(() => document.querySelector('[role="menuitemradio"][aria-checked="true"] .truncate')?.textContent?.trim());
  await app.screenshot("author-filter");
  await browser.keyboard.press("Escape");
  await screen.getByRole("menuitem", "Labels", { exact: false }).tap();
  await screen.getByPlaceholder("Search labels").waitFor();
  const label = await browser.evaluate(() => document.querySelector('[role="menuitemcheckbox"][aria-checked="true"] .truncate')?.textContent?.trim());
  await app.screenshot("label-filter");
  const values = await browser.evaluate(() => {
    const params = new URLSearchParams(location.search);
    return { author: params.get("author"), labels: JSON.parse(params.get("labels") ?? "[]") };
  });
  expect({ author, label, values }).toEqual({ author: "a".repeat(199), label: "b".repeat(199), values: { author: "a".repeat(199), labels: ["b".repeat(199)] } });
});
