@shopware-ag/dive 1.17.2 → 1.18.0
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/README.md +56 -22
- package/build/dive.cjs +11 -7
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +3 -4
- package/build/dive.d.ts +3 -4
- package/build/dive.js +9 -5
- package/build/dive.js.map +1 -1
- package/package.json +1 -1
- package/src/__test__/DIVE.test.ts +0 -40
- package/src/animation/__test__/AnimationSystem.test.ts +0 -7
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -140
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -140
- package/src/axiscamera/__test__/AxisCamera.test.ts +0 -76
- package/src/com/__test__/Communication.test.ts +0 -6
- package/src/controls/__test__/OrbitControls.test.ts +0 -87
- package/src/dive.ts +3 -3
- package/src/exporters/usdz/__test__/USDZExporter.test.ts +57 -0
- package/src/group/Group.ts +6 -1
- package/src/group/__test__/Group.test.ts +6 -3
- package/src/io/gltf/__test__/GLTFIO.test.ts +0 -77
- package/src/light/PointLight.ts +1 -1
- package/src/light/__test__/AmbientLight.test.ts +0 -24
- package/src/light/__test__/PointLight.test.ts +0 -61
- package/src/light/__test__/SceneLight.test.ts +0 -89
- package/src/loadingmanager/LoadingManager.ts +2 -1
- package/src/loadingmanager/__test__/LoadingManager.test.ts +0 -30
- package/src/math/degToRad/__test__/degToRad.test.ts +0 -7
- package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -7
- package/src/model/Model.ts +1 -1
- package/src/model/__test__/Model.test.ts +5 -155
- package/src/node/__test__/Node.test.ts +0 -149
- package/src/primitive/__test__/Primitive.test.ts +6 -199
- package/src/primitive/floor/__test__/Floor.test.ts +0 -3
- package/src/renderer/__test__/Renderer.test.ts +16 -46
- package/src/scene/__test__/Scene.test.ts +6 -16
- package/src/scene/root/Root.ts +4 -4
- package/src/scene/root/__test__/Root.test.ts +6 -188
- package/src/toolbox/__test__/BaseTool.test.ts +34 -38
- package/src/toolbox/select/__test__/SelectTool.test.ts +16 -89
- package/src/toolbox/transform/__test__/TransformTool.test.ts +14 -82
|
@@ -14,192 +14,6 @@ import { DIVECommunication } from '../../../com/Communication';
|
|
|
14
14
|
import { type DIVESceneObject } from '../../../types';
|
|
15
15
|
import { Vector3, Mesh, Box3, Object3D } from 'three';
|
|
16
16
|
|
|
17
|
-
jest.mock('three', () => {
|
|
18
|
-
return {
|
|
19
|
-
Vector3: jest.fn(function (x: number, y: number, z: number) {
|
|
20
|
-
this.x = x;
|
|
21
|
-
this.y = y;
|
|
22
|
-
this.z = z;
|
|
23
|
-
this.copy = (vec3: Vector3) => {
|
|
24
|
-
this.x = vec3.x;
|
|
25
|
-
this.y = vec3.y;
|
|
26
|
-
this.z = vec3.z;
|
|
27
|
-
return this;
|
|
28
|
-
};
|
|
29
|
-
this.set = (x: number, y: number, z: number) => {
|
|
30
|
-
this.x = x;
|
|
31
|
-
this.y = y;
|
|
32
|
-
this.z = z;
|
|
33
|
-
return this;
|
|
34
|
-
};
|
|
35
|
-
this.multiply = (vec3: Vector3) => {
|
|
36
|
-
this.x *= vec3.x;
|
|
37
|
-
this.y *= vec3.y;
|
|
38
|
-
this.z *= vec3.z;
|
|
39
|
-
return this;
|
|
40
|
-
};
|
|
41
|
-
this.clone = () => {
|
|
42
|
-
return new Vector3(this.x, this.y, this.z);
|
|
43
|
-
};
|
|
44
|
-
this.setY = (y: number) => {
|
|
45
|
-
this.y = y;
|
|
46
|
-
return this;
|
|
47
|
-
};
|
|
48
|
-
this.add = (vec3: Vector3) => {
|
|
49
|
-
this.x += vec3.x;
|
|
50
|
-
this.y += vec3.y;
|
|
51
|
-
this.z += vec3.z;
|
|
52
|
-
return this;
|
|
53
|
-
};
|
|
54
|
-
this.sub = (vec3: Vector3) => {
|
|
55
|
-
this.x -= vec3.x;
|
|
56
|
-
this.y -= vec3.y;
|
|
57
|
-
this.z -= vec3.z;
|
|
58
|
-
return this;
|
|
59
|
-
};
|
|
60
|
-
return this;
|
|
61
|
-
}),
|
|
62
|
-
Object3D: jest.fn(function () {
|
|
63
|
-
this.isObject3D = true;
|
|
64
|
-
this.clear = jest.fn();
|
|
65
|
-
this.color = {};
|
|
66
|
-
this.intensity = 0;
|
|
67
|
-
this.layers = {
|
|
68
|
-
mask: 0,
|
|
69
|
-
};
|
|
70
|
-
this.userData = {};
|
|
71
|
-
this.shadow = {
|
|
72
|
-
radius: 0,
|
|
73
|
-
mapSize: { width: 0, height: 0 },
|
|
74
|
-
bias: 0,
|
|
75
|
-
camera: {
|
|
76
|
-
near: 0,
|
|
77
|
-
far: 0,
|
|
78
|
-
fov: 0,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
this.add = jest.fn();
|
|
82
|
-
this.attach = jest.fn();
|
|
83
|
-
this.remove = jest.fn();
|
|
84
|
-
this.sub = jest.fn();
|
|
85
|
-
this.children = [
|
|
86
|
-
{
|
|
87
|
-
visible: true,
|
|
88
|
-
material: {
|
|
89
|
-
color: {},
|
|
90
|
-
},
|
|
91
|
-
userData: {},
|
|
92
|
-
},
|
|
93
|
-
];
|
|
94
|
-
this.userData = {};
|
|
95
|
-
this.position = new Vector3();
|
|
96
|
-
this.rotation = {
|
|
97
|
-
x: 0,
|
|
98
|
-
y: 0,
|
|
99
|
-
z: 0,
|
|
100
|
-
setFromVector3: jest.fn(),
|
|
101
|
-
};
|
|
102
|
-
this.scale = {
|
|
103
|
-
x: 1,
|
|
104
|
-
y: 1,
|
|
105
|
-
z: 1,
|
|
106
|
-
set: jest.fn(),
|
|
107
|
-
};
|
|
108
|
-
this.localToWorld = (vec3: Vector3) => {
|
|
109
|
-
return vec3;
|
|
110
|
-
};
|
|
111
|
-
this.mesh = new Mesh();
|
|
112
|
-
this.traverse = jest.fn((callback) => {
|
|
113
|
-
callback(this);
|
|
114
|
-
for (let i = 0; i < this.children.length; i++) {
|
|
115
|
-
callback(this.children[i]);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
this.parent = {
|
|
119
|
-
parent: null,
|
|
120
|
-
};
|
|
121
|
-
return this;
|
|
122
|
-
}),
|
|
123
|
-
Box3: jest.fn(function () {
|
|
124
|
-
this.min = new Vector3(Infinity, Infinity, Infinity);
|
|
125
|
-
this.max = new Vector3(-Infinity, -Infinity, -Infinity);
|
|
126
|
-
this.getCenter = jest.fn(() => {
|
|
127
|
-
return new Vector3(0, 0, 0);
|
|
128
|
-
});
|
|
129
|
-
this.expandByObject = jest.fn();
|
|
130
|
-
this.setFromObject = jest.fn();
|
|
131
|
-
|
|
132
|
-
return this;
|
|
133
|
-
}),
|
|
134
|
-
Raycaster: jest.fn(function () {
|
|
135
|
-
this.intersectObjects = jest.fn();
|
|
136
|
-
this.layers = {
|
|
137
|
-
mask: 0,
|
|
138
|
-
};
|
|
139
|
-
return this;
|
|
140
|
-
}),
|
|
141
|
-
Mesh: jest.fn(function () {
|
|
142
|
-
this.geometry = {
|
|
143
|
-
computeBoundingBox: jest.fn(),
|
|
144
|
-
boundingBox: new Box3(),
|
|
145
|
-
};
|
|
146
|
-
this.material = {};
|
|
147
|
-
this.castShadow = true;
|
|
148
|
-
this.receiveShadow = true;
|
|
149
|
-
this.layers = {
|
|
150
|
-
mask: 0,
|
|
151
|
-
};
|
|
152
|
-
this.updateWorldMatrix = jest.fn();
|
|
153
|
-
this.traverse = jest.fn();
|
|
154
|
-
this.removeFromParent = jest.fn();
|
|
155
|
-
this.localToWorld = (vec3: Vector3) => {
|
|
156
|
-
return vec3;
|
|
157
|
-
};
|
|
158
|
-
return this;
|
|
159
|
-
}),
|
|
160
|
-
BufferGeometry: jest.fn(function () {
|
|
161
|
-
this.setAttribute = jest.fn();
|
|
162
|
-
this.setIndex = jest.fn();
|
|
163
|
-
this.translate = jest.fn();
|
|
164
|
-
return this;
|
|
165
|
-
}),
|
|
166
|
-
CylinderGeometry: jest.fn(function () {
|
|
167
|
-
this.translate = jest.fn();
|
|
168
|
-
return this;
|
|
169
|
-
}),
|
|
170
|
-
SphereGeometry: jest.fn(function () {
|
|
171
|
-
this.translate = jest.fn();
|
|
172
|
-
return this;
|
|
173
|
-
}),
|
|
174
|
-
BoxGeometry: jest.fn(function () {
|
|
175
|
-
this.translate = jest.fn();
|
|
176
|
-
return this;
|
|
177
|
-
}),
|
|
178
|
-
ConeGeometry: jest.fn(function () {
|
|
179
|
-
this.rotateY = jest.fn();
|
|
180
|
-
this.translate = jest.fn();
|
|
181
|
-
return this;
|
|
182
|
-
}),
|
|
183
|
-
Float32BufferAttribute: jest.fn(function () {
|
|
184
|
-
return this;
|
|
185
|
-
}),
|
|
186
|
-
Uint32BufferAttribute: jest.fn(function () {
|
|
187
|
-
return this;
|
|
188
|
-
}),
|
|
189
|
-
MeshStandardMaterial: jest.fn(function () {
|
|
190
|
-
this.color = {};
|
|
191
|
-
this.roughness = 0;
|
|
192
|
-
this.roughnessMap = undefined;
|
|
193
|
-
this.metalness = 0;
|
|
194
|
-
this.metalnessMap = undefined;
|
|
195
|
-
return this;
|
|
196
|
-
}),
|
|
197
|
-
Color: jest.fn(function () {
|
|
198
|
-
return this;
|
|
199
|
-
}),
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
|
|
203
17
|
jest.mock('../../../com/Communication.ts', () => {
|
|
204
18
|
return {
|
|
205
19
|
DIVECommunication: {
|
|
@@ -415,6 +229,8 @@ let root: DIVERoot;
|
|
|
415
229
|
|
|
416
230
|
let spyConsoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
417
231
|
|
|
232
|
+
Object3D.prototype.attach = jest.fn();
|
|
233
|
+
|
|
418
234
|
describe('DIVE/scene/root/DIVERoot', () => {
|
|
419
235
|
beforeEach(() => {
|
|
420
236
|
root = new DIVERoot();
|
|
@@ -598,7 +414,7 @@ describe('DIVE/scene/root/DIVERoot', () => {
|
|
|
598
414
|
).not.toThrow();
|
|
599
415
|
expect(() =>
|
|
600
416
|
root.AddSceneObject({
|
|
601
|
-
id: '
|
|
417
|
+
id: 'id10',
|
|
602
418
|
name: 'Group',
|
|
603
419
|
entityType: 'group',
|
|
604
420
|
visible: true,
|
|
@@ -705,6 +521,7 @@ describe('DIVE/scene/root/DIVERoot', () => {
|
|
|
705
521
|
parentId: 'id_groupparent',
|
|
706
522
|
} as COMGroup),
|
|
707
523
|
).not.toThrow();
|
|
524
|
+
|
|
708
525
|
expect(() =>
|
|
709
526
|
root.UpdateSceneObject({
|
|
710
527
|
id: 'id_groupchild',
|
|
@@ -856,7 +673,7 @@ describe('DIVE/scene/root/DIVERoot', () => {
|
|
|
856
673
|
visible: true,
|
|
857
674
|
} as COMPrimitive),
|
|
858
675
|
).not.toThrow();
|
|
859
|
-
expect(spyConsoleWarn).
|
|
676
|
+
expect(spyConsoleWarn).toHaveBeenCalled();
|
|
860
677
|
|
|
861
678
|
spyConsoleWarn.mockClear();
|
|
862
679
|
expect(() =>
|
|
@@ -877,6 +694,7 @@ describe('DIVE/scene/root/DIVERoot', () => {
|
|
|
877
694
|
remove: jest.fn(),
|
|
878
695
|
},
|
|
879
696
|
} as unknown as DIVESceneObject);
|
|
697
|
+
|
|
880
698
|
expect(() =>
|
|
881
699
|
root.DeleteSceneObject({
|
|
882
700
|
id: 'id',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DIVEBaseTool } from '../BaseTool';
|
|
2
2
|
import type DIVEOrbitControls from '../../controls/OrbitControls';
|
|
3
3
|
import type { DIVEScene } from '../../scene/Scene';
|
|
4
|
-
import { type Intersection, type Object3D
|
|
4
|
+
import { Vector3, type Intersection, type Object3D } from 'three';
|
|
5
5
|
import { type DIVEHoverable } from '../../interface/Hoverable';
|
|
6
6
|
import { type DIVEDraggable } from '../../interface/Draggable';
|
|
7
|
+
import { RaycasterIntersectObjectMock } from '../../../__mocks__/three';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @jest-environment jsdom
|
|
@@ -60,19 +61,17 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
60
61
|
|
|
61
62
|
it('should raycast', () => {
|
|
62
63
|
const toolBox = new abstractWrapper(mockScene, mockController);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
];
|
|
73
|
-
});
|
|
64
|
+
RaycasterIntersectObjectMock.mockImplementationOnce(() => {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
object: {
|
|
68
|
+
visible: true,
|
|
69
|
+
},
|
|
70
|
+
} as unknown as Intersection,
|
|
71
|
+
];
|
|
72
|
+
});
|
|
74
73
|
expect(() => toolBox['raycast']()).not.toThrow();
|
|
75
|
-
expect(
|
|
74
|
+
expect(RaycasterIntersectObjectMock).toHaveBeenCalled();
|
|
76
75
|
});
|
|
77
76
|
|
|
78
77
|
it('should raycast with selection of objects', () => {
|
|
@@ -179,11 +178,10 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
179
178
|
const toolBox = new abstractWrapper(mockScene, mockController);
|
|
180
179
|
jest.spyOn(toolBox['_raycaster'], 'setFromCamera').mockImplementation();
|
|
181
180
|
|
|
181
|
+
const spy = jest.spyOn(toolBox['_raycaster'], 'intersectObjects');
|
|
182
|
+
|
|
182
183
|
// test with no hit with hovered object before
|
|
183
|
-
|
|
184
|
-
toolBox['_raycaster'],
|
|
185
|
-
'intersectObjects',
|
|
186
|
-
).mockReturnValueOnce([]);
|
|
184
|
+
spy.mockReturnValue([]);
|
|
187
185
|
|
|
188
186
|
toolBox['_hovered'] = {
|
|
189
187
|
uuid: 'uuid',
|
|
@@ -215,10 +213,7 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
215
213
|
).not.toThrow();
|
|
216
214
|
|
|
217
215
|
// test with no hovered object
|
|
218
|
-
|
|
219
|
-
toolBox['_raycaster'],
|
|
220
|
-
'intersectObjects',
|
|
221
|
-
).mockReturnValueOnce([
|
|
216
|
+
spy.mockReturnValue([
|
|
222
217
|
{
|
|
223
218
|
distance: 1,
|
|
224
219
|
point: {
|
|
@@ -259,10 +254,7 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
259
254
|
).not.toThrow();
|
|
260
255
|
|
|
261
256
|
// test with no hovered object with onPointerEnter
|
|
262
|
-
|
|
263
|
-
toolBox['_raycaster'],
|
|
264
|
-
'intersectObjects',
|
|
265
|
-
).mockReturnValueOnce([
|
|
257
|
+
spy.mockReturnValue([
|
|
266
258
|
{
|
|
267
259
|
distance: 1,
|
|
268
260
|
point: {
|
|
@@ -304,10 +296,7 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
304
296
|
).not.toThrow();
|
|
305
297
|
|
|
306
298
|
// test with same hovered object
|
|
307
|
-
|
|
308
|
-
toolBox['_raycaster'],
|
|
309
|
-
'intersectObjects',
|
|
310
|
-
).mockReturnValueOnce([
|
|
299
|
+
spy.mockReturnValue([
|
|
311
300
|
{
|
|
312
301
|
distance: 1,
|
|
313
302
|
point: {
|
|
@@ -357,17 +346,10 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
357
346
|
).not.toThrow();
|
|
358
347
|
|
|
359
348
|
// test with different hovered object
|
|
360
|
-
|
|
361
|
-
toolBox['_raycaster'],
|
|
362
|
-
'intersectObjects',
|
|
363
|
-
).mockReturnValueOnce([
|
|
349
|
+
spy.mockReturnValue([
|
|
364
350
|
{
|
|
365
351
|
distance: 1,
|
|
366
|
-
point:
|
|
367
|
-
x: 1,
|
|
368
|
-
y: 1,
|
|
369
|
-
z: 1,
|
|
370
|
-
} as unknown as Vector3,
|
|
352
|
+
point: new Vector3(1, 1, 1),
|
|
371
353
|
object: {
|
|
372
354
|
uuid: 'uuid2',
|
|
373
355
|
isHoverable: true,
|
|
@@ -457,6 +439,8 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
457
439
|
offsetY: 100,
|
|
458
440
|
} as PointerEvent),
|
|
459
441
|
).not.toThrow();
|
|
442
|
+
|
|
443
|
+
spy.mockRestore();
|
|
460
444
|
});
|
|
461
445
|
|
|
462
446
|
it('should execute onPointerUp correctly', () => {
|
|
@@ -527,6 +511,10 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
527
511
|
expect(() => toolBox.onDragStart({} as PointerEvent)).not.toThrow();
|
|
528
512
|
|
|
529
513
|
toolBox['_dragRaycastOnObjects'] = [];
|
|
514
|
+
jest.spyOn(
|
|
515
|
+
toolBox['_raycaster'],
|
|
516
|
+
'intersectObjects',
|
|
517
|
+
).mockReturnValueOnce([]);
|
|
530
518
|
expect(() => toolBox.onDragStart({} as PointerEvent)).not.toThrow();
|
|
531
519
|
|
|
532
520
|
jest.spyOn(
|
|
@@ -569,6 +557,10 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
569
557
|
return;
|
|
570
558
|
},
|
|
571
559
|
} as unknown as Object3D & DIVEDraggable;
|
|
560
|
+
jest.spyOn(
|
|
561
|
+
toolBox['_raycaster'],
|
|
562
|
+
'intersectObjects',
|
|
563
|
+
).mockReturnValueOnce([]);
|
|
572
564
|
expect(() => toolBox.onDragStart({} as PointerEvent)).not.toThrow();
|
|
573
565
|
});
|
|
574
566
|
|
|
@@ -577,6 +569,10 @@ describe('dive/toolbox/DIVEBaseTool', () => {
|
|
|
577
569
|
expect(() => toolBox.onDrag({} as PointerEvent)).not.toThrow();
|
|
578
570
|
|
|
579
571
|
toolBox['_dragRaycastOnObjects'] = [];
|
|
572
|
+
jest.spyOn(
|
|
573
|
+
toolBox['_raycaster'],
|
|
574
|
+
'intersectObjects',
|
|
575
|
+
).mockReturnValueOnce([]);
|
|
580
576
|
expect(() => toolBox.onDrag({} as PointerEvent)).not.toThrow();
|
|
581
577
|
|
|
582
578
|
toolBox['_draggable'] = {
|
|
@@ -9,13 +9,6 @@ import { type DIVEBaseTool } from '../../BaseTool';
|
|
|
9
9
|
import { DIVEAnimationSystem } from '../../../animation/AnimationSystem';
|
|
10
10
|
import { Tween } from '@tweenjs/tween.js';
|
|
11
11
|
|
|
12
|
-
jest.mock('@tweenjs/tween.js', () => {
|
|
13
|
-
return {
|
|
14
|
-
Tween: jest.fn(() => {}),
|
|
15
|
-
update: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
12
|
jest.mock('../../../renderer/Renderer', () => {
|
|
20
13
|
return jest.fn(function () {
|
|
21
14
|
return this;
|
|
@@ -76,74 +69,6 @@ jest.mock('../../../scene/Scene', () => {
|
|
|
76
69
|
};
|
|
77
70
|
});
|
|
78
71
|
|
|
79
|
-
const mock_intersectObjects = jest.fn().mockReturnValue([]);
|
|
80
|
-
|
|
81
|
-
jest.mock('three', () => {
|
|
82
|
-
return {
|
|
83
|
-
Vector2: jest.fn(function () {
|
|
84
|
-
return this;
|
|
85
|
-
}),
|
|
86
|
-
Vector3: jest.fn(function () {
|
|
87
|
-
return this;
|
|
88
|
-
}),
|
|
89
|
-
Raycaster: jest.fn(function () {
|
|
90
|
-
this.setFromCamera = jest.fn();
|
|
91
|
-
this.intersectObjects = mock_intersectObjects;
|
|
92
|
-
this.layers = {
|
|
93
|
-
mask: 0,
|
|
94
|
-
};
|
|
95
|
-
return this;
|
|
96
|
-
}),
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const mock_attach = jest.fn();
|
|
101
|
-
const mock_detach = jest.fn();
|
|
102
|
-
|
|
103
|
-
jest.mock('three/examples/jsm/controls/TransformControls', () => {
|
|
104
|
-
return {
|
|
105
|
-
TransformControls: jest.fn(function () {
|
|
106
|
-
this.isTransformControls = true;
|
|
107
|
-
this.addEventListener = jest.fn(
|
|
108
|
-
(type: string, callback: (e: object) => void) => {
|
|
109
|
-
callback({ value: false });
|
|
110
|
-
this.object = {};
|
|
111
|
-
callback({ value: false });
|
|
112
|
-
this.object = {
|
|
113
|
-
onMove: 'hello',
|
|
114
|
-
};
|
|
115
|
-
callback({ value: false });
|
|
116
|
-
this.object = {
|
|
117
|
-
onMove: jest.fn(),
|
|
118
|
-
};
|
|
119
|
-
callback({ value: false });
|
|
120
|
-
},
|
|
121
|
-
);
|
|
122
|
-
this.attach = jest.fn((object) => {
|
|
123
|
-
this.object = object;
|
|
124
|
-
});
|
|
125
|
-
this.detach = jest.fn(() => {
|
|
126
|
-
this.object = null;
|
|
127
|
-
});
|
|
128
|
-
this.traverse = function (callback: (obj: object) => void) {
|
|
129
|
-
callback(this);
|
|
130
|
-
};
|
|
131
|
-
this.setMode = jest.fn();
|
|
132
|
-
this.getRaycaster = jest.fn().mockReturnValue({
|
|
133
|
-
layers: {
|
|
134
|
-
mask: 0,
|
|
135
|
-
disableAll: jest.fn(),
|
|
136
|
-
enableAll: jest.fn(),
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
this.layers = {
|
|
140
|
-
mask: 0,
|
|
141
|
-
};
|
|
142
|
-
return this;
|
|
143
|
-
}),
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
|
|
147
72
|
const mockCamera: DIVEPerspectiveCamera = {} as DIVEPerspectiveCamera;
|
|
148
73
|
const mockRenderer = {
|
|
149
74
|
render: jest.fn(),
|
|
@@ -157,24 +82,31 @@ const mockController: DIVEOrbitControls = new DIVEOrbitControls(
|
|
|
157
82
|
mockAnimSystem,
|
|
158
83
|
);
|
|
159
84
|
|
|
85
|
+
let selectTool: DIVESelectTool;
|
|
86
|
+
let intersectObjectsSpy: jest.SpyInstance;
|
|
87
|
+
|
|
160
88
|
describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
selectTool = new DIVESelectTool(mockScene, mockController);
|
|
91
|
+
intersectObjectsSpy = jest
|
|
92
|
+
.spyOn(selectTool['_raycaster'], 'intersectObjects')
|
|
93
|
+
.mockReturnValue([]);
|
|
94
|
+
});
|
|
95
|
+
|
|
161
96
|
it('should test if it is SelectTool', () => {
|
|
162
97
|
const selectTool = { isSelectTool: true } as unknown as DIVEBaseTool;
|
|
163
98
|
expect(isSelectTool(selectTool)).toBeDefined();
|
|
164
99
|
});
|
|
165
100
|
|
|
166
101
|
it('should instantiate', () => {
|
|
167
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
168
102
|
expect(selectTool).toBeDefined();
|
|
169
103
|
});
|
|
170
104
|
|
|
171
105
|
it('should activate', () => {
|
|
172
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
173
106
|
expect(() => selectTool.Activate()).not.toThrow();
|
|
174
107
|
});
|
|
175
108
|
|
|
176
109
|
it('should execute onClick without hit', () => {
|
|
177
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
178
110
|
selectTool.AttachGizmo({} as unknown as DIVESelectable);
|
|
179
111
|
expect(() =>
|
|
180
112
|
selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
|
|
@@ -182,7 +114,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
182
114
|
});
|
|
183
115
|
|
|
184
116
|
it('should execute onClick with hit', () => {
|
|
185
|
-
|
|
117
|
+
intersectObjectsSpy.mockReturnValueOnce([
|
|
186
118
|
{
|
|
187
119
|
object: {
|
|
188
120
|
uuid: 'test',
|
|
@@ -194,7 +126,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
194
126
|
},
|
|
195
127
|
},
|
|
196
128
|
]);
|
|
197
|
-
|
|
129
|
+
|
|
198
130
|
expect(() =>
|
|
199
131
|
selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
|
|
200
132
|
).not.toThrow();
|
|
@@ -203,7 +135,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
203
135
|
it('should execute onClick with same ISelectable hit', () => {
|
|
204
136
|
const mock_onSelect = jest.fn();
|
|
205
137
|
|
|
206
|
-
|
|
138
|
+
intersectObjectsSpy.mockReturnValueOnce([
|
|
207
139
|
{
|
|
208
140
|
object: {
|
|
209
141
|
isSelectable: true,
|
|
@@ -217,7 +149,6 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
217
149
|
},
|
|
218
150
|
},
|
|
219
151
|
]);
|
|
220
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
221
152
|
selectTool.AttachGizmo({
|
|
222
153
|
visible: true,
|
|
223
154
|
isSelectable: true,
|
|
@@ -231,7 +162,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
231
162
|
it('should execute onClick with ISelectable hit', () => {
|
|
232
163
|
const mock_onSelect = jest.fn();
|
|
233
164
|
|
|
234
|
-
|
|
165
|
+
intersectObjectsSpy.mockReturnValueOnce([
|
|
235
166
|
{
|
|
236
167
|
object: {
|
|
237
168
|
isSelectable: true,
|
|
@@ -245,7 +176,6 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
245
176
|
},
|
|
246
177
|
},
|
|
247
178
|
]);
|
|
248
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
249
179
|
selectTool.AttachGizmo({
|
|
250
180
|
isSelectable: true,
|
|
251
181
|
uuid: 'test1',
|
|
@@ -258,7 +188,7 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
258
188
|
it('should execute onClick with IMovable hit', () => {
|
|
259
189
|
const mock_onSelect = jest.fn();
|
|
260
190
|
|
|
261
|
-
|
|
191
|
+
intersectObjectsSpy.mockReturnValueOnce([
|
|
262
192
|
{
|
|
263
193
|
object: {
|
|
264
194
|
isSelectable: true,
|
|
@@ -271,14 +201,13 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
271
201
|
},
|
|
272
202
|
},
|
|
273
203
|
]);
|
|
274
|
-
|
|
204
|
+
|
|
275
205
|
expect(() =>
|
|
276
206
|
selectTool.onClick({ offsetX: 0, offsetY: 0 } as PointerEvent),
|
|
277
207
|
).not.toThrow();
|
|
278
208
|
});
|
|
279
209
|
|
|
280
210
|
it('should Select', () => {
|
|
281
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
282
211
|
const mock_onSelect = jest.fn();
|
|
283
212
|
expect(() => selectTool.Select({ isSelectable: true })).not.toThrow();
|
|
284
213
|
expect(() =>
|
|
@@ -291,7 +220,6 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
291
220
|
});
|
|
292
221
|
|
|
293
222
|
it('should Deselect', () => {
|
|
294
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
295
223
|
const mock_onDeselect = jest.fn();
|
|
296
224
|
expect(() => selectTool.Deselect({ isSelectable: true })).not.toThrow();
|
|
297
225
|
expect(() =>
|
|
@@ -304,7 +232,6 @@ describe('dive/toolbox/select/DIVESelectTool', () => {
|
|
|
304
232
|
});
|
|
305
233
|
|
|
306
234
|
it('should set gizmo mode', () => {
|
|
307
|
-
const selectTool = new DIVESelectTool(mockScene, mockController);
|
|
308
235
|
expect(() => selectTool.SetGizmoMode('translate')).not.toThrow();
|
|
309
236
|
});
|
|
310
237
|
});
|