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

test("Long PR searches omit a flag and joined family whole at the label boundary", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  const observed: string[] = [];
  for (const [label, letter, emoji] of [["flag", "b", "🇺🇸"], ["family", "c", "👨‍👩‍👧"]]) {
    const query = letter.repeat(46) + emoji + " and the rest of the search";
    await t3.open(`/pull-requests?${new URLSearchParams({ q: query })}`);
    await screen.getByText(/^Nothing matches/).waitFor({ timeout: 60_000 });
    await app.screenshot(label);
    observed.push(await browser.evaluate(() => {
      const title = [...document.querySelectorAll("*")].find(el => el.childElementCount === 0 && el.textContent?.startsWith("Nothing matches"));
      return title?.textContent ?? "";
    }));
  }
  await expect(observed).toEqual([`Nothing matches “${"b".repeat(46)}…”`, `Nothing matches “${"c".repeat(46)}…”`]);
});
