Skip to content
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

[Maps] Use Json for mvt-tests #86492

Merged
merged 2 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
"@mapbox/geojson-rewind": "^0.5.0",
"@mapbox/mapbox-gl-draw": "^1.2.0",
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
"@mapbox/vector-tile": "1.3.1",
"@microsoft/api-documenter": "7.7.2",
"@microsoft/api-extractor": "7.7.0",
"@octokit/rest": "^16.35.0",
Expand Down Expand Up @@ -750,6 +751,7 @@
"ora": "^4.0.4",
"p-limit": "^3.0.1",
"parse-link-header": "^1.0.1",
"pbf": "3.2.1",
"pirates": "^4.0.1",
"pixelmatch": "^5.1.0",
"pkg-up": "^2.0.0",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
135 changes: 118 additions & 17 deletions x-pack/plugins/maps/server/mvt/get_tile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@
import { getGridTile, getTile } from './get_tile';
import { TILE_GRIDAGGS, TILE_SEARCHES } from './__tests__/tile_es_responses';
import { Logger } from 'src/core/server';
import * as path from 'path';
import * as fs from 'fs';
import { ES_GEO_FIELD_TYPE, RENDER_AS } from '../../common/constants';
import { ES_GEO_FIELD_TYPE, MVT_SOURCE_LAYER_NAME, RENDER_AS } from '../../common/constants';

// @ts-expect-error
import { VectorTile, VectorTileLayer } from '@mapbox/vector-tile';
// @ts-expect-error
import Protobuf from 'pbf';

interface ITileLayerJsonExpectation {
version: number;
name: string;
extent: number;
length: number;
features: Array<{
id: string | number | undefined;
type: number;
properties: object;
extent: number;
pointArrays: object;
}>;
}

describe('getTile', () => {
const mockCallElasticsearch = jest.fn();
Expand Down Expand Up @@ -39,7 +56,7 @@ describe('getTile', () => {
}
});

const tile = await getTile({
const pbfTile = await getTile({
x: 0,
y: 0,
z: 0,
Expand All @@ -53,7 +70,35 @@ describe('getTile', () => {
geoFieldType: ES_GEO_FIELD_TYPE.GEO_SHAPE,
});

compareTiles('./__tests__/pbf/0_0_0_docs.pbf', tile);
const jsonTile = new VectorTile(new Protobuf(pbfTile));
compareJsonTiles(jsonTile, {
version: 2,
name: 'source_layer',
extent: 4096,
length: 1,
features: [
{
id: undefined,
type: 3,
properties: {
__kbn__feature_id__: 'poly:G7PRMXQBgyyZ-h5iYibj:0',
_id: 'G7PRMXQBgyyZ-h5iYibj',
_index: 'poly',
},
extent: 4096,
pointArrays: [
[
{ x: 840, y: 1600 },
{ x: 1288, y: 1096 },
{ x: 1672, y: 1104 },
{ x: 2104, y: 1508 },
{ x: 1472, y: 2316 },
{ x: 840, y: 1600 },
],
],
},
],
});
});
});

Expand Down Expand Up @@ -115,22 +160,78 @@ describe('getGridTile', () => {
};

test('0.0.0 tile (clusters)', async () => {
const tile = await getGridTile(defaultParams);
compareTiles('./__tests__/pbf/0_0_0_grid_aspoint.pbf', tile);
const pbfTile = await getGridTile(defaultParams);
const jsonTile = new VectorTile(new Protobuf(pbfTile));
compareJsonTiles(jsonTile, {
version: 2,
name: 'source_layer',
extent: 4096,
length: 1,
features: [
{
id: undefined,
type: 1,
properties: {
['avg_of_TOTAL_AV']: 5398920.390458991,
doc_count: 42637,
},
extent: 4096,
pointArrays: [[{ x: 1206, y: 1539 }]],
},
],
});
});

test('0.0.0 tile (grids)', async () => {
const tile = await getGridTile({ ...defaultParams, requestType: RENDER_AS.GRID });
compareTiles('./__tests__/pbf/0_0_0_grid_asgrid.pbf', tile);
const pbfTile = await getGridTile({ ...defaultParams, requestType: RENDER_AS.GRID });
const jsonTile = new VectorTile(new Protobuf(pbfTile));
compareJsonTiles(jsonTile, {
version: 2,
name: 'source_layer',
extent: 4096,
length: 1,
features: [
{
id: undefined,
type: 3,
properties: {
['avg_of_TOTAL_AV']: 5398920.390458991,
doc_count: 42637,
},
extent: 4096,
pointArrays: [
[
{ x: 1216, y: 1536 },
{ x: 1216, y: 1568 },
{ x: 1184, y: 1568 },
{ x: 1184, y: 1536 },
{ x: 1216, y: 1536 },
],
],
},
],
});
});
});

function compareTiles(expectedRelativePath: string, actualTile: Buffer | null) {
if (actualTile === null) {
throw new Error('Tile should be created');
}
const expectedPath = path.resolve(__dirname, expectedRelativePath);
const expectedBin = fs.readFileSync(expectedPath, 'binary');
const expectedTile = Buffer.from(expectedBin, 'binary');
expect(expectedTile.equals(actualTile)).toBe(true);
/**
* Verifies JSON-representation of tile-contents
* @param actualTileJson
* @param expectedLayer
*/
function compareJsonTiles(actualTileJson: VectorTile, expectedLayer: ITileLayerJsonExpectation) {
const actualLayer: VectorTileLayer = actualTileJson.layers[MVT_SOURCE_LAYER_NAME];
expect(actualLayer.version).toEqual(expectedLayer.version);
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
expect(actualLayer.extent).toEqual(expectedLayer.extent);
expect(actualLayer.name).toEqual(expectedLayer.name);
expect(actualLayer.length).toEqual(expectedLayer.features.length);

expectedLayer.features.forEach((expectedFeature, index) => {
const actualFeature = actualLayer.feature(index);
expect(actualFeature.type).toEqual(expectedFeature.type);
expect(actualFeature.extent).toEqual(expectedFeature.extent);
expect(actualFeature.id).toEqual(expectedFeature.id);
expect(actualFeature.properties).toEqual(expectedFeature.properties);
expect(actualFeature.loadGeometry()).toEqual(expectedFeature.pointArrays);
});
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@
resolved "https://registry.yarnpkg.com/@mapbox/unitbezier/-/unitbezier-0.0.0.tgz#15651bd553a67b8581fb398810c98ad86a34524e"
integrity sha1-FWUb1VOme4WB+zmIEMmK2Go0Uk4=

"@mapbox/vector-tile@^1.3.1":
"@mapbox/vector-tile@1.3.1", "@mapbox/vector-tile@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@mapbox/vector-tile/-/vector-tile-1.3.1.tgz#d3a74c90402d06e89ec66de49ec817ff53409666"
integrity sha512-MCEddb8u44/xfQ3oD+Srl/tNcQoqTw3goGk2oLsrFxOTc3dUp+kAnby3PvAeeBYSMSjSPD1nd1AJA6W49WnoUw==
Expand Down Expand Up @@ -21931,7 +21931,7 @@ pathval@^1.1.0:
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA=

pbf@^3.0.5, pbf@^3.2.1:
pbf@3.2.1, pbf@^3.0.5, pbf@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/pbf/-/pbf-3.2.1.tgz#b4c1b9e72af966cd82c6531691115cc0409ffe2a"
integrity sha512-ClrV7pNOn7rtmoQVF4TS1vyU0WhYRnP92fzbfF75jAIwpnzdJXf8iTd4CMEqO4yUenH6NDqLiwjqlh6QgZzgLQ==
Expand Down