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

test("Word clipboard paragraph pastes as editable text", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("clipboard-demo");
  await t3.open();
  const composer = screen.getByRole("textbox");
  await composer.tap();
  await browser.evaluate(() => {
    const bytes = Uint8Array.from(atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAD0lEQVR4AQEEAPv/AP8AAAMBAQCNHeWCAAAAAElFTkSuQmCC"), c => c.charCodeAt(0));
    const clipboardData = new DataTransfer();
    clipboardData.setData("text/plain", "Hello from Word");
    clipboardData.setData("text/html", "<p class=MsoNormal>Hello from Word</p>");
    clipboardData.items.add(new File([bytes], "image.png", { type: "image/png" }));
    const editor = document.querySelector('[contenteditable="true"]');
    if (!editor) throw new Error("No composer editor");
    editor.dispatchEvent(new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }));
  });
  await app.screenshot("word-paste");
  await expect(composer).toContainText("Hello from Word");
  await expect(composer.getByRole("button", "Image attachment", { exact: false })).toHaveCount(0);
});
