Skip to content

Commit

Permalink
Updated testing
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Dong <[email protected]>
  • Loading branch information
danieldong51 committed Jul 22, 2024
1 parent ee29940 commit b27424f
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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();
});
});

0 comments on commit b27424f

Please sign in to comment.