-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis Builder] Add additional unit tests
Signed-off-by: Josh Romero <rmerqg@amazon.com>
- Loading branch information
1 parent
5924be8
commit bf85518
Showing
5 changed files
with
129 additions
and
7 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
75 changes: 75 additions & 0 deletions
75
src/plugins/vis_builder/public/application/components/data_tab/field_selector.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,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { FilterManager, IndexPatternField } from '../../../../../data/public'; | ||
import { FieldGroup } from './field_selector'; | ||
|
||
const mockGetDetails = jest.fn(() => ({ | ||
buckets: [1, 2, 3].map((n) => ({ | ||
display: `display-${n}`, | ||
value: `value-${n}`, | ||
percent: 25, | ||
count: 100, | ||
})), | ||
error: '', | ||
exists: 100, | ||
total: 150, | ||
})); | ||
|
||
const getFields = (name) => { | ||
return new IndexPatternField( | ||
{ | ||
name, | ||
type: 'number', | ||
esTypes: ['long'], | ||
count: 10, | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
}, | ||
name | ||
); | ||
}; | ||
|
||
describe('visBuilder sidebar field selector', function () { | ||
const defaultProps = { | ||
filterManager: {} as FilterManager, | ||
getDetails: mockGetDetails, | ||
header: 'mockHeader', | ||
id: 'mockID', | ||
}; | ||
describe('FieldGroup', () => { | ||
it('renders an empty accordion if no fields specified', async () => { | ||
const { container } = render(<FieldGroup {...defaultProps} />); | ||
|
||
expect(container).toHaveTextContent(defaultProps.header); | ||
expect(container).toHaveTextContent('0'); | ||
expect(screen.queryAllByTestId('field-selector-field').length).toBeFalsy(); | ||
|
||
await fireEvent.click(screen.getByText(defaultProps.header)); | ||
|
||
expect(mockGetDetails).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('renders an accordion with FieldSelectorFields if fields provided', async () => { | ||
const props = { | ||
...defaultProps, | ||
fields: ['bytes', 'machine.ram', 'memory', 'phpmemory'].map(getFields), | ||
}; | ||
const { container } = render(<FieldGroup {...props} />); | ||
|
||
expect(container).toHaveTextContent(props.header); | ||
expect(container).toHaveTextContent(props.fields.length.toString()); | ||
expect(screen.queryAllByTestId('field-selector-field').length).toBe(props.fields.length); | ||
|
||
await fireEvent.click(screen.getByText('memory')); | ||
|
||
expect(mockGetDetails).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
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
46 changes: 46 additions & 0 deletions
46
src/plugins/vis_builder/public/application/components/data_tab/field_selector_field.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,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { IndexPatternField } from '../../../../../data/public'; | ||
|
||
import { SelectorFieldButton } from './field_selector_field'; | ||
|
||
describe('visBuilder sidebar field selector field', function () { | ||
describe('SelectorFieldButton', () => { | ||
it('should render normal fields without a dragValue specified', async () => { | ||
const props = { | ||
field: new IndexPatternField( | ||
{ | ||
name: 'bytes', | ||
type: 'number', | ||
esTypes: ['long'], | ||
count: 10, | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
}, | ||
'bytes' | ||
), | ||
}; | ||
render(<SelectorFieldButton {...props} />); | ||
|
||
expect(screen.getByTestId('field-bytes-showDetails')).toBeDefined(); | ||
}); | ||
|
||
// it('should allow specified dragValue to override the field name'); | ||
|
||
// it('should make dots wrappable'); | ||
|
||
// it('should use a non-scripted FieldIcon by default'); | ||
}); | ||
|
||
// describe('FieldSelectorField', function () { | ||
|
||
// }); | ||
}); |
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