-
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.
Merge branch 'master' into misc-pass-1
- Loading branch information
Showing
38 changed files
with
2,282 additions
and
2,697 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
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
45 changes: 45 additions & 0 deletions
45
src/plugins/data/public/query/filter_manager/lib/get_display_value.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,45 @@ | ||
/* | ||
* 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 { stubIndexPattern, phraseFilter } from 'src/plugins/data/common/stubs'; | ||
import { getDisplayValueFromFilter } from './get_display_value'; | ||
|
||
describe('getDisplayValueFromFilter', () => { | ||
it('returns the value if string', () => { | ||
phraseFilter.meta.value = 'abc'; | ||
const displayValue = getDisplayValueFromFilter(phraseFilter, [stubIndexPattern]); | ||
expect(displayValue).toBe('abc'); | ||
}); | ||
|
||
it('returns the value if undefined', () => { | ||
phraseFilter.meta.value = undefined; | ||
const displayValue = getDisplayValueFromFilter(phraseFilter, [stubIndexPattern]); | ||
expect(displayValue).toBe(''); | ||
}); | ||
|
||
it('calls the value function if proivided', () => { | ||
// The type of value currently doesn't match how it's used. Refactor needed. | ||
phraseFilter.meta.value = jest.fn((x) => { | ||
return 'abc'; | ||
}) as any; | ||
const displayValue = getDisplayValueFromFilter(phraseFilter, [stubIndexPattern]); | ||
expect(displayValue).toBe('abc'); | ||
expect(phraseFilter.meta.value).toHaveBeenCalledWith(undefined); | ||
}); | ||
|
||
it('calls the value function if proivided, with formatter', () => { | ||
stubIndexPattern.getFormatterForField = jest.fn().mockReturnValue('banana'); | ||
phraseFilter.meta.value = jest.fn((x) => { | ||
return x + 'abc'; | ||
}) as any; | ||
const displayValue = getDisplayValueFromFilter(phraseFilter, [stubIndexPattern]); | ||
expect(stubIndexPattern.getFormatterForField).toHaveBeenCalledTimes(1); | ||
expect(phraseFilter.meta.value).toHaveBeenCalledWith('banana'); | ||
expect(displayValue).toBe('bananaabc'); | ||
}); | ||
}); |
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.