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

test("Simple theme colors keep invalid drafts and reject submission", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Theme demo");
  await t3.thread({ project, title: "Theme editing", messages: ["Hello"] });
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Create theme", { exact: true }).tap();
  await screen.getByRole("button", "Dark", { exact: true }).tap();
  await screen.getByLabel("Theme name", { exact: true }).fill("Invalid color proof");
  const background = screen.getByRole("textbox", "Background hex value", { exact: true });
  const accent = screen.getByRole("textbox", "Accent hex value", { exact: true });
  await background.fill("#112233");
  await background.press("Backspace");
  await app.screenshot("invalid-background-draft");
  await accent.fill("#3366cc");
  await app.screenshot("after-sibling-accent-edit");
  // Restore the same invalid Background before exercising the independent submit path.
  await background.fill("#112233");
  await background.press("Backspace");
  await screen.getByRole("dialog", "Create theme", { exact: true }).getByRole("button", "Create theme", { exact: true }).tap();
  await app.screenshot("after-invalid-submit");
  await expect(screen.getByText(/must be a literal CSS color/)).toBeVisible();
  await expect(background).toHaveValue("#11223");
  await background.fill("#112233");
  await screen.getByRole("dialog", "Create theme", { exact: true }).getByRole("button", "Create theme", { exact: true }).tap();
  await app.screenshot("after-corrected-submit");
  await expect(screen.getByRole("dialog", "Create theme", { exact: true })).not.toBeVisible();
});
