From 294ec9fc2c082e3bbf0c06152ca246242d8a2e16 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 11 Jan 2024 14:33:25 +0100 Subject: [PATCH] Add test cases #1234 --- .../codeMap.mouseEvent.service.spec.ts | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/visualization/app/codeCharta/ui/codeMap/codeMap.mouseEvent.service.spec.ts b/visualization/app/codeCharta/ui/codeMap/codeMap.mouseEvent.service.spec.ts index d48edaf152c..ebdb9ede16c 100644 --- a/visualization/app/codeCharta/ui/codeMap/codeMap.mouseEvent.service.spec.ts +++ b/visualization/app/codeCharta/ui/codeMap/codeMap.mouseEvent.service.spec.ts @@ -846,12 +846,50 @@ describe("codeMapMouseEventService", () => { }) describe("labelForSelectedBuilding", () => { - it("should create a label when clicking on a building", () => {}) + it("should create a label when selecting a building", () => { + threeSceneService.getLabelForHoveredNode = jest.fn() + threeSceneService.animateLabel = jest.fn() + codeMapLabelService.addLeafLabel = jest.fn() - it("should remove the label when the building is unselected", () => {}) + codeMapMouseEventService["drawLabelForSelected"](codeMapBuilding) + + expect(threeSceneService.getLabelForHoveredNode).toHaveBeenCalled() + expect(codeMapLabelService.addLeafLabel).toHaveBeenCalledWith(codeMapBuilding.node, 0, true) + expect(codeMapMouseEventService["temporaryLabelForSelectedBuilding"]).toEqual(codeMapBuilding.node) + }) + + it("should remove the label when a previously selected building is unselected", () => { + threeSceneService.getLabelForHoveredNode = jest.fn() + threeSceneService.animateLabel = jest.fn() + codeMapLabelService.clearTemporaryLabel = jest.fn() + codeMapMouseEventService["drawLabelForSelected"](codeMapBuilding) - it("should remove the old and create the new label when selected building is changed", () => {}) + codeMapMouseEventService["clearLabelForSelected"]() - it("should keep the label when clicking on the already selected building", () => {}) + expect(codeMapLabelService.clearTemporaryLabel).toHaveBeenCalledWith(codeMapBuilding.node) + expect(codeMapMouseEventService["temporaryLabelForSelectedBuilding"]).toBeNull() + }) + + it("should remove the old and create the new label when selected building is changed", () => { + //TODO we need two buildings for this, check if we have two in the mocks + }) + + it("should keep the label when clicking on the already selected building", () => { + threeSceneService.getLabelForHoveredNode = jest.fn() + threeSceneService.animateLabel = jest.fn() + codeMapMouseEventService["clearTemporaryLabel"] = jest.fn() + codeMapMouseEventService["drawLabelForSelected"] = jest.fn() + + codeMapMouseEventService["drawLabelForSelected"](codeMapBuilding) + const referenceLabel = codeMapMouseEventService["temporaryLabelForSelectedBuilding"] + codeMapMouseEventService["intersectedBuilding"] = codeMapBuilding + + codeMapMouseEventService["onLeftClick"]() + + expect(codeMapMouseEventService["drawLabelForSelected"]).toHaveBeenCalledWith(codeMapBuilding) + expect(codeMapMouseEventService["drawLabelForSelected"]).toHaveBeenCalledTimes(2) + expect(codeMapMouseEventService["clearTemporaryLabel"]).not.toHaveBeenCalled() + expect(codeMapMouseEventService["temporaryLabelForSelectedBuilding"]).toEqual(referenceLabel) + }) }) })