@@ -22,7 +22,12 @@ import { fireEvent, render } from "@testing-library/react";
2222import { clone } from "lodash" ;
2323import { useFrame } from "@react-three/fiber" ;
2424import { useTexture } from "@react-three/drei" ;
25- import { Quaternion } from "three" ;
25+ import {
26+ InstancedMesh as ThreeInstancedMesh ,
27+ Quaternion ,
28+ type Intersection ,
29+ type Raycaster ,
30+ } from "three" ;
2631import { fakePlant } from "../../../__test_support__/fake_state/resources" ;
2732import { INITIAL } from "../../config" ;
2833import {
@@ -202,6 +207,50 @@ describe("<PlantInstances />", () => {
202207 expect ( mockNavigate ) . not . toHaveBeenCalled ( ) ;
203208 } ) ;
204209
210+ const iconRaycast = ( p = fakeProps ( ) ) => {
211+ const wrapper = createRenderer ( < PlantInstances { ...p } /> ) ;
212+ const mesh = wrapper . root . findAll ( node =>
213+ ( node . type as string ) == "instancedMesh" ) [ 0 ] ;
214+ const raycast = mesh . props . raycast as (
215+ this : ThreeInstancedMesh ,
216+ raycaster : Raycaster ,
217+ intersects : Intersection [ ] ,
218+ ) => void ;
219+ unmountRenderer ( wrapper ) ;
220+ return raycast ;
221+ } ;
222+
223+ it . each ( [
224+ Mode . clickToAdd ,
225+ Mode . createPoint ,
226+ Mode . createWeed ,
227+ ] ) ( "allows %s raycasts through plant icons" , mode => {
228+ getModeSpy . mockReturnValue ( mode ) ;
229+ const defaultRaycast = jest . spyOn (
230+ ThreeInstancedMesh . prototype ,
231+ "raycast" ,
232+ ) ;
233+ const intersects : Intersection [ ] = [ ] ;
234+ const raycaster = { } as Raycaster ;
235+ iconRaycast ( ) . call ( { } as ThreeInstancedMesh , raycaster , intersects ) ;
236+ expect ( defaultRaycast ) . not . toHaveBeenCalled ( ) ;
237+ expect ( intersects ) . toEqual ( [ ] ) ;
238+ defaultRaycast . mockRestore ( ) ;
239+ } ) ;
240+
241+ it ( "keeps plant icon raycasts outside placement modes" , ( ) => {
242+ getModeSpy . mockReturnValue ( Mode . none ) ;
243+ const defaultRaycast = jest . spyOn (
244+ ThreeInstancedMesh . prototype ,
245+ "raycast" ,
246+ ) . mockImplementation ( ( ) => undefined ) ;
247+ const intersects : Intersection [ ] = [ ] ;
248+ const raycaster = { } as Raycaster ;
249+ iconRaycast ( ) . call ( { } as ThreeInstancedMesh , raycaster , intersects ) ;
250+ expect ( defaultRaycast ) . toHaveBeenCalledWith ( raycaster , intersects ) ;
251+ defaultRaycast . mockRestore ( ) ;
252+ } ) ;
253+
205254 it ( "doesn't navigate with missing instanceId" , ( ) => {
206255 setMockInstanceId ( undefined ) ;
207256 const p = fakeProps ( ) ;
0 commit comments