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

test("Extensionless empty ZIPs show the archive icon", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("zip-example", {
    archive: Uint8Array.from([80,75,5,6,...Array(18).fill(0)]),
    filled: Uint8Array.from(Buffer.from("UEsDBBQAAAAAAN15eV0WNZYxBgAAAAYAAAAJAAAAaGVsbG8udHh0SGVsbG8KUEsBAhQDFAAAAAAA3Xl5XRY1ljEGAAAABgAAAAkAAAAAAAAAAAAAAIABAAAAAGhlbGxvLnR4dFBLBQYAAAAAAQABADcAAAAtAAAAAAA=", "base64")),
  });
  const thread = await t3.thread({ project, title: "ZIP file icons", messages: ["Ready to inspect files"], model: "showcase" });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("Look at @archive");
  await screen.getByRole("option", "archive", { exact: false }).tap();
  await composer.pressSequentially(" and @filled");
  await screen.getByRole("option", "filled", { exact: false }).tap();
  await app.screenshot("composer-zip-icons");
  await browser.keyboard.press("Enter");
  await screen.getByRole("link", "archive", { exact: true }).waitFor();
  await screen.getByRole("link", "filled", { exact: true }).waitFor();
  await screen.getByRole("button", "Submit message", { exact: true }).waitFor();
  await browser.evaluate(() => {
    [...document.querySelectorAll('a')].find(a => a.textContent?.trim() === 'archive')?.scrollIntoView({ block: 'center' });
  });
  await app.screenshot("sent-zip-icons");
  await expect.poll(() => browser.evaluate(() =>
    [...document.querySelectorAll('a')].find(a => a.textContent?.trim() === 'archive')?.querySelector('svg')?.getAttribute('data-pierre-icon')
  )).toBe("file-tree-builtin-zip");
});
