-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dan Dong <[email protected]>
- Loading branch information
1 parent
ee29940
commit e8b28de
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/plugins/vis_builder/public/application/components/data_tab/field_bucket.test.tsx
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,58 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
// @ts-ignore | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { IndexPatternField } from '../../../../../data/common'; | ||
// @ts-ignore | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
import { FieldBucket } from './field_bucket'; | ||
import { Bucket } from './types'; | ||
|
||
const mockUseIndexPatterns = jest.fn(() => ({ selected: 'mockIndexPattern' })); | ||
const mockUseOnAddFilter = jest.fn(); | ||
jest.mock('../../utils/use', () => ({ | ||
useIndexPatterns: jest.fn(() => mockUseIndexPatterns), | ||
useOnAddFilter: jest.fn(() => mockUseOnAddFilter), | ||
})); | ||
|
||
describe('visBuilder field bucket', function () { | ||
function mountComponent(field: IndexPatternField, bucket: Bucket) { | ||
const compProps = { field, bucket }; | ||
return mountWithIntl(<FieldBucket {...compProps} />); | ||
} | ||
|
||
it('should render with buttons if field is filterable', async () => { | ||
const field = new IndexPatternField( | ||
{ | ||
name: 'bytes', | ||
type: 'number', | ||
esTypes: ['long'], | ||
count: 10, | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
}, | ||
'bytes' | ||
); | ||
const bucket = { | ||
display: `display`, | ||
value: `value`, | ||
percent: 25, | ||
count: 100, | ||
}; | ||
const comp = mountComponent(field, bucket); | ||
const addButton = findTestSubject(comp, 'plus-bytes-value'); | ||
const minusButton = findTestSubject(comp, 'minus-bytes-value'); | ||
expect(addButton.length).toBe(1); | ||
expect(minusButton.length).toBe(1); | ||
|
||
addButton.simulate('click'); | ||
minusButton.simulate('click'); | ||
expect(mockUseOnAddFilter).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |