|
1 | 1 | /** |
2 | 2 | * @jest-environment jsdom |
3 | 3 | */ |
4 | | -/* eslint-disable @typescript-eslint/no-unused-vars */ |
5 | | -/* eslint-disable @typescript-eslint/no-empty-function */ |
6 | 4 | import { initBabylonJS } from "./scene-helper"; |
7 | 5 | import { BabylonJSScene } from "../../inputs/babylon-scene-helper-inputs"; |
8 | 6 | import { BabylonCamera } from "../../inputs/babylon-camera-inputs"; |
| 7 | +import { MockMeshType } from "../../__mocks__/babylonjs.mock"; |
9 | 8 |
|
10 | | -// Type definitions for mock objects |
11 | | -interface MockVector3Type { |
12 | | - x: number; |
13 | | - y: number; |
14 | | - z: number; |
15 | | - set(x: number, y: number, z: number): void; |
16 | | -} |
17 | | - |
18 | | -interface MockColor3Type { |
19 | | - r: number; |
20 | | - g: number; |
21 | | - b: number; |
22 | | -} |
23 | | - |
24 | | -interface MockColor4Type { |
25 | | - r: number; |
26 | | - g: number; |
27 | | - b: number; |
28 | | - a: number; |
29 | | -} |
30 | | - |
31 | | -interface MockMeshType { |
32 | | - name: string; |
33 | | - position: MockVector3Type; |
34 | | - receiveShadows: boolean; |
35 | | - material: object | null; |
36 | | - _groundWidth?: number; |
37 | | - _groundHeight?: number; |
38 | | -} |
39 | | - |
40 | | -// Mock BabylonJS core module |
| 9 | +// Mock BabylonJS core module using centralized mocks |
41 | 10 | jest.mock("@babylonjs/core", () => { |
42 | | - const actualMock = jest.requireActual("../../__mocks__/babylonjs.mock"); |
43 | | - |
44 | | - class MockEngine { |
45 | | - _canvas: HTMLCanvasElement; |
46 | | - _renderLoop: (() => void) | null = null; |
47 | | - |
48 | | - constructor(canvas: HTMLCanvasElement, _antialias?: boolean, _options?: object) { |
49 | | - this._canvas = canvas; |
50 | | - } |
51 | | - |
52 | | - setHardwareScalingLevel(_level: number) { /* mock */ } |
53 | | - |
54 | | - resize() { /* mock */ } |
55 | | - |
56 | | - runRenderLoop(callback: () => void) { |
57 | | - this._renderLoop = callback; |
58 | | - } |
59 | | - |
60 | | - stopRenderLoop() { |
61 | | - this._renderLoop = null; |
62 | | - } |
63 | | - |
64 | | - dispose() { /* mock */ } |
65 | | - } |
66 | | - |
67 | | - class MockBabylonScene { |
68 | | - _meshes: MockMeshType[] = []; |
69 | | - metadata: { shadowGenerators: MockShadowGenerator[] } = { shadowGenerators: [] }; |
70 | | - clearColor: MockColor4Type | null = null; |
71 | | - activeCamera: MockArcRotateCamera | null = null; |
72 | | - |
73 | | - dispose() { /* mock */ } |
74 | | - render() { /* mock */ } |
75 | | - } |
76 | | - |
77 | | - class MockHemisphericLight { |
78 | | - name: string; |
79 | | - direction: MockVector3Type; |
80 | | - diffuse: MockColor3Type; |
81 | | - groundColor: MockColor3Type; |
82 | | - intensity = 1; |
83 | | - |
84 | | - constructor(name: string, direction: MockVector3Type, _scene: MockBabylonScene) { |
85 | | - this.name = name; |
86 | | - this.direction = direction; |
87 | | - this.diffuse = new actualMock.MockColor3(1, 1, 1); |
88 | | - this.groundColor = new actualMock.MockColor3(0.5, 0.5, 0.5); |
89 | | - } |
90 | | - |
91 | | - dispose() { /* mock */ } |
92 | | - } |
93 | | - |
94 | | - class MockDirectionalLight { |
95 | | - name: string; |
96 | | - direction: MockVector3Type; |
97 | | - position: MockVector3Type; |
98 | | - diffuse: MockColor3Type; |
99 | | - intensity = 1; |
100 | | - |
101 | | - constructor(name: string, direction: MockVector3Type, _scene: MockBabylonScene) { |
102 | | - this.name = name; |
103 | | - this.direction = direction; |
104 | | - this.position = new actualMock.MockVector3(); |
105 | | - this.diffuse = new actualMock.MockColor3(1, 1, 1); |
106 | | - } |
107 | | - |
108 | | - dispose() { /* mock */ } |
109 | | - } |
110 | | - |
111 | | - class MockShadowGenerator { |
112 | | - useBlurExponentialShadowMap = false; |
113 | | - blurKernel = 0; |
114 | | - darkness = 0; |
115 | | - |
116 | | - constructor(_mapSize: number, _light: MockDirectionalLight) { /* mock */ } |
117 | | - } |
118 | | - |
119 | | - class MockArcRotateCamera { |
120 | | - name: string; |
121 | | - alpha: number; |
122 | | - beta: number; |
123 | | - radius: number; |
124 | | - target: MockVector3Type; |
125 | | - angularSensibilityX = 1000; |
126 | | - angularSensibilityY = 1000; |
127 | | - lowerRadiusLimit: number | null = null; |
128 | | - upperRadiusLimit: number | null = null; |
129 | | - panningSensibility = 1000; |
130 | | - wheelPrecision = 3; |
131 | | - maxZ = 10000; |
132 | | - minZ = 0.1; |
133 | | - lowerBetaLimit: number | null = null; |
134 | | - upperBetaLimit: number | null = null; |
135 | | - lowerAlphaLimit: number | null = null; |
136 | | - upperAlphaLimit: number | null = null; |
137 | | - |
138 | | - constructor( |
139 | | - name: string, |
140 | | - alpha: number, |
141 | | - beta: number, |
142 | | - radius: number, |
143 | | - target: MockVector3Type, |
144 | | - scene: MockBabylonScene |
145 | | - ) { |
146 | | - this.name = name; |
147 | | - this.alpha = alpha; |
148 | | - this.beta = beta; |
149 | | - this.radius = radius; |
150 | | - this.target = target; |
151 | | - scene.activeCamera = this; |
152 | | - } |
153 | | - |
154 | | - attachControl(_canvas: HTMLCanvasElement, _noPreventDefault?: boolean) { /* mock */ } |
155 | | - dispose() { /* mock */ } |
156 | | - } |
157 | | - |
158 | | - const MockMeshBuilder = { |
159 | | - CreateGround: (name: string, options: { width: number; height: number }, _scene: MockBabylonScene) => { |
160 | | - const mesh = new actualMock.MockMesh(name, null) as MockMeshType; |
161 | | - mesh._groundWidth = options.width; |
162 | | - mesh._groundHeight = options.height; |
163 | | - mesh.receiveShadows = false; |
164 | | - return mesh; |
165 | | - } |
166 | | - }; |
167 | | - |
168 | | - const MockTools = { |
169 | | - ToRadians: (degrees: number) => degrees * (Math.PI / 180) |
170 | | - }; |
171 | | - |
172 | | - return { |
173 | | - Engine: MockEngine, |
174 | | - Scene: MockBabylonScene, |
175 | | - Vector3: actualMock.MockVector3, |
176 | | - Color3: actualMock.MockColor3, |
177 | | - Color4: actualMock.MockColor4, |
178 | | - HemisphericLight: MockHemisphericLight, |
179 | | - DirectionalLight: MockDirectionalLight, |
180 | | - ShadowGenerator: MockShadowGenerator, |
181 | | - ArcRotateCamera: MockArcRotateCamera, |
182 | | - MeshBuilder: MockMeshBuilder, |
183 | | - StandardMaterial: actualMock.MockStandardMaterial, |
184 | | - Tools: MockTools, |
185 | | - }; |
| 11 | + const { createSceneHelperMock } = jest.requireActual("../../__mocks__/babylonjs.mock"); |
| 12 | + return createSceneHelperMock(); |
186 | 13 | }); |
187 | 14 |
|
188 | 15 | describe("initBabylonJS unit tests", () => { |
|
0 commit comments