[Maps] Use Json for mvt-tests (#86492) (#86588)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Thomas Neirynck 2020-12-22 13:13:07 -05:00 committed by GitHub
parent c01df953fc
commit 96d63cc22e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 19 deletions

View file

@ -374,6 +374,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",
@ -740,6 +741,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",

View file

@ -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();
@ -39,7 +56,7 @@ describe('getTile', () => {
}
});
const tile = await getTile({
const pbfTile = await getTile({
x: 0,
y: 0,
z: 0,
@ -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 },
],
],
},
],
});
});
});
@ -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);
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);
});
}

View file

@ -2996,7 +2996,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==
@ -21984,7 +21984,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==