Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/3890/custom view broken #3898

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions visualization/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🐞
Expand Down
65 changes: 65 additions & 0 deletions visualization/app/codeCharta/util/customConfigHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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()
})
})
})
4 changes: 3 additions & 1 deletion visualization/app/codeCharta/util/customConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -191,13 +192,14 @@ export class CustomConfigHelper {

static applyCustomConfig(
configId: string,
// biome-ignore lint/correctness/noUnusedVariables: <explanation>
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)
Expand Down