@@ -11,6 +11,12 @@ import { CustomConfigItemGroup } from "../ui/customConfigs/customConfigs.compone
11
11
import { klona } from "klona"
12
12
import { stubDate } from "../../../mocks/dateMock.helper"
13
13
import { FileDownloader } from "./fileDownloader"
14
+ import { Vector3 } from "three/src/math/Vector3"
15
+ import { Store } from "@ngrx/store"
16
+ import { ThreeCameraService } from "../ui/codeMap/threeViewer/threeCamera.service"
17
+ import { ThreeMapControlsService } from "../ui/codeMap/threeViewer/threeMapControls.service"
18
+ import { ThreeRendererService } from "../ui/codeMap/threeViewer/threeRenderer.service"
19
+ import { setState } from "../state/store/state.actions"
14
20
15
21
describe ( "CustomConfigHelper" , ( ) => {
16
22
beforeEach ( ( ) => {
@@ -439,4 +445,63 @@ describe("CustomConfigHelper", () => {
439
445
expect ( FileDownloader . downloadData ) . toHaveBeenCalledWith ( "mock_serialized_config_to_be_downloaded" , `${ newDate } .cc.config.json` )
440
446
} )
441
447
} )
448
+
449
+ describe ( "applyCustomConfig" , ( ) => {
450
+ let customConfigMock : CustomConfig
451
+ let store : Store
452
+ let threeCameraService : ThreeCameraService
453
+ let threeOrbitControlsService : ThreeMapControlsService
454
+ let threeRendererService : ThreeRendererService
455
+
456
+ beforeEach ( ( ) => {
457
+ customConfigMock = {
458
+ stateSettings : {
459
+ appSettings : { } ,
460
+ dynamicSettings : { } ,
461
+ fileSettings : { }
462
+ } ,
463
+ camera : {
464
+ camera : new Vector3 ( 1 , 2 , 3 ) ,
465
+ cameraTarget : new Vector3 ( 4 , 5 , 6 )
466
+ }
467
+ } as CustomConfig
468
+
469
+ store = {
470
+ dispatch : jest . fn ( )
471
+ } as unknown as Store
472
+
473
+ threeCameraService = {
474
+ setPosition : jest . fn ( )
475
+ } as unknown as ThreeCameraService
476
+
477
+ threeOrbitControlsService = {
478
+ setControlTarget : jest . fn ( )
479
+ } as unknown as ThreeMapControlsService
480
+
481
+ threeRendererService = {
482
+ render : jest . fn ( )
483
+ } as unknown as ThreeRendererService
484
+
485
+ jest . spyOn ( CustomConfigHelper , "getCustomConfigSettings" ) . mockReturnValue ( customConfigMock )
486
+ } )
487
+
488
+ it ( "should dispatch stateSettings to the store" , ( ) => {
489
+ CustomConfigHelper . applyCustomConfig ( "testId" , store , threeCameraService , threeOrbitControlsService , threeRendererService )
490
+
491
+ expect ( store . dispatch ) . toHaveBeenCalledWith ( setState ( { value : customConfigMock . stateSettings } ) )
492
+ } )
493
+
494
+ it ( "should update camera position and orbit controls target" , ( ) => {
495
+ CustomConfigHelper . applyCustomConfig ( "testId" , store , threeCameraService , threeOrbitControlsService , threeRendererService )
496
+
497
+ expect ( threeCameraService . setPosition ) . toHaveBeenCalledWith ( customConfigMock . camera . camera )
498
+ expect ( threeOrbitControlsService . setControlTarget ) . toHaveBeenCalledWith ( customConfigMock . camera . cameraTarget )
499
+ } )
500
+
501
+ it ( "should trigger a render in the renderer service" , ( ) => {
502
+ CustomConfigHelper . applyCustomConfig ( "testId" , store , threeCameraService , threeOrbitControlsService , threeRendererService )
503
+
504
+ expect ( threeRendererService . render ) . toHaveBeenCalled ( )
505
+ } )
506
+ } )
442
507
} )
0 commit comments