@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.3244daa → 2.26.0-pr.feature-update-to-react-19.361.4e55758
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/robots/RobotAnimator.d.ts.map +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +677 -680
- package/dist/index.js.map +1 -1
- package/dist/test/setup.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/robots/RobotAnimator.tsx +20 -33
- package/src/components/robots/RobotAnimator.unit.test.tsx +49 -36
- package/src/test/setup.ts +14 -12
package/dist/test/setup.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
2
|
//# sourceMappingURL=setup.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wandelbots/wandelbots-js-react-components",
|
|
3
|
-
"version": "2.26.0-pr.feature-update-to-react-19.361.
|
|
3
|
+
"version": "2.26.0-pr.feature-update-to-react-19.361.4e55758",
|
|
4
4
|
"description": "React UI toolkit for building applications on top of the Wandelbots platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
DHParameter,
|
|
5
5
|
MotionGroupStateResponse,
|
|
6
6
|
} from "@wandelbots/nova-api/v1"
|
|
7
|
-
import React, {
|
|
7
|
+
import React, { useRef } from "react"
|
|
8
8
|
import type { Group, Object3D } from "three"
|
|
9
9
|
import { useAutorun } from "../utils/hooks"
|
|
10
10
|
import { collectJoints } from "./robotModelLogic"
|
|
@@ -25,56 +25,53 @@ export default function RobotAnimator({
|
|
|
25
25
|
Globals.assign({ frameLoop: "always" })
|
|
26
26
|
const jointValues = useRef<number[]>([])
|
|
27
27
|
const jointObjects = useRef<Object3D[]>([])
|
|
28
|
-
const [isInitialized, setIsInitialized] = useState(false)
|
|
29
28
|
const { invalidate } = useThree()
|
|
30
29
|
|
|
31
30
|
function setGroupRef(group: Group | null) {
|
|
32
|
-
if (!group)
|
|
33
|
-
setIsInitialized(false)
|
|
34
|
-
return
|
|
35
|
-
}
|
|
31
|
+
if (!group) return
|
|
36
32
|
|
|
37
33
|
jointObjects.current = collectJoints(group)
|
|
38
34
|
|
|
39
|
-
//
|
|
35
|
+
// Set initial position only if we have valid joint objects
|
|
40
36
|
if (
|
|
41
37
|
jointObjects.current.length > 0 &&
|
|
42
38
|
jointObjects.current.every((obj) => obj != null)
|
|
43
39
|
) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
// Use requestAnimationFrame to ensure axisValues is ready
|
|
41
|
+
requestAnimationFrame(() => {
|
|
42
|
+
setRotation()
|
|
43
|
+
invalidate()
|
|
44
|
+
})
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
function updateJoints(newJointValues: number[]) {
|
|
51
|
-
if (!isInitialized) return
|
|
52
|
-
|
|
53
49
|
jointValues.current = newJointValues
|
|
54
50
|
setSpring.start(Object.assign({}, jointValues.current) as any)
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
// Initialize spring only after joints are ready
|
|
58
53
|
const [axisValues, setSpring] = useSpring(() => ({
|
|
59
54
|
...Object.assign(
|
|
60
55
|
{},
|
|
61
56
|
rapidlyChangingMotionState.state.joint_position.joints,
|
|
62
57
|
),
|
|
63
58
|
onChange: () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
invalidate()
|
|
67
|
-
}
|
|
59
|
+
setRotation()
|
|
60
|
+
invalidate()
|
|
68
61
|
},
|
|
69
62
|
onResolve: () => {
|
|
70
|
-
|
|
71
|
-
setRotation()
|
|
72
|
-
}
|
|
63
|
+
setRotation()
|
|
73
64
|
},
|
|
74
65
|
}))
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
function setRotation() {
|
|
68
|
+
// Safety check to prevent race condition
|
|
69
|
+
if (
|
|
70
|
+
jointObjects.current.length === 0 ||
|
|
71
|
+
!jointObjects.current.every((obj) => obj != null)
|
|
72
|
+
) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
78
75
|
|
|
79
76
|
const updatedJointValues = jointObjects.current.map((_, objectIndex) =>
|
|
80
77
|
(axisValues as any)[objectIndex].get(),
|
|
@@ -92,19 +89,9 @@ export default function RobotAnimator({
|
|
|
92
89
|
rotationSign * updatedJointValues[index]! + rotationOffset
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Effect to handle initial rotation when component becomes initialized
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (isInitialized) {
|
|
100
|
-
setRotation()
|
|
101
|
-
invalidate()
|
|
102
|
-
}
|
|
103
|
-
}, [isInitialized, setRotation, invalidate])
|
|
92
|
+
}
|
|
104
93
|
|
|
105
94
|
useAutorun(() => {
|
|
106
|
-
if (!isInitialized) return
|
|
107
|
-
|
|
108
95
|
const newJointValues =
|
|
109
96
|
rapidlyChangingMotionState.state.joint_position.joints.filter(
|
|
110
97
|
(item) => item !== undefined,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
DHParameter,
|
|
3
|
+
MotionGroupStateResponse,
|
|
4
|
+
} from "@wandelbots/nova-api/v1"
|
|
2
5
|
import { Object3D } from "three"
|
|
3
|
-
import
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
4
7
|
|
|
5
8
|
// Import the component for testing
|
|
6
9
|
import RobotAnimator from "./RobotAnimator"
|
|
@@ -27,9 +30,9 @@ vi.mock("@react-three/fiber", () => ({
|
|
|
27
30
|
}),
|
|
28
31
|
}))
|
|
29
32
|
|
|
33
|
+
import { useSpring } from "@react-spring/three"
|
|
30
34
|
import { useAutorun } from "../utils/hooks"
|
|
31
35
|
import { collectJoints } from "./robotModelLogic"
|
|
32
|
-
import { useSpring } from "@react-spring/three"
|
|
33
36
|
|
|
34
37
|
const mockUseAutorun = useAutorun as any
|
|
35
38
|
const mockCollectJoints = collectJoints as any
|
|
@@ -72,7 +75,9 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
72
75
|
mockAxisValues = {}
|
|
73
76
|
for (let i = 0; i < 6; i++) {
|
|
74
77
|
mockAxisValues[i] = {
|
|
75
|
-
get: vi
|
|
78
|
+
get: vi
|
|
79
|
+
.fn()
|
|
80
|
+
.mockReturnValue(mockMotionState.state.joint_position.joints[i]),
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -123,7 +128,7 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
123
128
|
const dhParam = dhParameters[index]
|
|
124
129
|
const rotationOffset = dhParam.theta || 0
|
|
125
130
|
const rotationSign = dhParam.reverse_rotation_direction ? -1 : 1
|
|
126
|
-
|
|
131
|
+
|
|
127
132
|
joint.rotation.y = rotationSign * jointValues[index]! + rotationOffset
|
|
128
133
|
})
|
|
129
134
|
|
|
@@ -140,7 +145,7 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
140
145
|
// Test the filtering logic that removes undefined values
|
|
141
146
|
const inputJoints = [1, undefined, 3, undefined, 5, 6]
|
|
142
147
|
const filteredJoints = inputJoints.filter((item) => item !== undefined)
|
|
143
|
-
|
|
148
|
+
|
|
144
149
|
expect(filteredJoints).toEqual([1, 3, 5, 6])
|
|
145
150
|
expect(filteredJoints.length).toBe(4)
|
|
146
151
|
})
|
|
@@ -148,25 +153,25 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
148
153
|
it("should test DH parameter application", () => {
|
|
149
154
|
// Test various DH parameter combinations
|
|
150
155
|
const testCases = [
|
|
151
|
-
{
|
|
152
|
-
jointValue: 1.0,
|
|
156
|
+
{
|
|
157
|
+
jointValue: 1.0,
|
|
153
158
|
dhParam: { theta: 0, reverse_rotation_direction: false },
|
|
154
|
-
expected: 1.0
|
|
159
|
+
expected: 1.0,
|
|
155
160
|
},
|
|
156
|
-
{
|
|
157
|
-
jointValue: 1.0,
|
|
161
|
+
{
|
|
162
|
+
jointValue: 1.0,
|
|
158
163
|
dhParam: { theta: 0.5, reverse_rotation_direction: false },
|
|
159
|
-
expected: 1.5
|
|
164
|
+
expected: 1.5,
|
|
160
165
|
},
|
|
161
|
-
{
|
|
162
|
-
jointValue: 1.0,
|
|
166
|
+
{
|
|
167
|
+
jointValue: 1.0,
|
|
163
168
|
dhParam: { theta: 0, reverse_rotation_direction: true },
|
|
164
|
-
expected: -1.0
|
|
169
|
+
expected: -1.0,
|
|
165
170
|
},
|
|
166
|
-
{
|
|
167
|
-
jointValue: 1.0,
|
|
171
|
+
{
|
|
172
|
+
jointValue: 1.0,
|
|
168
173
|
dhParam: { theta: 0.5, reverse_rotation_direction: true },
|
|
169
|
-
expected: -0.5
|
|
174
|
+
expected: -0.5,
|
|
170
175
|
},
|
|
171
176
|
]
|
|
172
177
|
|
|
@@ -174,9 +179,9 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
174
179
|
const joint = new Object3D()
|
|
175
180
|
const rotationOffset = dhParam.theta || 0
|
|
176
181
|
const rotationSign = dhParam.reverse_rotation_direction ? -1 : 1
|
|
177
|
-
|
|
182
|
+
|
|
178
183
|
joint.rotation.y = rotationSign * jointValue + rotationOffset
|
|
179
|
-
|
|
184
|
+
|
|
180
185
|
expect(joint.rotation.y).toBeCloseTo(expected, 5)
|
|
181
186
|
})
|
|
182
187
|
})
|
|
@@ -203,10 +208,11 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
203
208
|
it("should test empty joint array handling", () => {
|
|
204
209
|
// Test behavior when no joints are available
|
|
205
210
|
const emptyJoints: Object3D[] = []
|
|
206
|
-
|
|
211
|
+
|
|
207
212
|
// This simulates the isInitialized check in the component
|
|
208
|
-
const isInitialized =
|
|
209
|
-
|
|
213
|
+
const isInitialized =
|
|
214
|
+
emptyJoints.length > 0 && emptyJoints.every((obj) => obj != null)
|
|
215
|
+
|
|
210
216
|
expect(isInitialized).toBe(false)
|
|
211
217
|
})
|
|
212
218
|
|
|
@@ -214,10 +220,12 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
214
220
|
// Test the joint object validation logic
|
|
215
221
|
const validJoints = [new Object3D(), new Object3D(), new Object3D()]
|
|
216
222
|
const invalidJoints = [new Object3D(), null, new Object3D()]
|
|
217
|
-
|
|
218
|
-
const isValidJointsInitialized =
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
|
|
224
|
+
const isValidJointsInitialized =
|
|
225
|
+
validJoints.length > 0 && validJoints.every((obj) => obj != null)
|
|
226
|
+
const isInvalidJointsInitialized =
|
|
227
|
+
invalidJoints.length > 0 && invalidJoints.every((obj) => obj != null)
|
|
228
|
+
|
|
221
229
|
expect(isValidJointsInitialized).toBe(true)
|
|
222
230
|
expect(isInvalidJointsInitialized).toBe(false)
|
|
223
231
|
})
|
|
@@ -227,7 +235,9 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
227
235
|
expect(mockMotionState.state).toBeDefined()
|
|
228
236
|
expect(mockMotionState.state.joint_position).toBeDefined()
|
|
229
237
|
expect(mockMotionState.state.joint_position.joints).toBeDefined()
|
|
230
|
-
expect(Array.isArray(mockMotionState.state.joint_position.joints)).toBe(
|
|
238
|
+
expect(Array.isArray(mockMotionState.state.joint_position.joints)).toBe(
|
|
239
|
+
true,
|
|
240
|
+
)
|
|
231
241
|
expect(mockMotionState.state.joint_position.joints.length).toBe(6)
|
|
232
242
|
})
|
|
233
243
|
|
|
@@ -245,10 +255,10 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
245
255
|
const mockCallback = vi.fn()
|
|
246
256
|
const testJoints = [new Object3D(), new Object3D()]
|
|
247
257
|
const testValues = [1.0, 2.0]
|
|
248
|
-
|
|
258
|
+
|
|
249
259
|
// Simulate calling the callback
|
|
250
260
|
mockCallback(testJoints, testValues)
|
|
251
|
-
|
|
261
|
+
|
|
252
262
|
expect(mockCallback).toHaveBeenCalledWith(testJoints, testValues)
|
|
253
263
|
expect(mockCallback).toHaveBeenCalledTimes(1)
|
|
254
264
|
})
|
|
@@ -257,29 +267,32 @@ describe("RobotAnimator Logic Tests", () => {
|
|
|
257
267
|
// Test the initialization state logic that prevents race conditions
|
|
258
268
|
let isInitialized = false
|
|
259
269
|
const joints: Object3D[] = []
|
|
260
|
-
|
|
270
|
+
|
|
261
271
|
// Simulate setGroupRef logic
|
|
262
272
|
function simulateSetGroupRef(group: any) {
|
|
263
273
|
if (!group) {
|
|
264
274
|
isInitialized = false
|
|
265
275
|
return
|
|
266
276
|
}
|
|
267
|
-
|
|
277
|
+
|
|
268
278
|
// Simulate collectJoints
|
|
269
279
|
const collectedJoints = group ? [new Object3D(), new Object3D()] : []
|
|
270
|
-
|
|
280
|
+
|
|
271
281
|
// Only mark as initialized if we have valid joint objects
|
|
272
|
-
if (
|
|
282
|
+
if (
|
|
283
|
+
collectedJoints.length > 0 &&
|
|
284
|
+
collectedJoints.every((obj) => obj != null)
|
|
285
|
+
) {
|
|
273
286
|
isInitialized = true
|
|
274
287
|
} else {
|
|
275
288
|
isInitialized = false
|
|
276
289
|
}
|
|
277
290
|
}
|
|
278
|
-
|
|
291
|
+
|
|
279
292
|
// Test null group
|
|
280
293
|
simulateSetGroupRef(null)
|
|
281
294
|
expect(isInitialized).toBe(false)
|
|
282
|
-
|
|
295
|
+
|
|
283
296
|
// Test valid group
|
|
284
297
|
simulateSetGroupRef({ type: "Group" })
|
|
285
298
|
expect(isInitialized).toBe(true)
|
package/src/test/setup.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { beforeAll, vi } from
|
|
1
|
+
import "@testing-library/jest-dom"
|
|
2
|
+
import { beforeAll, vi } from "vitest"
|
|
3
3
|
|
|
4
4
|
// Mock ResizeObserver
|
|
5
5
|
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
@@ -16,9 +16,9 @@ global.IntersectionObserver = vi.fn().mockImplementation(() => ({
|
|
|
16
16
|
}))
|
|
17
17
|
|
|
18
18
|
// Mock matchMedia
|
|
19
|
-
Object.defineProperty(window,
|
|
19
|
+
Object.defineProperty(window, "matchMedia", {
|
|
20
20
|
writable: true,
|
|
21
|
-
value: vi.fn().mockImplementation(query => ({
|
|
21
|
+
value: vi.fn().mockImplementation((query) => ({
|
|
22
22
|
matches: false,
|
|
23
23
|
media: query,
|
|
24
24
|
onchange: null,
|
|
@@ -95,15 +95,17 @@ const mockWebGLContext = {
|
|
|
95
95
|
TRUE: 1,
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
HTMLCanvasElement.prototype.getContext = vi
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
98
|
+
HTMLCanvasElement.prototype.getContext = vi
|
|
99
|
+
.fn()
|
|
100
|
+
.mockImplementation((contextType) => {
|
|
101
|
+
if (contextType === "webgl" || contextType === "experimental-webgl") {
|
|
102
|
+
return mockWebGLContext
|
|
103
|
+
}
|
|
104
|
+
return null
|
|
105
|
+
})
|
|
104
106
|
|
|
105
107
|
beforeAll(() => {
|
|
106
108
|
// Suppress console errors in tests
|
|
107
|
-
vi.spyOn(console,
|
|
108
|
-
vi.spyOn(console,
|
|
109
|
+
vi.spyOn(console, "error").mockImplementation(() => {})
|
|
110
|
+
vi.spyOn(console, "warn").mockImplementation(() => {})
|
|
109
111
|
})
|