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

test("Ctrl+click places the caret without outlining the composer line", WEB, async ({ t3, app, browser }) => {
  await t3.project("Dictation demo");
  await t3.open();
  await browser.locator('[role="textbox"][contenteditable="true"]').waitFor();
  const point = await browser.evaluate(() => {
    const line = document.querySelector('[role="textbox"][contenteditable="true"] p');
    if (!line) throw new Error("Composer first paragraph was not found");
    const box = line.getBoundingClientRect();
    return { x: box.x + 20, y: box.y + box.height / 2 };
  });
  await browser.mouse.move(point.x, point.y);
  await browser.mouse.down();
  await browser.mouse.up();
  await app.screenshot("plain-click");
  await browser.keyboard.down("Control");
  await browser.mouse.down();
  await browser.mouse.up();
  await browser.keyboard.up("Control");
  await app.screenshot("ctrl-click-released");
  const outline = await browser.evaluate(() => {
    const line = document.querySelector('[role="textbox"][contenteditable="true"] p');
    if (!line) throw new Error("Composer first paragraph was not found");
    return getComputedStyle(line).outlineStyle;
  });
  expect(outline, "Ctrl+click must not draw a blue outline around the first paragraph").toBe("none");
});
