Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/studio/src/components/editor/PropertyPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
getCssFilterFunctionPx,
inferBoxShadowPreset,
inferClipPathPreset,
isSelectedElementHidden,
normalizePanelPxValue,
parseInsetClipPathSides,
setCssFilterFunctionPx,
} from "./PropertyPanel";
import { isSelectedElementHidden } from "./propertyPanelHelpers";
} from "./propertyPanelHelpers";

describe("PropertyPanel style helpers", () => {
it("normalizes bounded pixel values without accepting incompatible units", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import { act } from "react";
import { describe, expect, it, vi } from "vitest";
import { PropertyPanelEmptyState } from "./PropertyPanelEmptyState";
import type { DomEditSelection } from "./domEditingTypes";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

describe("PropertyPanelEmptyState — flat empty", () => {
it("shows the cursor glyph, headline, and the two shortcut rows", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import { act } from "react";
import { describe, expect, it, vi } from "vitest";
import {
FlatColorGradingAccessory,
FlatColorGradingSection,
Expand All @@ -11,22 +10,9 @@ import {
normalizeHfColorGrading,
type NormalizedHfColorGrading,
} from "@hyperframes/core/color-grading";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

function neutralGrading() {
const grading = normalizeHfColorGrading("neutral");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import { act } from "react";
import { describe, expect, it, vi } from "vitest";
import {
FlatLayoutSection,
LayoutFlexBlock,
LayoutGeometryRows,
LayoutTransform3DBlock,
LayoutZIndexRow,
} from "./propertyPanelFlatLayoutSection";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

function getFlatRowInput(host: HTMLElement, label: string): HTMLInputElement {
const rows = Array.from(host.querySelectorAll<HTMLElement>(".group"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { act } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { FlatMotionSection, FlatTimingRow } from "./propertyPanelFlatMotionSection";
import type { DomEditSelection } from "./domEditing";
import { usePlayerStore } from "../../player";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
setupReactActEnvironment();

afterEach(() => {
document.body.innerHTML = "";
// The store is module-global, so a test that parks a focused ease segment
// would otherwise leak it into every test that runs after it.
usePlayerStore.getState().reset();
Expand Down Expand Up @@ -47,16 +46,6 @@ function baseElement(overrides: Partial<DomEditSelection> = {}): DomEditSelectio
} as DomEditSelection;
}

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}

describe("FlatTimingRow", () => {
it("renders Start, End, and Duration from the element's data attributes", () => {
const { host, root } = renderInto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import {
FlatGroupHeader,
FlatRow,
FlatSegmentedRow,
FlatSelectRow,
FlatSlider,
} from "./propertyPanelFlatPrimitives";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

describe("FlatRow", () => {
it("renders the default tier with no reset button", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
// @vitest-environment happy-dom

import React, { act, useState } from "react";
import { act, useState } from "react";
import { createRoot } from "react-dom/client";
import postcss from "postcss";
import tailwindcss from "tailwindcss";
import { afterEach, describe, expect, it, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { FlatTextLayerList, FlatTextSection } from "./propertyPanelFlatTextSection";
import type { DomEditSelection, DomEditTextField } from "./domEditingTypes";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

const FIELDS = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
// @vitest-environment happy-dom

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import { act } from "react";
import { describe, expect, it, vi } from "vitest";
import { FlatToggle } from "./propertyPanelFlatToggle";
import { renderInto, setupReactActEnvironment } from "./testRenderUtils";

(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});

function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
setupReactActEnvironment();

describe("FlatToggle", () => {
it("renders the off state with a dim label and dim knob, and fires onChange(true) on click", () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/studio/src/components/editor/testRenderUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach } from "vitest";

/**
* Marks the current environment as React-act-aware and registers the shared
* per-test DOM cleanup. Call once per test file, at module scope, before any
* `describe`/`it` blocks run.
*/
export function setupReactActEnvironment(): void {
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

afterEach(() => {
document.body.innerHTML = "";
});
}

export function renderInto(node: React.ReactElement) {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
act(() => {
root.render(node);
});
return { host, root };
}
Loading