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

test("A theme containing @position-try imports and applies without an error", WEB, async ({t3, app, screen, browser}) => {
  await t3.project("theme-demo");
  await t3.open("/settings/appearance");
  const json = await browser.evaluate(async () => {
    const { serializeThemeFile } = await import("/src/themePalette.ts");
    const { EMBER_THEME } = await import("/src/themePalette.ts");
    return serializeThemeFile({ ...EMBER_THEME, id: "tooltip-tips", label: "Tooltip Tips", css: "@position-try --tip-tr { position-area: top span-right; justify-self: start; }\n:root { --tip-color: red; }" });
  });
  await screen.getByRole("button", "Add theme", {exact: true}).tap();
  const dialog = screen.getByRole("dialog", "Add a theme");
  await dialog.getByRole("textbox", "Theme JSON").fill(json);
  await dialog.getByRole("button", "Add theme", {exact: true}).tap();
  try {
    await expect(dialog).toBeHidden();
    await screen.getByRole("button", "Use Tooltip Tips theme", {exact: true}).tap();
    await expect.poll(() => browser.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--tip-color").trim())).toBe("red");
  } finally {
    await app.screenshot("position-try-theme-import");
  }
});
