Skip to content

Commit

Permalink
#3mf Add unit test for updating number of colors in 3D print dialog o…
Browse files Browse the repository at this point in the history
…n printer change
  • Loading branch information
VictoriaG authored and phanlezz committed Jun 10, 2024
1 parent 273f87c commit 0359929
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ThreeSceneService } from "../../codeMap/threeViewer/threeSceneService"
import { DEFAULT_STATE, TEST_NODES } from "../../../util/dataMocks"
import { CodeMapMesh } from "../../codeMap/rendering/codeMapMesh"
import { defaultState } from "../../../state/store/state.manager"
import { Vector3 } from "three"

describe("Export3DMapDialogComponent", () => {
beforeEach(() => {
Expand All @@ -30,5 +31,46 @@ describe("Export3DMapDialogComponent", () => {
expect(dialog).not.toBe(null)
})

// Add more test cases as needed
it("should update number of colors on printer change", async () => {
const { fixture } = await render(Export3DMapDialogComponent, { excludeComponentDeclaration: true })

const component = fixture.componentInstance
const threeSceneService = TestBed.inject(ThreeSceneService)

const updateNumberOfColorsMock = jest.fn()
const updateSizeMock = jest.fn()
const getSizeMock = jest.fn().mockReturnValue(new Vector3(10, 10, 10))
Object.defineProperty(component, "previewMesh", {
value: {
updateNumberOfColors: updateNumberOfColorsMock,
updateSize: updateSizeMock,
getSize: getSizeMock,
printMesh: { traverse: jest.fn() },
mapMesh: { geometry: {} },
updateMapColors: jest.fn(),
updateColor: jest.fn()
},
writable: true
})
const cameraMock = {
position: {
set: jest.fn()
}
}
Object.defineProperty(component, "printPreviewScene", {
value: {
getObjectByName: jest.fn().mockReturnValue(cameraMock)
},
writable: true
})

component.selectedPrinter = component.printers[1]

component.onSelectedPrinterChange()

expect(threeSceneService.getMapMesh).toHaveBeenCalled()
expect(updateNumberOfColorsMock).toHaveBeenCalled()
expect(component["currentNumberOfColors"]).toBe(component.selectedPrinter.numberOfColors)
expect(cameraMock.position.set).toHaveBeenCalled()
})
})

0 comments on commit 0359929

Please sign in to comment.