// @vitest-environment happy-dom
import React, { act, createRef } from "react";
import { createRoot } from "react-dom/client";
import { describe, expect, it, vi } from "vitest";
import type { DomEditSelection } from "./domEditing";
import { DomEditSelectionChrome } from "./DomEditSelectionChrome";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
describe("DomEditSelectionChrome crop composition", () => {
it("places rotated crop UI in exactly one oriented coordinate plane", () => {
const element = document.createElement("div");
element.id = "clip";
element.style.clipPath = "inset(10px)";
Object.defineProperties(element, {
offsetWidth: { value: 200 },
offsetHeight: { value: 100 },
});
document.body.append(element);
vi.spyOn(window, "getComputedStyle").mockReturnValue({
clipPath: "inset(10px)",
transform: "matrix(0.8660254, 0.5, -0.5, 0.8660254, 0, 0)",
} as CSSStyleDeclaration);
const selection = {
element,
id: "clip",
selector: "#clip",
capabilities: {
canCrop: true,
canApplyManualOffset: true,
canApplyManualSize: true,
canApplyManualRotation: true,
},
} as unknown as DomEditSelection;
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(
,
);
});
const cropFrame = host.querySelector("[data-dom-edit-crop-frame]")!;
const rotations: string[] = [];
for (
let node: HTMLElement | null = cropFrame;
node && node !== host;
node = node.parentElement
) {
if (node.style.transform.includes("rotate(")) rotations.push(node.style.transform);
}
expect(rotations).toHaveLength(1);
expect(Number.parseFloat(rotations[0]!.slice("rotate(".length))).toBeCloseTo(30, 5);
act(() => root.unmount());
});
});