-
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.
- Loading branch information
Maja Grubic
committed
Feb 7, 2021
1 parent
f7c845e
commit 21b011e
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/plugins/discover/public/__mocks__/index_pattern_with_source_filter.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,83 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { IIndexPatternFieldList } from '../../../data/common/index_patterns/fields'; | ||
import { IndexPattern } from '../../../data/common'; | ||
import { indexPatterns } from '../../../data/public'; | ||
|
||
const fields = [ | ||
{ | ||
name: '_source', | ||
type: '_source', | ||
scripted: false, | ||
filterable: false, | ||
aggregatable: false, | ||
}, | ||
{ | ||
name: '_index', | ||
type: 'string', | ||
scripted: false, | ||
filterable: true, | ||
aggregatable: false, | ||
}, | ||
{ | ||
name: 'message', | ||
type: 'string', | ||
scripted: false, | ||
filterable: false, | ||
aggregatable: false, | ||
}, | ||
{ | ||
name: 'extension', | ||
type: 'string', | ||
scripted: false, | ||
filterable: true, | ||
aggregatable: true, | ||
}, | ||
{ | ||
name: 'bytes', | ||
type: 'number', | ||
scripted: false, | ||
filterable: true, | ||
aggregatable: true, | ||
}, | ||
{ | ||
name: 'scripted', | ||
type: 'number', | ||
scripted: true, | ||
filterable: false, | ||
}, | ||
] as IIndexPatternFieldList; | ||
|
||
fields.getByName = (name: string) => { | ||
return fields.find((field) => field.name === name); | ||
}; | ||
|
||
const indexPattern = ({ | ||
id: 'the-index-pattern-id', | ||
title: 'the-index-pattern-title', | ||
metaFields: ['_index', '_score'], | ||
formatField: jest.fn(), | ||
flattenHit: undefined, | ||
formatHit: jest.fn((hit) => hit._source), | ||
fields, | ||
sourceFilters: [{ value: 'bytes' }], | ||
getComputedFields: () => ({ docvalueFields: [], scriptFields: {}, storedFields: ['*'] }), | ||
getSourceFiltering: () => ({}), | ||
getFieldByName: () => ({}), | ||
timeFieldName: '', | ||
docvalueFields: [], | ||
} as unknown) as IndexPattern; | ||
|
||
indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields); | ||
indexPattern.isTimeBased = () => !!indexPattern.timeFieldName; | ||
indexPattern.formatField = (hit: Record<string, any>, fieldName: string) => { | ||
return fieldName === '_source' ? hit._source : indexPattern.flattenHit(hit)[fieldName]; | ||
}; | ||
|
||
export const indexPatternWithSourceFilterMock = indexPattern; |
47 changes: 47 additions & 0 deletions
47
src/plugins/discover/public/application/helpers/get_field_list.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,47 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { indexPatternMock } from '../../__mocks__/index_pattern'; | ||
import { getFieldListFromIndexPattern } from './get_field_list'; | ||
import { indexPatternWithSourceFilterMock } from '../../__mocks__/index_pattern_with_source_filter'; | ||
|
||
describe('get field list test', () => { | ||
describe('no source filters', () => { | ||
test('returns all fields', async () => { | ||
expect(getFieldListFromIndexPattern(indexPatternMock, false)).toEqual([{ field: '*' }]); | ||
}); | ||
|
||
test('returns all fields with unmapped fields', async () => { | ||
expect(getFieldListFromIndexPattern(indexPatternMock, true)).toEqual([ | ||
{ field: '*', include_unmapped: 'true' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('with source filters', () => { | ||
test('returns all fields', async () => { | ||
const fields = [ | ||
{ field: '_index' }, | ||
{ field: 'message' }, | ||
{ field: 'extension' }, | ||
{ field: 'scripted' }, | ||
]; | ||
expect(getFieldListFromIndexPattern(indexPatternWithSourceFilterMock, false)).toEqual(fields); | ||
}); | ||
|
||
test('returns all fields with unmapped fields', async () => { | ||
const fields = [ | ||
{ field: '_index', include_unmapped: 'true' }, | ||
{ field: 'message', include_unmapped: 'true' }, | ||
{ field: 'extension', include_unmapped: 'true' }, | ||
{ field: 'scripted', include_unmapped: 'true' }, | ||
]; | ||
expect(getFieldListFromIndexPattern(indexPatternWithSourceFilterMock, true)).toEqual(fields); | ||
}); | ||
}); | ||
}); |