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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests #3890
  • Loading branch information
BenediktMehl committed Jan 28, 2025
commit f3f137a1ae5286eabbaa1d8562c6c713d254ebfa
65 changes: 65 additions & 0 deletions visualization/app/codeCharta/util/customConfigHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
})