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

const css = `[data-settings-page-scroll] { background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><circle cx="4" cy="4" r="2" fill="red"/></svg>'); }`;

test("Inline SVG with double-quoted attributes renders in a custom theme", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Theme demo");
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Create theme", { exact: true }).tap();
  const dialog = screen.getByRole("dialog", "Create theme", { exact: true });
  await dialog.getByRole("textbox", "Theme name", { exact: true }).fill("Dots");
  await dialog.getByRole("button", "Custom CSS", { exact: true }).tap();
  await dialog.getByRole("textbox", "Custom CSS", { exact: true }).fill(css);
  await dialog.getByRole("button", "Create theme", { exact: true }).tap();
  await dialog.waitFor({ state: "hidden" });
  try {
    await expect.poll(() => browser.evaluate(() => {
      const page = document.querySelector("[data-settings-page-scroll]");
      return page ? getComputedStyle(page).backgroundImage : "none";
    }), { message: "The selected Dots theme keeps its inline SVG background" }).not.toBe("none");
  } finally {
    await app.screenshot("inline-svg-background");
  }
});
