@@ -67,58 +67,68 @@ test("convertCircuitJsonTo3D should handle GLTF models", async () => {
6767 scene : 0 ,
6868 scenes : [ { nodes : [ 0 ] } ] ,
6969 nodes : [ { mesh : 0 } ] ,
70- meshes : [ {
71- primitives : [ {
72- attributes : { POSITION : 0 , NORMAL : 1 } ,
73- mode : 4 // TRIANGLES
74- } ]
75- } ] ,
70+ meshes : [
71+ {
72+ primitives : [
73+ {
74+ attributes : { POSITION : 0 , NORMAL : 1 } ,
75+ mode : 4 , // TRIANGLES
76+ } ,
77+ ] ,
78+ } ,
79+ ] ,
7680 accessors : [
7781 {
7882 bufferView : 0 ,
7983 componentType : 5126 , // FLOAT
8084 count : 3 ,
81- type : "VEC3"
85+ type : "VEC3" ,
8286 } ,
8387 {
8488 bufferView : 1 ,
8589 componentType : 5126 , // FLOAT
8690 count : 3 ,
87- type : "VEC3"
88- }
91+ type : "VEC3" ,
92+ } ,
8993 ] ,
9094 bufferViews : [
9195 {
9296 buffer : 0 ,
9397 byteOffset : 0 ,
94- byteLength : 36
98+ byteLength : 36 ,
9599 } ,
96100 {
97101 buffer : 0 ,
98102 byteOffset : 36 ,
99- byteLength : 36
100- }
103+ byteLength : 36 ,
104+ } ,
105+ ] ,
106+ buffers : [
107+ {
108+ byteLength : 72 ,
109+ uri :
110+ "data:application/octet-stream;base64," +
111+ btoa (
112+ String . fromCharCode (
113+ ...new Uint8Array (
114+ new Float32Array ( [
115+ // Triangle positions
116+ 0 , 0 , 0 , 1 , 0 , 0 , 0.5 , 1 , 0 ,
117+ // Triangle normals
118+ 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 ,
119+ ] ) . buffer ,
120+ ) ,
121+ ) ,
122+ ) ,
123+ } ,
101124 ] ,
102- buffers : [ {
103- byteLength : 72 ,
104- uri : "data:application/octet-stream;base64," + btoa (
105- String . fromCharCode ( ...new Uint8Array (
106- new Float32Array ( [
107- // Triangle positions
108- 0 , 0 , 0 , 1 , 0 , 0 , 0.5 , 1 , 0 ,
109- // Triangle normals
110- 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1
111- ] ) . buffer
112- ) )
113- )
114- } ]
115125 }
116126
117127 const originalFetch = globalThis . fetch
118128 globalThis . fetch = ( async ( url : string ) => {
119129 if ( url === "test://mock-model.gltf" ) {
120130 return new Response ( JSON . stringify ( mockGLTF ) , {
121- headers : { "Content-Type" : "application/json" }
131+ headers : { "Content-Type" : "application/json" } ,
122132 } )
123133 }
124134 throw new Error ( `Unexpected URL: ${ url } ` )
@@ -155,38 +165,52 @@ test("should position GLTF model correctly in 3D scene", async () => {
155165 scene : 0 ,
156166 scenes : [ { nodes : [ 0 ] } ] ,
157167 nodes : [ { mesh : 0 } ] ,
158- meshes : [ {
159- primitives : [ {
160- attributes : { POSITION : 0 } ,
161- mode : 4
162- } ]
163- } ] ,
164- accessors : [ {
165- bufferView : 0 ,
166- componentType : 5126 ,
167- count : 3 ,
168- type : "VEC3"
169- } ] ,
170- bufferViews : [ {
171- buffer : 0 ,
172- byteOffset : 0 ,
173- byteLength : 36
174- } ] ,
175- buffers : [ {
176- byteLength : 36 ,
177- uri : "data:application/octet-stream;base64," + btoa (
178- String . fromCharCode ( ...new Uint8Array (
179- new Float32Array ( [ 0 , 0 , 0 , 1 , 0 , 0 , 0.5 , 1 , 0 ] ) . buffer
180- ) )
181- )
182- } ]
168+ meshes : [
169+ {
170+ primitives : [
171+ {
172+ attributes : { POSITION : 0 } ,
173+ mode : 4 ,
174+ } ,
175+ ] ,
176+ } ,
177+ ] ,
178+ accessors : [
179+ {
180+ bufferView : 0 ,
181+ componentType : 5126 ,
182+ count : 3 ,
183+ type : "VEC3" ,
184+ } ,
185+ ] ,
186+ bufferViews : [
187+ {
188+ buffer : 0 ,
189+ byteOffset : 0 ,
190+ byteLength : 36 ,
191+ } ,
192+ ] ,
193+ buffers : [
194+ {
195+ byteLength : 36 ,
196+ uri :
197+ "data:application/octet-stream;base64," +
198+ btoa (
199+ String . fromCharCode (
200+ ...new Uint8Array (
201+ new Float32Array ( [ 0 , 0 , 0 , 1 , 0 , 0 , 0.5 , 1 , 0 ] ) . buffer ,
202+ ) ,
203+ ) ,
204+ ) ,
205+ } ,
206+ ] ,
183207 }
184208
185209 const originalFetch = globalThis . fetch
186210 globalThis . fetch = ( async ( url : string ) => {
187211 if ( url === "test://mock-model.gltf" ) {
188212 return new Response ( JSON . stringify ( mockGLTF ) , {
189- headers : { "Content-Type" : "application/json" }
213+ headers : { "Content-Type" : "application/json" } ,
190214 } )
191215 }
192216 throw new Error ( `Unexpected URL: ${ url } ` )
@@ -195,7 +219,6 @@ test("should position GLTF model correctly in 3D scene", async () => {
195219 try {
196220 const scene = await convertCircuitJsonTo3D ( circuitWithGltf as any )
197221
198-
199222 // Find the GLTF component box
200223 const gltfBox = scene . boxes . find ( ( box ) => box . meshType === "gltf" )
201224 expect ( gltfBox ) . toBeDefined ( )
@@ -212,7 +235,6 @@ test("should position GLTF model correctly in 3D scene", async () => {
212235 expect ( gltfBox ! . size . x ) . toBe ( 8 )
213236 expect ( gltfBox ! . size . y ) . toBe ( 3 )
214237 expect ( gltfBox ! . size . z ) . toBe ( 6 )
215-
216238 } finally {
217239 globalThis . fetch = originalFetch
218240 }
@@ -226,8 +248,11 @@ test("should fallback gracefully when GLTF loading fails", async () => {
226248 clearGLTFCache ( )
227249
228250 const originalFetch = globalThis . fetch
229- globalThis . fetch = ( async ( url : string | URL | Request , init ?: RequestInit ) => {
230- const urlStr = typeof url === 'string' ? url : url . toString ( )
251+ globalThis . fetch = ( async (
252+ url : string | URL | Request ,
253+ init ?: RequestInit ,
254+ ) => {
255+ const urlStr = typeof url === "string" ? url : url . toString ( )
231256 if ( urlStr === "test://mock-model.gltf" ) {
232257 throw new Error ( "Network error - GLTF not found" )
233258 }
@@ -241,7 +266,6 @@ test("should fallback gracefully when GLTF loading fails", async () => {
241266 expect ( scene . boxes ) . toBeInstanceOf ( Array )
242267 expect ( scene . boxes . length ) . toBeGreaterThan ( 0 )
243268
244-
245269 // Should have the board box (unaffected by GLTF error)
246270 const boardBox = scene . boxes . find ( ( box ) => box . size . y === 1.6 )
247271 expect ( boardBox ) . toBeDefined ( )
@@ -263,7 +287,6 @@ test("should fallback gracefully when GLTF loading fails", async () => {
263287 expect ( componentBox ! . size . x ) . toBe ( 8 )
264288 expect ( componentBox ! . size . y ) . toBe ( 3 )
265289 expect ( componentBox ! . size . z ) . toBe ( 6 )
266-
267290 } finally {
268291 globalThis . fetch = originalFetch
269292 }
0 commit comments