import { expect } from "e2e";
import JSZip from "jszip";

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

test(
  "An archive member size uses the German decimal separator",
  WEB,
  async ({ t3, app, browser, screen }) => {
    const zip = await new JSZip()
      .file("report.txt", "a".repeat(1.5 * 1024 * 1024))
      .generateAsync({ type: "uint8array", compression: "STORE" });
    await t3.project("demo", { "reports.zip": zip });
    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();
    await screen.getByRole("button", "Neuer Thread in demo", { exact: true }).tap();
    await screen.getByTestId("composer-editor").waitFor();
    await browser.keyboard.press("Control+p");
    await screen.getByPlaceholder("Dateien durchsuchen…").fill("reports.zip");
    await screen.getByRole("option", "reports.zip", { exact: false }).tap();
    const member = screen.getByRole("row").filter({ hasText: "report.txt" });
    await member.waitFor({ timeout: 60_000 });
    await app.screenshot("german-archive-member");
    expect(await member.getByRole("cell").nth(1).textContent()).toBe("1,5 MB");
  },
);
