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

test("Minimap omits an emoji straddling the parsing cutoff", WEB, async ({ t3, app, browser, screen }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  const prefix = "[Build log](https://example.com/builds/1042/log?sig=";
  const link = prefix + "a".repeat(1499 - prefix.length - 2) + ") ";
  const project = await t3.project("build-demo");
  const thread = await t3.thread({ project, title: "Release build", model: "multi-turn", messages: [link + "🎉 the release build passed", "Second message so the minimap shows"] });
  await t3.open(thread);
  const jump = screen.getByRole("button", /^Jump to message:/);
  await jump.hover();
  const point = await browser.evaluate(() => {
    const rail = document.querySelector('[aria-label^="Jump to message:"]')!.getBoundingClientRect();
    const strip = document.querySelector("[data-minimap-strip]")!.getBoundingClientRect();
    return { x: rail.left + rail.width / 2, y: strip.top + strip.height / 2 };
  });
  await browser.mouse.move(point.x, point.y);
  await screen.getByText("first fixture turn complete", { exact: false }).first().waitFor();
  await app.screenshot("first-minimap-preview");
  const label = await browser.evaluate(() => document.querySelector('[aria-label^="Jump to message:"]')?.getAttribute("aria-label"));
  const preview = await browser.evaluate(() => document.querySelector('[aria-label^="Jump to message:"] .dropdown-glass')?.textContent);
  expect({ label, preview }).toEqual({ label: "Jump to message: Build log", preview: "Build logfirst fixture turn complete" });
});
