Skip to content

Commit

Permalink
Added new tests for onObject interaction (#102)
Browse files Browse the repository at this point in the history
* Fix extend tiles tests

* Add tests for onObject control buttons and wheel event

* Add tests for onObject bar selection

* Add tests for onObject hover

* Add test for onObject context menu subselection

* Add coordination mock for onObject tests

---------

Co-authored-by: Iuliia Kulagina <[email protected]>
  • Loading branch information
kullJul and Iuliia Kulagina authored Apr 2, 2024
1 parent 9750ede commit 9438dc0
Show file tree
Hide file tree
Showing 4 changed files with 597 additions and 48 deletions.
12 changes: 6 additions & 6 deletions src/globemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class GlobeMap implements IVisual {
private root: HTMLElement;
private rendererContainer: HTMLElement;
private rendererCanvas: HTMLElement;
private camera: THREE.PerspectiveCamera;
public camera: THREE.PerspectiveCamera;
private renderer: THREE.WebGLRenderer;
private scene: THREE.Scene;
private orbitControls: OrbitControls;
Expand All @@ -176,12 +176,12 @@ export class GlobeMap implements IVisual {
private locationsLoaded: number = 0;
private initialLocationsLength: number = 0;
private renderLoopEnabled = true;
private needsRender = false;
public needsRender = false;
private mousePosNormalized: THREE.Vector2;
private mousePos: THREE.Vector2;
private rayCaster: THREE.Raycaster;
private selectedBar: THREE.Object3D;
private hoveredBar: THREE.Object3D;
public hoveredBar: THREE.Object3D;
private averageBarVector: THREE.Vector3;
private controlContainer: HTMLElement;
public colors: IColorPalette;
Expand All @@ -197,9 +197,9 @@ export class GlobeMap implements IVisual {
private formatMode: boolean = false;
private pressKey: boolean = false;
private barFromMouseDown: THREE.Object3D;
private subSelectedBar: IGlobeMapObject3DWithToolTipData;
public subSelectedBar: IGlobeMapObject3DWithToolTipData;
private subSelectionService: powerbi.extensibility.IVisualSubSelectionService;
private subSelectionRegionOutlines: Map<SubSelectionOutlineVisibility, SubSelectionRegionOutline>;
public subSelectionRegionOutlines: Map<SubSelectionOutlineVisibility, SubSelectionRegionOutline>;

private isFirstLoad: boolean = true;

Expand Down Expand Up @@ -1219,7 +1219,7 @@ export class GlobeMap implements IVisual {
return regionOutline;
}

private worldToScreenPositions(bar: THREE.Object3D) {
public worldToScreenPositions(bar: THREE.Object3D) {
const vector = new THREE.Vector3();
const canvas = this.renderer.domElement;

Expand Down
45 changes: 41 additions & 4 deletions test/visualBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export class GlobeMapBuilder extends VisualBuilderBase<VisualClass> {
super(width, height, "GlobeMap1447669447625");
}

public update(dataView: DataView[] | DataView, updateType?: VisualUpdateType): void {
public update(dataView: DataView[] | DataView, updateType?: VisualUpdateType, formatMode?: boolean, subSelections?: powerbi.visuals.CustomVisualSubSelection[]): void {
let options: VisualUpdateOptions = {
dataViews: Array.isArray(dataView) ? dataView : [dataView],
viewport: this.viewport,
type: updateType!
type: updateType!,
formatMode: formatMode,
subSelections: subSelections
};

this.visual.update(options);
Expand All @@ -55,8 +57,11 @@ export class GlobeMapBuilder extends VisualBuilderBase<VisualClass> {
dataViews: DataView[] | DataView,
fn: () => any,
updateType: VisualUpdateType = GlobeMapBuilder.ChangeAllType,
timeout?: number): number {
this.update(dataViews, updateType);
formatMode: boolean = false,
timeout?: number,
subSelections?: powerbi.visuals.CustomVisualSubSelection[]
): number {
this.update(dataViews, updateType, formatMode, subSelections);
return renderTimeout(fn, timeout);
}

Expand All @@ -67,4 +72,36 @@ export class GlobeMapBuilder extends VisualBuilderBase<VisualClass> {
public get instance(): VisualClass {
return this.visual;
}

public get canvasElement(): HTMLElement | null {
return this.element.querySelector("canvas");
}

public get controlsElements(): NodeListOf<HTMLElement> | null {
return this.element.querySelectorAll(".control");
}

public get rightControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--move-right");
}

public get leftControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--move-left");
}

public get upControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--move-up");
}

public get downControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--move-down");
}

public get zoomUpControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--zoom-up");
}

public get zoomDownControlElement(): HTMLElement | null {
return this.element.querySelector(".control.js-control--zoom-down");
}
}
25 changes: 25 additions & 0 deletions test/visualData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import DataView = powerbi.DataView;
import { ValueType } from "powerbi-visuals-utils-typeutils/lib/valueType";
import { TestDataViewBuilder } from "powerbi-visuals-utils-testutils/lib/dataViewBuilder/testDataViewBuilder";
import { getRandomNumbers } from "powerbi-visuals-utils-testutils";
import { ILocationDictionary } from "../src/interfaces/locationInterfaces";

export class GlobeMapData extends TestDataViewBuilder {
public static ColumnSource: string = "Location";
Expand Down Expand Up @@ -146,4 +147,28 @@ export class GlobeMapData extends TestDataViewBuilder {
}
], columnNames).build();
}

public getCoordinatesMock(): ILocationDictionary{
return {
"addis ababa, ethiopia": {latitude: 9.03582859, longitude: 38.75241089},
"ahmedabad, india": {latitude: 23.0145092, longitude: 72.59175873},
"cairo, egypt": {latitude: 30.04348755, longitude: 31.23529243},
"cape town, south africa": {latitude: -33.92710876, longitude: 18.42006111},
"casablanca, morocco": {latitude: 33.59451294, longitude: -7.6200285},
"chennai, india": {latitude: 13.07209206, longitude: 80.20185852},
"durban, south africa": {latitude: -29.88188934, longitude: 30.98084259},
"jakarta, indonesia": {latitude: -6.17475653, longitude: 106.82707214},
"jeddah, saudi arabia": {latitude: 21.48730469, longitude: 39.18133545},
"lagos, nigeria": {latitude: 6.45505762, longitude: 3.39417958},
"lima, peru": {latitude: -12.06210613, longitude: -77.03652191},
"london, united kingdom": {latitude: 51.50740814, longitude: -0.12772401},
"mexico city, mexico": {latitude: 19.43267822, longitude: -99.13420868},
"new taipei city, republic of china": {latitude: 25.01170921, longitude: 121.46588135},
"riyadh, saudi arabia": {latitude: 24.69496918, longitude: 46.72412872},
"shanghai, china": {latitude: 31.23036957, longitude: 121.47370148},
"shenzhen, china": {latitude: 22.54368019, longitude: 114.0579071},
"surat, india": {latitude: 21.20350838, longitude: 72.83922577},
"tehran, iran": {latitude: 35.68925095, longitude: 51.38959885}
};
}
}
Loading

0 comments on commit 9438dc0

Please sign in to comment.