import { expect } from "e2e";
import { test, WEB } from "./t3.ts";
const LIBREOFFICE = "{\\rtf1\\paperw11906\\paperh16838\\margl5954\\margr454\\margt567\\margb8505\\sectd\\sbknone\na\\sect\\sectd\\sbknone\nb\\sect\\sectd\nc\\par\n}\n";
test("RTF section and column breaks separate text without extra pages", WEB, async ({t3, app, screen, browser}) => {
  const project = await t3.project("rtf-documents", {
    "breaks.rtf": String.raw`{\rtf1\ansi North\column South\sect West}`,
    "fdo67498.rtf": LIBREOFFICE,
    "paragraphs.rtf": String.raw`{\rtf1\ansi One\par\sect Two\page\column Three}`,
  });
  const thread = await t3.thread({project, title:"Review RTF documents", messages:["Start"]});
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Files F").tap();
  for (const name of ["fdo67498.rtf", "breaks.rtf"]) {
    await screen.getByRole("treeitem", name).tap();
    await expect(screen.getByText("1 page", {exact:false})).toBeVisible({timeout:120_000});
    const body = browser.frameLocator(`iframe[title^="${name}"]`).locator("body");
    await body.waitFor({state:"visible"});
    await app.screenshot(name.replace(".rtf", ""));

  }
  for (const [name, text] of [["fdo67498.rtf", "a\nb\nc"], ["breaks.rtf", "North\nSouth\nWest"]]) {
    await screen.getByRole("treeitem", name).tap();
    await expect(browser.frameLocator(`iframe[title^="${name}"]`).locator("body")).toHaveText(text);
  }
});
