From d91bccfbe9b2c644eb34ab76ed30c6a842d8a2ab Mon Sep 17 00:00:00 2001 From: Benedikt Mehl Date: Tue, 28 Jan 2025 18:45:44 +0100 Subject: [PATCH 1/3] Fix bug #3890 --- visualization/app/codeCharta/util/customConfigHelper.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/visualization/app/codeCharta/util/customConfigHelper.ts b/visualization/app/codeCharta/util/customConfigHelper.ts index 11021bf908..f396f82b87 100644 --- a/visualization/app/codeCharta/util/customConfigHelper.ts +++ b/visualization/app/codeCharta/util/customConfigHelper.ts @@ -15,6 +15,7 @@ import { BehaviorSubject } from "rxjs" import { VisibleFilesBySelectionMode } from "../ui/customConfigs/visibleFilesBySelectionMode.selector" import { Store } from "@ngrx/store" import { ThreeRendererService } from "../ui/codeMap/threeViewer/threeRenderer.service" +import { setState } from "../state/store/state.actions" export const CUSTOM_CONFIG_FILE_EXTENSION = ".cc.config.json" const CUSTOM_CONFIGS_LOCAL_STORAGE_VERSION = "1.0.1" @@ -191,13 +192,14 @@ export class CustomConfigHelper { static applyCustomConfig( configId: string, - // biome-ignore lint/correctness/noUnusedVariables: store: Store, threeCameraService: ThreeCameraService, threeOrbitControlsService: ThreeMapControlsService, threeRendererService: ThreeRendererService ) { const customConfig = this.getCustomConfigSettings(configId) + store.dispatch(setState({ value: customConfig.stateSettings })) + if (customConfig.camera) { threeCameraService.setPosition(customConfig.camera.camera) threeOrbitControlsService.setControlTarget(customConfig.camera.cameraTarget) From f3f137a1ae5286eabbaa1d8562c6c713d254ebfa Mon Sep 17 00:00:00 2001 From: Benedikt Mehl Date: Tue, 28 Jan 2025 18:59:18 +0100 Subject: [PATCH 2/3] Add tests #3890 --- .../util/customConfigHelper.spec.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/visualization/app/codeCharta/util/customConfigHelper.spec.ts b/visualization/app/codeCharta/util/customConfigHelper.spec.ts index 2419ae8878..2a16bedb08 100644 --- a/visualization/app/codeCharta/util/customConfigHelper.spec.ts +++ b/visualization/app/codeCharta/util/customConfigHelper.spec.ts @@ -11,6 +11,12 @@ import { CustomConfigItemGroup } from "../ui/customConfigs/customConfigs.compone import { klona } from "klona" import { stubDate } from "../../../mocks/dateMock.helper" import { FileDownloader } from "./fileDownloader" +import { Vector3 } from "three/src/math/Vector3" +import { Store } from "@ngrx/store" +import { ThreeCameraService } from "../ui/codeMap/threeViewer/threeCamera.service" +import { ThreeMapControlsService } from "../ui/codeMap/threeViewer/threeMapControls.service" +import { ThreeRendererService } from "../ui/codeMap/threeViewer/threeRenderer.service" +import { setState } from "../state/store/state.actions" describe("CustomConfigHelper", () => { beforeEach(() => { @@ -439,4 +445,63 @@ describe("CustomConfigHelper", () => { expect(FileDownloader.downloadData).toHaveBeenCalledWith("mock_serialized_config_to_be_downloaded", `${newDate}.cc.config.json`) }) }) + + describe("applyCustomConfig", () => { + let customConfigMock: CustomConfig + let store: Store + let threeCameraService: ThreeCameraService + let threeOrbitControlsService: ThreeMapControlsService + let threeRendererService: ThreeRendererService + + beforeEach(() => { + customConfigMock = { + stateSettings: { + appSettings: {}, + dynamicSettings: {}, + fileSettings: {} + }, + camera: { + camera: new Vector3(1, 2, 3), + cameraTarget: new Vector3(4, 5, 6) + } + } as CustomConfig + + store = { + dispatch: jest.fn() + } as unknown as Store + + threeCameraService = { + setPosition: jest.fn() + } as unknown as ThreeCameraService + + threeOrbitControlsService = { + setControlTarget: jest.fn() + } as unknown as ThreeMapControlsService + + threeRendererService = { + render: jest.fn() + } as unknown as ThreeRendererService + + jest.spyOn(CustomConfigHelper, "getCustomConfigSettings").mockReturnValue(customConfigMock) + }) + + it("should dispatch stateSettings to the store", () => { + CustomConfigHelper.applyCustomConfig("testId", store, threeCameraService, threeOrbitControlsService, threeRendererService) + + expect(store.dispatch).toHaveBeenCalledWith(setState({ value: customConfigMock.stateSettings })) + }) + + it("should update camera position and orbit controls target", () => { + CustomConfigHelper.applyCustomConfig("testId", store, threeCameraService, threeOrbitControlsService, threeRendererService) + + expect(threeCameraService.setPosition).toHaveBeenCalledWith(customConfigMock.camera.camera) + expect(threeOrbitControlsService.setControlTarget).toHaveBeenCalledWith(customConfigMock.camera.cameraTarget) + }) + + it("should trigger a render in the renderer service", () => { + CustomConfigHelper.applyCustomConfig("testId", store, threeCameraService, threeOrbitControlsService, threeRendererService) + + expect(threeRendererService.render).toHaveBeenCalled() + }) + }) }) From 557aa76aa9811441dfda0ef72ecc54d1e78cc558 Mon Sep 17 00:00:00 2001 From: Benedikt Mehl Date: Tue, 28 Jan 2025 19:10:49 +0100 Subject: [PATCH 3/3] Update changelog #3890 --- visualization/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/visualization/CHANGELOG.md b/visualization/CHANGELOG.md index e4cc751411..18fa500386 100644 --- a/visualization/CHANGELOG.md +++ b/visualization/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/) - Increased the size of the color quantile diagram [#3827](https://github.com/MaibornWolff/codecharta/pull/3827) +### Fixed 🐞 + +- Fix applying Custom Views [#3898](https://github.com/MaibornWolff/codecharta/pull/3898) + ## [1.131.2] - 2024-12-04 ### Fixed 🐞