Skip to content

Commit 2e26ff4

Browse files
test: resync/bake gizmo body offsets when a parent moves
1 parent 40b0fc1 commit 2e26ff4

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

fission/src/test/scene/GizmoSceneObject.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,47 @@ describe("GizmoSceneObject", () => {
136136
})
137137
})
138138

139+
describe("syncToParent()", () => {
140+
test("should reseat via parent's postGizmoCreation and rebake offsets", () => {
141+
mockParentObject.postGizmoCreation = vi.fn()
142+
143+
gizmoSceneObject.setTransform(new THREE.Matrix4())
144+
const bakeSpy = vi.spyOn(
145+
gizmoSceneObject as unknown as { bakeRelativeTransformations: () => void },
146+
"bakeRelativeTransformations"
147+
)
148+
149+
gizmoSceneObject.syncToParent()
150+
151+
expect(mockParentObject.postGizmoCreation).toHaveBeenCalledWith(gizmoSceneObject)
152+
expect(bakeSpy).toHaveBeenCalledTimes(1)
153+
expect(gizmoSceneObject["_forceUpdate"]).toBe(false)
154+
})
155+
156+
test("should do nothing while dragging", () => {
157+
mockParentObject.postGizmoCreation = vi.fn()
158+
gizmoSceneObject.gizmo.dragging = true
159+
160+
const bakeSpy = vi.spyOn(
161+
gizmoSceneObject as unknown as { bakeRelativeTransformations: () => void },
162+
"bakeRelativeTransformations"
163+
)
164+
165+
gizmoSceneObject.syncToParent()
166+
167+
expect(mockParentObject.postGizmoCreation).not.toHaveBeenCalled()
168+
expect(bakeSpy).not.toHaveBeenCalled()
169+
})
170+
171+
test("should do nothing without parent", () => {
172+
const noParentGizmo = new GizmoSceneObject("translate", 1.0, mockMesh)
173+
174+
expect(() => noParentGizmo.syncToParent()).not.toThrow()
175+
176+
noParentGizmo.dispose()
177+
})
178+
})
179+
139180
describe("updateNodeTransform()", () => {
140181
test("should handle missing parent gracefully", () => {
141182
const noParentGizmo = new GizmoSceneObject("translate", 1.0, mockMesh)

0 commit comments

Comments
 (0)