Skip to content

Commit

Permalink
[Maps] Move layer stats collector logic to common (elastic#135754)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpeihl authored Jul 12, 2022
1 parent 6d3b052 commit cd1e67c
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 288 deletions.
15 changes: 15 additions & 0 deletions x-pack/plugins/maps/common/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { LayerStatsCollector } from './layer_stats_collector';
export type {
EMS_BASEMAP_KEYS,
JOIN_KEYS,
LAYER_KEYS,
RESOLUTION_KEYS,
SCALING_KEYS,
} from './types';
111 changes: 111 additions & 0 deletions x-pack/plugins/maps/common/telemetry/layer_stats_collector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

// @ts-ignore
import mapSavedObjects from './test_resources/sample_map_saved_objects.json';
import { LayerStatsCollector } from './layer_stats_collector';
import { MapSavedObjectAttributes } from '../map_saved_object_type';

const expecteds = [
{
layerCount: 3,
basemapCounts: { roadmap: 1 },
joinCounts: {},
layerCounts: { ems_basemap: 1, ems_region: 1, es_agg_clusters: 1 },
resolutionCounts: { coarse: 1 },
scalingCounts: {},
emsFileCounts: { italy_provinces: 1 },
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 2 },
sourceCount: 3,
},
{
layerCount: 3,
basemapCounts: { roadmap: 1 },
joinCounts: { term: 1 },
layerCounts: { ems_basemap: 1, ems_region: 1, es_docs: 1 },
resolutionCounts: {},
scalingCounts: { limit: 1 },
emsFileCounts: { france_departments: 1 },
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 2 },
sourceCount: 3,
},
{
layerCount: 2,
basemapCounts: { roadmap: 1 },
joinCounts: {},
layerCounts: { ems_basemap: 1, ems_region: 1 },
resolutionCounts: {},
scalingCounts: {},
emsFileCounts: { canada_provinces: 1 },
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 1 },
sourceCount: 2,
},
{
layerCount: 1,
basemapCounts: {},
joinCounts: {},
layerCounts: { es_agg_clusters: 1 },
resolutionCounts: { coarse: 1 },
scalingCounts: {},
emsFileCounts: {},
layerTypeCounts: { GEOJSON_VECTOR: 1 },
sourceCount: 1,
},
{
layerCount: 1,
basemapCounts: {},
joinCounts: {},
layerCounts: { es_agg_heatmap: 1 },
resolutionCounts: { coarse: 1 },
scalingCounts: {},
emsFileCounts: {},
layerTypeCounts: { HEATMAP: 1 },
sourceCount: 1,
},
];

const testsToRun = mapSavedObjects.map(
(savedObject: { attributes: MapSavedObjectAttributes }, index: number) => {
const { attributes } = savedObject;
return [attributes, expecteds[index]] as const;
}
);

describe.each(testsToRun)('LayerStatsCollector %#', (attributes, expected) => {
const statsCollector = new LayerStatsCollector(attributes);
test('getLayerCount', () => {
expect(statsCollector.getLayerCount()).toBe(expected.layerCount);
});

test('getBasemapCounts', () => {
expect(statsCollector.getBasemapCounts()).toEqual(expected.basemapCounts);
});

test('getJoinCounts', () => {
expect(statsCollector.getJoinCounts()).toEqual(expected.joinCounts);
});

test('getLayerCounts', () => {
expect(statsCollector.getLayerCounts()).toEqual(expected.layerCounts);
});

test('getResolutionCounts', () => {
expect(statsCollector.getResolutionCounts()).toEqual(expected.resolutionCounts);
});

test('getScalingCounts', () => {
expect(statsCollector.getScalingCounts()).toEqual(expected.scalingCounts);
});

test('getEmsFileCounts', () => {
expect(statsCollector.getEmsFileCounts()).toEqual(expected.emsFileCounts);
});

test('getSourceCount', () => {
expect(statsCollector.getSourceCount()).toEqual(expected.sourceCount);
});
});
Loading

0 comments on commit cd1e67c

Please sign in to comment.