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

test("ANSI fonts use Windows-1252 under Cyrillic and Macintosh document code pages", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("rtf-sample", {
    "ansi-font.rtf": String.raw`{\rtf1\ansi\ansicpg1251{\fonttbl\f0\froman\fcharset0 Times-Roman;}\f0 \'805 caf\'e9}`,
    "mac-font.rtf": String.raw`{\rtf1\mac{\fonttbl\f0\fswiss\fcharset0 Helvetica;}\f0 pridr\'9eana}`,
  });
  const thread = await t3.thread({ project, title: "RTF font previews", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Files F").tap();
  const texts: string[] = [];
  for (const file of ["ansi-font.rtf", "mac-font.rtf"]) {
    await screen.getByRole("treeitem", file).tap();
    await screen.getByText("Text and images", { exact: false }).waitFor({ timeout: 60_000 });
    await screen.getByText("1 page", { exact: false }).waitFor({ timeout: 60_000 });
    await app.screenshot(file);
    texts.push(await browser.evaluate(() => Array.from(document.querySelectorAll("iframe")).map(frame => frame.srcdoc).join("\n")));
  }
  expect(texts[0]).toContain("€5 café");
  expect(texts[1]).toContain("pridržana");
});
