forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] top term percentage field property (elastic#59386)
* [Maps] top term percentage property * populate percentage in feature properties * TS work * clean up TS * fix all type errors * unit test for esAggFieldsFactory * clean up * i18n cleanup * do not show decimal place for perentage * fix jest expects * fix eslint errors * tslint errors * handle empty top bucket aggregation Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
5ff13ad
commit 578137f
Showing
23 changed files
with
439 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 0 additions & 96 deletions
96
x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.test.js
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ESAggField, esAggFieldsFactory } from './es_agg_field'; | ||
import { AGG_TYPE, FIELD_ORIGIN } from '../../../common/constants'; | ||
import { IESAggSource } from '../sources/es_agg_source'; | ||
import { IIndexPattern } from 'src/plugins/data/public'; | ||
|
||
const mockIndexPattern = { | ||
title: 'wildIndex', | ||
fields: [ | ||
{ | ||
name: 'foo*', | ||
}, | ||
], | ||
} as IIndexPattern; | ||
|
||
const mockEsAggSource = { | ||
getAggKey: (aggType: AGG_TYPE, fieldName: string) => { | ||
return 'agg_key'; | ||
}, | ||
getAggLabel: (aggType: AGG_TYPE, fieldName: string) => { | ||
return 'agg_label'; | ||
}, | ||
getIndexPattern: async () => { | ||
return mockIndexPattern; | ||
}, | ||
} as IESAggSource; | ||
|
||
const defaultParams = { | ||
label: 'my agg field', | ||
source: mockEsAggSource, | ||
aggType: AGG_TYPE.COUNT, | ||
origin: FIELD_ORIGIN.SOURCE, | ||
}; | ||
|
||
describe('supportsFieldMeta', () => { | ||
test('Non-counting aggregations should support field meta', () => { | ||
const avgMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.AVG }); | ||
expect(avgMetric.supportsFieldMeta()).toBe(true); | ||
const maxMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.MAX }); | ||
expect(maxMetric.supportsFieldMeta()).toBe(true); | ||
const minMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.MIN }); | ||
expect(minMetric.supportsFieldMeta()).toBe(true); | ||
const termsMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.TERMS }); | ||
expect(termsMetric.supportsFieldMeta()).toBe(true); | ||
}); | ||
|
||
test('Counting aggregations should not support field meta', () => { | ||
const countMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.COUNT }); | ||
expect(countMetric.supportsFieldMeta()).toBe(false); | ||
const sumMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.SUM }); | ||
expect(sumMetric.supportsFieldMeta()).toBe(false); | ||
const uniqueCountMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.UNIQUE_COUNT }); | ||
expect(uniqueCountMetric.supportsFieldMeta()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('esAggFieldsFactory', () => { | ||
test('Should only create top terms field when term field is not provided', () => { | ||
const fields = esAggFieldsFactory( | ||
{ type: AGG_TYPE.TERMS }, | ||
mockEsAggSource, | ||
FIELD_ORIGIN.SOURCE | ||
); | ||
expect(fields.length).toBe(1); | ||
}); | ||
|
||
test('Should create top terms and top terms percentage fields', () => { | ||
const fields = esAggFieldsFactory( | ||
{ type: AGG_TYPE.TERMS, field: 'myField' }, | ||
mockEsAggSource, | ||
FIELD_ORIGIN.SOURCE | ||
); | ||
expect(fields.length).toBe(2); | ||
}); | ||
}); |
Oops, something went wrong.