-
Notifications
You must be signed in to change notification settings - Fork 890
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 b27424f
Showing
2 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...s_builder/public/application/components/data_tab/__snapshots__/field_bucket.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
/* | ||
* 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'; | ||
import { EuiSmallButtonIcon } from '@elastic/eui'; | ||
|
||
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 props = { | ||
// key: 'bucket1', | ||
// bucket: { | ||
// count: 100, | ||
// display: 'display', | ||
// percent: 5, | ||
// value: '12', | ||
// }, | ||
// field: new IndexPatternField( | ||
// { | ||
// name: 'bytes', | ||
// type: 'number', | ||
// esTypes: ['long'], | ||
// count: 10, | ||
// scripted: false, | ||
// searchable: true, | ||
// aggregatable: true, | ||
// readFromDocValues: true, | ||
// }, | ||
// 'bytes' | ||
// ), | ||
// }; | ||
// mountWithIntl(<FieldBucket {...props} />); | ||
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); | ||
expect(findTestSubject(comp, 'plus-bytes-value').length).toBe(1); | ||
expect(findTestSubject(comp, 'minus-bytes-value').length).toBe(1); | ||
expect(comp.find(EuiSmallButtonIcon)).toMatchSnapshot(); | ||
}); | ||
}); |