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

test("Quoted route metadata displays the project favicon", WEB, async ({ t3, app, screen, browser }) => {
  const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#dc2626"/><circle cx="32" cy="32" r="19" fill="#fde047"/></svg>';
  const files = (quoted: boolean) => ({
    "public/brand/quoted.svg": svg,
    "src/routes/__root.tsx": `export const Route = createRootRoute({ head: () => ({ links: [{ ${quoted ? '"rel"' : 'rel'}: "icon", ${quoted ? '"href"' : 'href'}: "/brand/quoted.svg", "data-theme": "dark" }] }) });`,
  });
  const quoted = await t3.project("quoted-keys", files(true));
  await t3.project("bare-keys", files(false));
  const thread = await t3.thread({ project: quoted, title: "Favicon comparison", messages: ["first"] });
  await t3.open(thread);
  await screen.getByRole("combobox", "Projects", { exact: true }).tap();
  await browser.locator('[role="option"]:has-text("bare-keys") img').waitFor({ state: "visible" });
  try {
    await expect(browser.locator('[role="option"]:has-text("quoted-keys") img')).toBeVisible();
  } finally {
    await app.screenshot("project-favicons");
  }
});
