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

test("Closed inline formatting ends at Shift+Return", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("composer-demo");
  const thread = await t3.thread({ project, title: "Composer formatting", messages: ["Ready to compose"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  const results = [];
  for (const [label, text] of [["inline-code", "`Test`"], ["bold", "**Test**"]]) {
    await composer.tap();
    await browser.keyboard.press("ControlOrMeta+A");
    await browser.keyboard.press("Backspace");
    await browser.keyboard.type(text);
    await browser.keyboard.press("Shift+Enter");
    await browser.keyboard.type("f");
    await browser.keyboard.press("ControlOrMeta+Home");
    await app.screenshot(label);
    results.push(await browser.evaluate(() => {
      const editor = document.querySelector('[contenteditable="true"]');
      return Array.from(editor?.querySelectorAll("code,strong,b") ?? []).some(node => node.textContent?.includes("f"));
    }));
  }
  expect(results).toEqual([false, false]);
});
