@@ -351,10 +351,100 @@ describe('ReactThreeTestRenderer Core', () => {
351351 expect ( renderer . toTree ( ) ) . toMatchSnapshot ( )
352352 } )
353353
354+ it ( 'correctly searches through multiple levels in regular objects' , async ( ) => {
355+ // Create a deep tree: group -> mesh -> mesh -> mesh
356+ const renderer = await ReactThreeTestRenderer . create (
357+ < group name = "root-group" >
358+ < mesh name = "level1-mesh" >
359+ < boxGeometry />
360+ < meshBasicMaterial color = "red" />
361+ < mesh name = "level2-mesh" >
362+ < boxGeometry />
363+ < meshBasicMaterial color = "green" />
364+ < mesh name = "level3-mesh" >
365+ < boxGeometry />
366+ < meshBasicMaterial color = "blue" />
367+ </ mesh >
368+ </ mesh >
369+ </ mesh >
370+ </ group > ,
371+ )
372+
373+ // Test from the root
374+ const allMeshes = renderer . scene . findAllByType ( 'Mesh' )
375+ expect ( allMeshes . length ) . toBe ( 3 ) // Should find all three meshes
376+
377+ // Test from an intermediate node
378+ const topMesh = renderer . scene . find ( ( node ) => node . props . name === 'level1-mesh' )
379+ const nestedMeshes = topMesh . findAllByType ( 'Mesh' )
380+ expect ( nestedMeshes . length ) . toBe ( 2 ) // Should find the two nested meshes
381+
382+ // Find a deeply nested mesh from an intermediate node by property
383+ const level3 = topMesh . find ( ( node ) => node . props . name === 'level3-mesh' )
384+ expect ( level3 ) . toBeDefined ( )
385+ expect ( level3 . type ) . toBe ( 'Mesh' )
386+ } )
387+
388+ it ( 'Can search from retrieved primitive Instance' , async ( ) => {
389+ const group = new THREE . Group ( )
390+ group . name = 'PrimitiveGroup'
391+
392+ const childMesh = new THREE . Mesh ( new THREE . BoxGeometry ( 1 , 1 , 1 ) , new THREE . MeshBasicMaterial ( { color : 'red' } ) )
393+ childMesh . name = 'PrimitiveChildMesh'
394+ group . add ( childMesh )
395+
396+ const nestedMesh = new THREE . Mesh ( new THREE . BoxGeometry ( 1 , 1 , 1 ) , new THREE . MeshBasicMaterial ( { color : 'red' } ) )
397+ nestedMesh . name = 'PrimitiveNestedChildMesh'
398+ childMesh . add ( nestedMesh )
399+
400+ const renderer = await ReactThreeTestRenderer . create ( < primitive object = { group } /> )
401+
402+ const foundGroup = renderer . scene . findByType ( 'Group' )
403+ const foundMesh = foundGroup . children [ 0 ]
404+ const foundNestedMesh = foundMesh . findByType ( 'Mesh' )
405+ expect ( foundNestedMesh ) . toBeDefined ( )
406+ } )
407+
354408 it ( 'root instance and refs return the same value' , async ( ) => {
355409 let refInst = null
356410 const renderer = await ReactThreeTestRenderer . create ( < mesh ref = { ( ref ) => ( refInst = ref ) } /> )
357411 const root = renderer . getInstance ( ) // this will be Mesh
358412 expect ( root ) . toEqual ( refInst )
359413 } )
414+
415+ it ( 'handles primitive objects and their children correctly in toGraph' , async ( ) => {
416+ // Create a component with both regular objects and primitives with children
417+ const PrimitiveTestComponent = ( ) => {
418+ // Create a THREE.js group with mesh children
419+ const group = new THREE . Group ( )
420+ group . name = 'PrimitiveGroup'
421+
422+ const childMesh = new THREE . Mesh ( new THREE . BoxGeometry ( 1 , 1 , 1 ) , new THREE . MeshBasicMaterial ( { color : 'red' } ) )
423+ childMesh . name = 'PrimitiveChildMesh'
424+ group . add ( childMesh )
425+
426+ // Add a nested group to test deeper hierarchies
427+ const nestedGroup = new THREE . Group ( )
428+ nestedGroup . name = 'NestedGroup'
429+ const nestedMesh = new THREE . Mesh ( new THREE . SphereGeometry ( 0.5 ) , new THREE . MeshBasicMaterial ( { color : 'blue' } ) )
430+ nestedMesh . name = 'NestedMesh'
431+ nestedGroup . add ( nestedMesh )
432+ group . add ( nestedGroup )
433+
434+ return (
435+ < >
436+ < mesh name = "RegularMesh" >
437+ < boxGeometry args = { [ 2 , 2 ] } />
438+ < meshBasicMaterial />
439+ </ mesh >
440+
441+ < primitive object = { group } />
442+ </ >
443+ )
444+ }
445+
446+ const renderer = await ReactThreeTestRenderer . create ( < PrimitiveTestComponent /> )
447+
448+ expect ( renderer . toGraph ( ) ) . toMatchSnapshot ( )
449+ } )
360450} )
0 commit comments