This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
/
MapControlsTest.ts
128 lines (108 loc) · 4.52 KB
/
MapControlsTest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (C) 2017-2019 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
// tslint:disable:only-arrow-functions
// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions
import { mercatorProjection } from "@here/harp-geoutils";
import { MapView } from "@here/harp-mapview";
import { expect } from "chai";
import * as sinon from "sinon";
import * as THREE from "three";
import { MapControls } from "../lib/MapControls";
declare const global: any;
const inNodeContext = typeof window === "undefined";
describe.only("MapControls", function() {
let sandbox: sinon.SinonSandbox;
beforeEach(function() {
sandbox = sinon.createSandbox();
if (inNodeContext) {
const theGlobal: any = global;
// tslint:disable-next-line:no-empty
theGlobal.requestAnimationFrame = () => {};
theGlobal.performance = {
// tslint:disable-next-line:no-empty
now: () => {}
};
}
});
afterEach(function() {
sandbox.restore();
if (inNodeContext) {
delete global.requestAnimationFrame;
delete global.performance;
}
});
describe("on object creation", function() {
let addEventListener: () => {};
let mapView: MapView;
let mapControls: MapControls;
let camera: THREE.Camera;
let domElement: any;
let maxZoom: number;
let minZoom: number;
let minCameraHeight: number;
beforeEach(function() {
addEventListener = sandbox.stub();
camera = {} as any;
domElement = { addEventListener } as any;
maxZoom = 10;
minZoom = 5;
minCameraHeight = 100;
mapView = sandbox.createStubInstance(MapView) as any;
sandbox.stub(mapView, "renderer").get(() => ({ domElement }));
sandbox.stub(mapView, "camera").get(() => camera);
sandbox.stub(mapView, "maxZoomLevel").get(() => maxZoom);
sandbox.stub(mapView, "minZoomLevel").get(() => minZoom);
sandbox.stub(mapView, "minCameraHeight").get(() => minCameraHeight);
sandbox.stub(mapView, "projection").get(() => mercatorProjection);
mapControls = new MapControls(mapView);
});
it("initializes camera property using value from constructor param", function() {
expect(mapControls.camera).to.be.equals(camera);
});
it("initializes domElement property using value from constructor param", function() {
expect(mapControls.domElement).to.be.equals(domElement);
});
it("initializes minZoomLevel property using value from constructor param", function() {
expect(mapControls.minZoomLevel).to.be.equals(minZoom);
});
it("initializes maxZoomLevel property using value from constructor param", function() {
expect(mapControls.maxZoomLevel).to.be.equals(maxZoom);
});
it("initializes minCameraHeight property using value from constructor param", function() {
expect(mapControls.minCameraHeight).to.be.equals(minCameraHeight);
});
});
it("correctly updates mapView on mouse move", function() {
const updateStub = sandbox.stub();
//@ts-ignore
const mapControls = new MapControls({
renderer: { domElement: { addEventListener: sandbox.stub() } as any } as any,
update: updateStub
});
sandbox.stub(mapControls, "dispatchEvent");
expect(updateStub.callCount).to.be.equal(0);
mapControls.mouseMove({ preventDefault: sandbox.stub(), stopPropagation: sandbox.stub() });
expect(updateStub.callCount).to.be.equal(1);
});
it("correctly updates mapView on touch move", function() {
const updateStub = sandbox.stub();
//@ts-ignore
const mapControls = new MapControls({
renderer: { domElement: { addEventListener: sandbox.stub() } as any } as any,
update: updateStub
});
mapControls.m_touchState.touches = { length: 5 };
sandbox.stub(mapControls, "updateTouches");
sandbox.stub(mapControls, "dispatchEvent");
expect(updateStub.callCount).to.be.equal(0);
mapControls.touchMove({
touches: [],
preventDefault: sandbox.stub(),
stopPropagation: sandbox.stub()
});
expect(updateStub.callCount).to.be.equal(1);
});
});