import { describe, expect, it } from "vitest"; import type { SolidMotionAdapter } from "../adapter/types.ts"; import { MOTION_PROP_KEYS, splitMotionProps } from "./split-motion-props.ts"; const fakeAdapter = { splitProps(props: Record, keys: readonly PropertyKey[]) { const motionProps = Object.create(null) as Record; const domProps = Object.create(null) as Record; const keySet = new Set(keys); for (const key of Reflect.ownKeys(props)) { const target = keySet.has(key) ? motionProps : domProps; Object.defineProperty(target, key, { enumerable: true, get: () => props[key], }); } return [motionProps, domProps] as never; }, } as unknown as Pick; describe("splitMotionProps", () => { it("keeps Motion-owned props out of the DOM prop bag", () => { const [motionProps, domProps] = splitMotionProps( { id: "card", class: "rounded", animate: { opacity: 1 }, initial: { opacity: 0 }, style: { opacity: 0.5 }, whileHover: { scale: 1.05 }, drag: "x", presenceKey: "card-a", onClick: () => undefined, }, fakeAdapter, ); expect(Object.keys(motionProps).sort()).toEqual([ "animate", "drag", "initial", "presenceKey", "style", "whileHover", ]); expect(Object.keys(domProps).sort()).toEqual(["class", "id", "onClick"]); }); it("does not invoke accessor-valued motion props while splitting", () => { let reads = 0; const rawProps = { get animate() { reads += 1; return { opacity: 1 }; }, id: "box", }; const [motionProps] = splitMotionProps(rawProps, fakeAdapter); expect(reads).toBe(0); expect(motionProps.animate).toEqual({ opacity: 1 }); expect(reads).toBe(1); }); it("tracks the Milestone 0 and near-MVP Motion prop surface", () => { expect(MOTION_PROP_KEYS).toEqual(expect.arrayContaining([ "initial", "animate", "exit", "transition", "variants", "style", "presenceKey", "layout", "layoutDependency", "whileHover", "whileTap", "whileFocus", "whileDrag", "whileInView", "drag", ])); }); });