Skip to content

Commit

Permalink
Add tests, Remove dead code, Some refactoring #1716
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanenkoVladimir committed Apr 22, 2021
1 parent cdcf84d commit 5d06c7c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
Expand Up @@ -322,11 +322,15 @@ describe("CodeMapLabelService", () => {
codeMapLabelService.addLabel(otherSampleLeaf, { showNodeName: true, showNodeMetric: false })
threeSceneService.labels.children = generateSceneLabelChild(4)

threeSceneService["highlightedLineIndex"] = 5
threeSceneService["highlightedLine"] = new Object3D()
codeMapLabelService.clearTemporaryLabel(sampleLeaf)

expect(codeMapLabelService.dispose).toBeCalledWith(threeSceneService.labels.children)
expect(threeSceneService.labels.children.length).toEqual(2)
expect(codeMapLabelService["labels"][0].node).toEqual(otherSampleLeaf)
expect(threeSceneService["highlightedLineIndex"]).toEqual(-1)
expect(threeSceneService["highlightedLine"]).toEqual(null)
})

it("should not clear if no label exists for a given node", () => {
Expand Down
Expand Up @@ -19,7 +19,7 @@ import { CodeMapNode } from "../../../codeCharta.model"
import { setIdToBuilding } from "../../../state/store/lookUp/idToBuilding/idToBuilding.actions"
import { setIdToNode } from "../../../state/store/lookUp/idToNode/idToNode.actions"
import { setScaling } from "../../../state/store/appSettings/scaling/scaling.actions"
import {Box3, Geometry, Matrix4, Object3D, Raycaster, Vector3} from "three"
import {Box3, Geometry, Group, Material, Matrix4, Object3D, Raycaster, Vector3} from "three"

describe("ThreeSceneService", () => {
let threeSceneService: ThreeSceneService
Expand Down Expand Up @@ -316,6 +316,90 @@ describe("ThreeSceneService", () => {
})
})

describe("resetLineHighlight", () => {
it("should reset line highlighting", () => {
threeSceneService["highlightedLineIndex"] = 5
threeSceneService["highlightedLine"] = new Object3D()

threeSceneService.resetLineHighlight()

expect(threeSceneService["highlightedLineIndex"]).toEqual(-1)
expect(threeSceneService["highlightedLine"]).toEqual(null)
})
})

describe("getHoveredLabelLineIndex", () => {
it("should return index+1 if found", () => {
const labels = []
const label1 = new Object3D()
const label2 = new Object3D()
const label3 = new Object3D()
labels.push(label1, label2, label3)

const indexIncrement = threeSceneService.getHoveredLabelLineIndex(labels, label2)

expect(indexIncrement).toEqual(2)
})
})

describe("toggleLineAnimation", () => {
let highlightedLabel = null
let hoveredLabel = null
let highlightedLine = null
let lineGeometry = null
let labels = null
let labelsGroup = null

beforeEach(() => {
highlightedLine = new Object3D()
lineGeometry = new Geometry()
lineGeometry.vertices.push(new Vector3(3, 3, 3), new Vector3(3, 3, 3))
highlightedLine["geometry"] = lineGeometry
highlightedLine.material = new Material()

labels = []
labels.push(new Object3D(), new Object3D(), new Object3D())

labelsGroup = new Group()
labelsGroup.children = labels
threeSceneService.labels = labelsGroup

hoveredLabel = new Object3D()
hoveredLabel.position.set(2, 2, 2)

highlightedLabel = new Object3D()
highlightedLabel.position.set(1,1,1)
highlightedLabel.material = new Material()

threeSceneService["highlightedLineIndex"] = 1
threeSceneService["highlightedLabel"] = highlightedLabel
threeSceneService["highlightedLine"] = highlightedLine
threeSceneService["normedTransformVector"] = new Vector3(0,0,0)

})

it("should set endpoint to given hoveredLabel coordinates if not in reset mode", () => {

threeSceneService.toggleLineAnimation(false, hoveredLabel)

expect(threeSceneService.labels.children[1]["geometry"].vertices[0]).toEqual(new Vector3(3,3,3))
expect(threeSceneService.labels.children[1]["geometry"].vertices[1]).toEqual(new Vector3(2,2,2))
expect(threeSceneService["highlightedLineIndex"]).toEqual(-1)
expect(threeSceneService["highlightedLine"]).toEqual(null)
})

it("should set endpoint to highlightedLabel if in reset mode", () => {

threeSceneService.resetLabel()

expect(threeSceneService.labels.children[1]["geometry"].vertices[0]).toEqual(new Vector3(3,3,3))
expect(threeSceneService.labels.children[1]["geometry"].vertices[1]).toEqual(new Vector3(1,1,1))
expect(threeSceneService["highlightedLineIndex"]).toEqual(-1)
expect(threeSceneService["highlightedLine"]).toEqual(null)
expect(threeSceneService["highlightedLabel"]).toEqual(null)
})
})

describe("scaleHeight", () => {
it("should update mapGeometry scaling to new vector", () => {
const scaling = new Vector3(1, 2, 3)
Expand Down
Expand Up @@ -99,12 +99,6 @@ export class ThreeSceneService implements CodeMapPreRenderServiceSubscriber, Map
}
}

highlightBuildingsAfterSelect() {
// TODO dead code? Remove it please.
const state = this.storeService.getState()
this.getMapMesh().highlightBuilding(this.highlighted, this.selected, state, this.constantHighlight)
}

private selectMaterial(materials: Material[]) {
const selectedMaterial = materials.find(({ userData }) => userData.id === this.selected.node.id)
selectedMaterial?.["color"].setHex(this.numberSelectionColor)
Expand Down Expand Up @@ -248,15 +242,14 @@ export class ThreeSceneService implements CodeMapPreRenderServiceSubscriber, Map
}

toggleLineAnimation(reset: boolean, hoveredLabel? : Object3D){

const geometry = new Geometry()
const endPoint = reset ? new Vector3(this.highlightedLabel.position.x, this.highlightedLabel.position.y, this.highlightedLabel.position.z) : new Vector3(hoveredLabel.position.x, hoveredLabel.position.y, hoveredLabel.position.z)

geometry.vertices.push(this.highlightedLine.geometry.vertices[0], endPoint)

const newLineForHiglightedLabel = new Line(geometry, this.highlightedLine.material);
const newLineForHighlightedLabel = new Line(geometry, this.highlightedLine.material);

this.labels.children.splice(this.highlightedLineIndex, 0, newLineForHiglightedLabel)
this.labels.children.splice(this.highlightedLineIndex, 0, newLineForHighlightedLabel)

this.highlightedLineIndex = -1
this.highlightedLine = null
Expand Down

0 comments on commit 5d06c7c

Please sign in to comment.