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

test("Batch theme import identifies the oversized file in German", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("demo");
  await t3.thread({ project, title: "Theme import", messages: ["Start"] });
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("Deutsch", { exact: true }).tap();
  await screen.getByLabel("Sprache", { exact: true }).waitFor();
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Design hinzufügen", { exact: true }).tap();
  await browser.evaluate(() => {
    const input = document.querySelector<HTMLInputElement>('input[type="file"]');
    if (!input) throw new Error("Theme file input is missing");
    const files = new DataTransfer();
    files.items.add(new File([JSON.stringify({ name: "Dawn", type: "light", colors: { "editor.background": "#fafafa", "editor.foreground": "#202020" }, tokenColors: [] })], "dawn.json", { type: "application/json" }));
    files.items.add(new File([" ".repeat(1048100)], "huge.json", { type: "application/json" }));
    input.files = files.files;
    input.dispatchEvent(new Event("change", { bubbles: true }));
    return null;
  });
  const alert = screen.getByRole("alert");
  await alert.waitFor();
  try {
    await expect(alert).toHaveText("huge.json: Diese Datei ist 1.00 MB groß. Design-Dateien haben nur wenige KB, daher wurde sie nicht gelesen (Limit 256 KB).");
  } finally {
    await app.screenshot("batch-oversized-theme-german");
  }
});
