Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

HARP-12989 Fix extra console entries in tests #1972

Merged
merged 6 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 59 additions & 52 deletions @here/harp-mapview-decoder/test/TileDataSourceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
webMercatorTilingScheme
} from "@here/harp-geoutils";
import { DataSource, MapView, Statistics, Tile, TileLoaderState } from "@here/harp-mapview";
import { errorOnlyLoggingAroundFunction } from "@here/harp-test-utils";
import { assert, expect } from "chai";
import * as sinon from "sinon";

Expand Down Expand Up @@ -301,72 +302,78 @@ describe("TileDataSource", function() {
});

it("supports deprecated minZoomLevel and maxZoomLevel in constructor", function() {
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: createMockTileDecoder(),
minZoomLevel: 3,
maxZoomLevel: 17
errorOnlyLoggingAroundFunction("DataSource", () => {
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: createMockTileDecoder(),
minZoomLevel: 3,
maxZoomLevel: 17
});

assert.equal(testedDataSource.minZoomLevel, 3);
assert.equal(testedDataSource.minDataLevel, 3);
assert.equal(testedDataSource.maxZoomLevel, 17);
assert.equal(testedDataSource.maxDataLevel, 17);
});

assert.equal(testedDataSource.minZoomLevel, 3);
assert.equal(testedDataSource.minDataLevel, 3);
assert.equal(testedDataSource.maxZoomLevel, 17);
assert.equal(testedDataSource.maxDataLevel, 17);
});

it("supports setting of theme", async function() {
const mockDecoder = createMockTileDecoder();
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "tilezen",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: mockDecoder,
minZoomLevel: 3,
maxZoomLevel: 17
errorOnlyLoggingAroundFunction("DataSource", async () => {
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "tilezen",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: mockDecoder,
minZoomLevel: 3,
maxZoomLevel: 17
});

testedDataSource.attach(createMockMapView());

const styles: StyleSet = [
{
styleSet: "tilezen",
technique: "none"
}
];

await testedDataSource.setTheme({
styles
});

assert(mockDecoder.configure.calledOnce);
assert(mockDecoder.configure.calledWith(sinon.match({ styleSet: styles })));
});

testedDataSource.attach(createMockMapView());

const styles: StyleSet = [
{
styleSet: "tilezen",
technique: "none"
}
];

await testedDataSource.setTheme({
styles
});

assert(mockDecoder.configure.calledOnce);
assert(mockDecoder.configure.calledWith(sinon.match({ styleSet: styles })));
});

it("supports setting of languages", async function() {
const mockDecoder = createMockTileDecoder();
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "tilezen",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: mockDecoder,
minZoomLevel: 3,
maxZoomLevel: 17,
languages: ["de"]
});
errorOnlyLoggingAroundFunction("DataSource", async () => {
const testedDataSource = new TileDataSource(new TileFactory(Tile), {
styleSetName: "tilezen",
tilingScheme: webMercatorTilingScheme,
dataProvider: new MockDataProvider(),
decoder: mockDecoder,
minZoomLevel: 3,
maxZoomLevel: 17,
languages: ["de"]
});

await testedDataSource.connect();
await testedDataSource.connect();

expect(mockDecoder.configure.calledOnce).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de"] }))).to.be.true;
expect(mockDecoder.configure.calledOnce).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de"] }))).to.be.true;

testedDataSource.attach(createMockMapView());
testedDataSource.attach(createMockMapView());

testedDataSource.setLanguages(["de", "en"]);
testedDataSource.setLanguages(["de", "en"]);

expect(mockDecoder.configure.calledTwice).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de", "en"] }))).to.be
.true;
expect(mockDecoder.configure.calledTwice).to.be.true;
expect(mockDecoder.configure.calledWith(sinon.match({ languages: ["de", "en"] }))).to.be
.true;
});
});
});
4 changes: 3 additions & 1 deletion @here/harp-mapview/lib/MapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,8 @@ export class MapView extends EventDispatcher {
ConcurrentDecoderFacade.destroyIfTerminated();
ConcurrentTilerFacade.destroyIfTerminated();

this.m_taskScheduler.clearQueuedTasks();

// Remove all event handlers.
super.dispose();
}
Expand Down Expand Up @@ -2158,7 +2160,7 @@ export class MapView extends EventDispatcher {
dataSource.setLanguages(this.m_languages);

if (theme !== undefined && theme.styles !== undefined) {
dataSource.setTheme(theme);
await dataSource.setTheme(theme);
}

this.m_connectedDataSources.add(dataSource.name);
Expand Down
7 changes: 7 additions & 0 deletions @here/harp-mapview/lib/MapViewTaskScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export class MapViewTaskScheduler extends THREE.EventDispatcher {
}
}

/**
* Removes all tasks that have been queued.
*/
clearQueuedTasks() {
this.m_taskQueue.clear();
}

private spaceInFrame(frameStartTime: number): number {
const passedTime = (performance || Date).now() - frameStartTime;
return Math.max(1000 / this.m_maxFps - passedTime, 0);
Expand Down
75 changes: 50 additions & 25 deletions @here/harp-mapview/test/MapViewTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
sphereProjection,
webMercatorTilingScheme
} from "@here/harp-geoutils";
import { getTestResourceUrl, waitForEvent } from "@here/harp-test-utils";
import {
errorOnlyLoggingAroundFunction,
getTestResourceUrl,
waitForEvent
} from "@here/harp-test-utils";
import * as TestUtils from "@here/harp-test-utils/lib/WebGLStub";
import { FontCatalog } from "@here/harp-text-canvas";
import { getAppBaseUrl } from "@here/harp-utils";
Expand Down Expand Up @@ -101,7 +105,7 @@ describe("MapView", function() {
} as unknown) as HTMLCanvasElement;
});

afterEach(function() {
afterEach(async function() {
if (mapView !== undefined) {
mapView.dispose();
mapView = undefined;
Expand Down Expand Up @@ -640,25 +644,27 @@ describe("MapView", function() {
const webGlContextRestoredHandler = addEventListenerSpy.getCall(1).args[1];
const webGlContextLostHandler = addEventListenerSpy.getCall(0).args[1];

await mapView.setTheme({
clearColor: "#ffffff"
});
expect(clearColorStub.calledWith("#ffffff"));
await errorOnlyLoggingAroundFunction(["MapViewThemeManager", "MapView"], async () => {
await mapView!.setTheme({
clearColor: "#ffffff"
});

await webGlContextRestoredHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));
expect(clearColorStub.calledWith("#ffffff"));
await webGlContextRestoredHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));

await mapView.setTheme({
clearColor: undefined
});
await mapView!.setTheme({
clearColor: undefined
});

expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));

await webGlContextRestoredHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));
await webGlContextRestoredHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));

webGlContextLostHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));
webGlContextLostHandler();
expect(clearColorStub.calledWith(DEFAULT_CLEAR_COLOR));
});
});

it("Correctly sets and removes all event listeners by API", function() {
Expand Down Expand Up @@ -702,15 +708,18 @@ describe("MapView", function() {

it("ignore set and get tile wrapping mode for sphere projection", function() {
mapView = new MapView({ canvas, projection: sphereProjection });
mapView.tileWrappingEnabled = false;
errorOnlyLoggingAroundFunction("MapView", () => {
mapView!.tileWrappingEnabled = false; // Ignore warning here
});
expect(mapView.tileWrappingEnabled).equal(true);
});

it("supports #dispose", async function() {
const dataSource = new FakeOmvDataSource({ name: "omv" });
const dataSourceDisposeStub = sinon.stub(dataSource, "dispose");
mapView = new MapView({ canvas });
mapView.addDataSource(dataSource);
await mapView.getTheme();
await mapView.addDataSource(dataSource);

const disposeStub = sinon.stub();
mapView!.addEventListener(MapViewEventNames.Dispose, disposeStub);
Expand All @@ -732,7 +741,8 @@ describe("MapView", function() {
it("#dispose removes event listeners", async function() {
const dataSource = new FakeOmvDataSource({ name: "omv" });
mapView = new MapView({ canvas });
mapView.addDataSource(dataSource);
await mapView.getTheme();
await mapView.addDataSource(dataSource);
await dataSource.connect();

const eventStubs: Map<string, sinon.SinonStub> = new Map();
Expand Down Expand Up @@ -869,7 +879,7 @@ describe("MapView", function() {
expect(mapView.fog instanceof MapViewFog).to.equal(true);
});

it("converts screen coords to geo to screen w/ different pixel ratio", function() {
it("converts screen coords to geo to screen w/ different pixel ratio", async function() {
const customCanvas = {
clientWidth: 1920,
clientHeight: 1080,
Expand All @@ -878,14 +888,20 @@ describe("MapView", function() {
removeEventListener: sinon.stub()
};

const mapViewOptions = {
canvas: (customCanvas as any) as HTMLCanvasElement,
addBackgroundDatasource: false
};
for (let x = -100; x <= 100; x += 100) {
for (let y = -100; y <= 100; y += 100) {
mapView = new MapView({ canvas: (customCanvas as any) as HTMLCanvasElement });
mapView = new MapView(mapViewOptions);
await mapView.getTheme();
const resultA = mapView.getScreenPosition(mapView.getGeoCoordinatesAt(x, y)!);
mapView.dispose();

customCanvas.pixelRatio = 2;
mapView = new MapView({ canvas: (customCanvas as any) as HTMLCanvasElement });
mapView = new MapView(mapViewOptions);
await mapView.getTheme();
const resultB = mapView.getScreenPosition(mapView.getGeoCoordinatesAt(x, y)!);

expect(resultA!.x).to.be.closeTo(resultB!.x, 0.00000001);
Expand All @@ -897,7 +913,7 @@ describe("MapView", function() {
}
}
});
it("converts screen coords to world to screen w/ different pixel ratio", function() {
it("converts screen coords to world to screen w/ different pixel ratio", async function() {
const customCanvas = {
clientWidth: 1920,
clientHeight: 1080,
Expand All @@ -906,14 +922,20 @@ describe("MapView", function() {
removeEventListener: sinon.stub()
};

const mapViewOptions = {
canvas: (customCanvas as any) as HTMLCanvasElement,
addBackgroundDatasource: false
};
for (let x = -100; x <= 100; x += 100) {
for (let y = -100; y <= 100; y += 100) {
mapView = new MapView({ canvas: (customCanvas as any) as HTMLCanvasElement });
mapView = new MapView(mapViewOptions);
await mapView.getTheme();
const resultA = mapView.getScreenPosition(mapView.getWorldPositionAt(x, y)!);
mapView.dispose();

customCanvas.pixelRatio = 2;
mapView = new MapView({ canvas: (customCanvas as any) as HTMLCanvasElement });
mapView = new MapView(mapViewOptions);
await mapView.getTheme();
const resultB = mapView.getScreenPosition(mapView.getWorldPositionAt(x, y)!);

expect(resultA!.x).to.be.closeTo(resultB!.x, 0.00000001);
Expand Down Expand Up @@ -1434,6 +1456,7 @@ describe("MapView", function() {
};
}
mapView = new MapView({ canvas, theme: {} });
await mapView.getTheme();

const dataSource = new FakeOmvDataSource({ name: "omv" });

Expand All @@ -1454,6 +1477,7 @@ describe("MapView", function() {
it("languages set in MapView are also set in datasources", async function() {
const dataSource = new FakeOmvDataSource({ name: "omv" });
mapView = new MapView({ canvas, theme: {} });
await mapView.getTheme();

await mapView.addDataSource(dataSource);
mapView.languages = ["Goblin"];
Expand All @@ -1466,6 +1490,7 @@ describe("MapView", function() {
it("languages set in MapView are also set in datasources added later", async function() {
const dataSource = new FakeOmvDataSource({ name: "omv" });
mapView = new MapView({ canvas, theme: {} });
await mapView.getTheme();

mapView.languages = ["Goblin"];
await mapView.addDataSource(dataSource);
Expand Down
13 changes: 10 additions & 3 deletions @here/harp-mapview/test/StatisticsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
import { errorOnlyLoggingAroundFunction } from "@here/harp-test-utils";
import { assert } from "chai";

import {
Expand Down Expand Up @@ -181,7 +182,9 @@ describe("mapview-statistics", function() {
assert.isNumber(tx);
assert.isAbove(tx, t);

stats.log();
errorOnlyLoggingAroundFunction("Statistics", () => {
stats.log();
});
done();
}, 2);
}, 2);
Expand Down Expand Up @@ -223,7 +226,9 @@ describe("mapview-statistics", function() {
assert.isNumber(tx);
assert.isAbove(tx, t);

stats.log();
errorOnlyLoggingAroundFunction("Statistics", () => {
stats.log();
});
done();
}, 2);
}, 2);
Expand Down Expand Up @@ -266,7 +271,9 @@ describe("mapview-statistics", function() {
assert.isNumber(stats.getTimer("post").value);
assert.isAbove(stats.getTimer("post").value ?? 0, 0);

stats.log();
errorOnlyLoggingAroundFunction("Statistics", () => {
stats.log();
});

done();
}, 2);
Expand Down
Loading