Skip to content

Rd 783 e2e for animated route layer #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ demos/tmp_*
dist
docs
docsmd
build
build

# Test output
test-results
playwright-report
12 changes: 12 additions & 0 deletions e2e/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Map } from "@maptiler/sdk";

declare global {
interface Window {
__map: Map;
__pageLoadTimeout: number;
notifyScreenshotStateReady: (data: TTestTransferData) => Promise<void>;
__pageObjects: Record<string, unknown>;
}

type TTestTransferData = string | number | boolean | string[] | number[] | boolean[] | null | Record<string, unknown> | [number, number];
}
82 changes: 82 additions & 0 deletions e2e/public/animated-route.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"pitch": [
30,
40,
50,
60,
50,
40,
30
],
"bearing": [
0,
180,
360
],
"zoom": [
13.5,
14,
14.5,
15,
14.5,
14,
13.5
]
},
"geometry": {
"coordinates": [
[
-5.513465218122661,
55.44452556522981
],
[
-5.498757996681263,
55.45488849896259
],
[
-5.4776627901701715,
55.459774141237716
],
[
-5.450773829757111,
55.45446729456921
],
[
-5.434581030391769,
55.44241894502119
],
[
-5.434433020938883,
55.42337006037573
],
[
-5.447655667245527,
55.40895140980018
],
[
-5.474692405196635,
55.40169789075969
],
[
-5.504997423959253,
55.410637475280794
],
[
-5.520595992154796,
55.42809094495976
],
[
-5.513910891499705,
55.44393572290733
]
],
"type": "LineString"
}
}
]
}
24 changes: 24 additions & 0 deletions e2e/public/animatedRouteLayer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MapTiler E2E Animated Route Layer</title>
<style>
#map {
width: 100vw;
height: 100vh;
border: 1px solid red;
}

body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module" src="/src/animatedRouteLayer.ts"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions e2e/public/mapLoad.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MapTiler E2E Map Load</title>
<style>
#map {
width: 100vw;
height: 100vh;
border: 1px solid red;
}

body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module" src="/src/mapLoad.ts"></script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions e2e/src/animatedRouteLayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { AnimatedRouteLayer } from "../../src/custom-layers/AnimatedRouteLayer";
import { Map as MapTiler, MapStyle } from "@maptiler/sdk";
import fetchGeoJSON from "../tests/helpers/fetchGeojson";

async function main() {
const map = new MapTiler({
container: "map",
apiKey: "DOESNT_MATTER",
style: MapStyle.SATELLITE,
projection: "globe",
pitch: 30,
bearing: 0,
zoom: 13.5,
center: [-5.513465218122661, 55.44452556522981],
});

window.__map = map;

const geojson = await fetchGeoJSON("/animated-route.geojson");

await map.onReadyAsync();

map.addSource("route-source", {
type: "geojson",
data: geojson,
lineMetrics: true,
});

map.addLayer({
id: "route-layer",
type: "line",
source: "route-source",
layout: {
"line-cap": "round",
"line-join": "round",
},
paint: {
"line-width": 5,
"line-color": "#FF0000",
"line-opacity": 0.8,
},
});

const animatedRouteLayer = new AnimatedRouteLayer({
manualUpdate: true,
source: {
id: "route-source",
layerID: "route-layer",
featureSetIndex: 0,
},
duration: 10000,
iterations: 1,
pathStrokeAnimation: {
activeColor: [0, 255, 0, 1],
inactiveColor: [100, 100, 100, 0.5],
},
cameraAnimation: {
pathSmoothing: {
resolution: 20,
epsilon: 2,
},
},
});

map.addLayer(animatedRouteLayer);

window.__pageObjects = {
animatedRouteLayer,
};
}

main();
12 changes: 12 additions & 0 deletions e2e/src/mapLoad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "@maptiler/sdk/dist/maptiler-sdk.css";
import { Map as MapTiler, MapStyle } from "@maptiler/sdk";

const map = new MapTiler({
container: "map",
apiKey: "DOESNT_MATTER",
style: MapStyle.SATELLITE,
projection: "globe",
zoom: 3,
});

window.__map = map;
45 changes: 45 additions & 0 deletions e2e/tests/AnimatedRouteLayer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect, test } from "@playwright/test";
import getMapInstanceForFixture from "./helpers/getMapInstanceForFixture";
import { AnimatedRouteLayer } from "index";
import { Map } from "@maptiler/sdk";
import expected from "./expected-results/animatedRouteLayer-1.json" assert { type: "json" };

test("Follows the correct path taking screenshots at each interval", async ({ page }) => {
await getMapInstanceForFixture({
fixture: "animatedRouteLayer",
page,
timeout: 10000,
});

expect(await page.title()).toBe("MapTiler E2E Animated Route Layer");

await page.exposeFunction("notifyScreenshotStateReady", async (data: Record<string, TTestTransferData>) => {
await expect(page).toHaveScreenshot(`animated-route-${data.frame}.png`);
expect(data).toEqual(expected[data.frame as number]);
});

await page.clock.install();

await page.evaluate(async () => {
const NUM_SCREENSHOTS = 20;
const NUM_FRAMES_BETWEEN_SCREENSHOTS = 20;

const { animatedRouteLayer } = window.__pageObjects as { animatedRouteLayer: AnimatedRouteLayer };
const map = window.__map as Map;

for (let i = 0; i < NUM_SCREENSHOTS; i++) {
for (let j = 0; j < NUM_FRAMES_BETWEEN_SCREENSHOTS; j++) {
animatedRouteLayer.updateManual();
}
await window.notifyScreenshotStateReady({
frame: i,
center: map.getCenter().toArray(),
zoom: map.getZoom(),
pitch: map.getPitch(),
bearing: map.getBearing(),
});
}
});

await page.clock.runFor(10000);
});
Empty file added e2e/tests/consts.ts
Empty file.
Loading
Loading