-
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.
Browse files
Browse the repository at this point in the history
* Converted files to TS. Added tests. * Removed ts-ignore * Fixed comments and tests * Fixed error * Fixed tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Uladzislau Lasitsa <vlad.lasitsa@gmail.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
a9c24bf
commit 461eea4
Showing
7 changed files
with
330 additions
and
34 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
src/legacy/core_plugins/data/public/actions/filters/create_filters_from_event.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,119 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { | ||
fieldFormats, | ||
FieldFormatsGetConfigFn, | ||
esFilters, | ||
IndexPatternsContract, | ||
} from '../../../../../../plugins/data/public'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { setIndexPatterns } from '../../../../../../plugins/data/public/services'; | ||
import { dataPluginMock } from '../../../../../../plugins/data/public/mocks'; | ||
import { createFiltersFromEvent, EventData } from './create_filters_from_event'; | ||
import { mockDataServices } from '../../search/aggs/test_helpers'; | ||
|
||
jest.mock('ui/new_platform'); | ||
|
||
const mockField = { | ||
name: 'bytes', | ||
indexPattern: { | ||
id: 'logstash-*', | ||
}, | ||
filterable: true, | ||
format: new fieldFormats.BytesFormat({}, (() => {}) as FieldFormatsGetConfigFn), | ||
}; | ||
|
||
describe('createFiltersFromEvent', () => { | ||
let dataPoints: EventData[]; | ||
|
||
beforeEach(() => { | ||
dataPoints = [ | ||
{ | ||
table: { | ||
columns: [ | ||
{ | ||
name: 'test', | ||
id: '1-1', | ||
meta: { | ||
type: 'histogram', | ||
indexPatternId: 'logstash-*', | ||
aggConfigParams: { | ||
field: 'bytes', | ||
interval: 30, | ||
otherBucket: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
rows: [ | ||
{ | ||
'1-1': '2048', | ||
}, | ||
], | ||
}, | ||
column: 0, | ||
row: 0, | ||
value: 'test', | ||
}, | ||
]; | ||
|
||
mockDataServices(); | ||
setIndexPatterns(({ | ||
...dataPluginMock.createStartContract().indexPatterns, | ||
get: async () => ({ | ||
id: 'logstash-*', | ||
fields: { | ||
getByName: () => mockField, | ||
filter: () => [mockField], | ||
}, | ||
}), | ||
} as unknown) as IndexPatternsContract); | ||
}); | ||
|
||
test('ignores event when value for rows is not provided', async () => { | ||
dataPoints[0].table.rows[0]['1-1'] = null; | ||
const filters = await createFiltersFromEvent(dataPoints); | ||
|
||
expect(filters.length).toEqual(0); | ||
}); | ||
|
||
test('handles an event when aggregations type is a terms', async () => { | ||
if (dataPoints[0].table.columns[0].meta) { | ||
dataPoints[0].table.columns[0].meta.type = 'terms'; | ||
} | ||
const filters = await createFiltersFromEvent(dataPoints); | ||
|
||
expect(filters.length).toEqual(1); | ||
expect(filters[0].query.match_phrase.bytes).toEqual('2048'); | ||
}); | ||
|
||
test('handles an event when aggregations type is not terms', async () => { | ||
const filters = await createFiltersFromEvent(dataPoints); | ||
|
||
expect(filters.length).toEqual(1); | ||
|
||
const [rangeFilter] = filters; | ||
|
||
if (esFilters.isRangeFilter(rangeFilter)) { | ||
expect(rangeFilter.range.bytes.gte).toEqual(2048); | ||
expect(rangeFilter.range.bytes.lt).toEqual(2078); | ||
} | ||
}); | ||
}); |
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
Oops, something went wrong.