-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] create NOT EXISTS filter for tooltip property with no value (#…
…62849) (#63143) * [Maps] create NOT EXISTS filter for tooltip property with no value * review feedback
- Loading branch information
Showing
4 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
x-pack/plugins/maps/public/layers/tooltips/es_tooltip_property.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,105 @@ | ||
/* | ||
* 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 { IFieldType, IndexPattern } from '../../../../../../src/plugins/data/public'; | ||
import { ESTooltipProperty } from './es_tooltip_property'; | ||
import { TooltipProperty } from './tooltip_property'; | ||
import { AbstractField } from '../fields/field'; | ||
import { FIELD_ORIGIN } from '../../../common/constants'; | ||
|
||
class MockField extends AbstractField {} | ||
|
||
const indexPatternField = { | ||
name: 'machine.os', | ||
type: 'string', | ||
esTypes: ['text'], | ||
count: 0, | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: false, | ||
} as IFieldType; | ||
|
||
const featurePropertyField = new MockField({ | ||
fieldName: 'machine.os', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
}); | ||
|
||
const indexPattern = { | ||
id: 'indexPatternId', | ||
fields: { | ||
getByName: (name: string): IFieldType | null => { | ||
return name === 'machine.os' ? indexPatternField : null; | ||
}, | ||
}, | ||
title: 'my index pattern', | ||
} as IndexPattern; | ||
|
||
describe('getESFilters', () => { | ||
test('Should return empty array when field does not exist in index pattern', async () => { | ||
const notFoundFeaturePropertyField = new MockField({ | ||
fieldName: 'field name that is not in index pattern', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
}); | ||
const esTooltipProperty = new ESTooltipProperty( | ||
new TooltipProperty( | ||
notFoundFeaturePropertyField.getName(), | ||
await notFoundFeaturePropertyField.getLabel(), | ||
'my value' | ||
), | ||
indexPattern, | ||
notFoundFeaturePropertyField | ||
); | ||
expect(await esTooltipProperty.getESFilters()).toEqual([]); | ||
}); | ||
|
||
test('Should return phrase filter when field value is provided', async () => { | ||
const esTooltipProperty = new ESTooltipProperty( | ||
new TooltipProperty( | ||
featurePropertyField.getName(), | ||
await featurePropertyField.getLabel(), | ||
'my value' | ||
), | ||
indexPattern, | ||
featurePropertyField | ||
); | ||
expect(await esTooltipProperty.getESFilters()).toEqual([ | ||
{ | ||
meta: { | ||
index: 'indexPatternId', | ||
}, | ||
query: { | ||
match_phrase: { | ||
['machine.os']: 'my value', | ||
}, | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
test('Should return NOT exists filter for null values', async () => { | ||
const esTooltipProperty = new ESTooltipProperty( | ||
new TooltipProperty( | ||
featurePropertyField.getName(), | ||
await featurePropertyField.getLabel(), | ||
undefined | ||
), | ||
indexPattern, | ||
featurePropertyField | ||
); | ||
expect(await esTooltipProperty.getESFilters()).toEqual([ | ||
{ | ||
meta: { | ||
index: 'indexPatternId', | ||
negate: true, | ||
}, | ||
exists: { | ||
field: 'machine.os', | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); |
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
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