Skip to content

Commit

Permalink
[UnifiedFieldList] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Dec 16, 2022
1 parent d520180 commit 4327b66
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface FieldListFiltersProps<T extends FieldListItem> {
allFields?: FieldTypeFilterProps<T>['allFields'];
getCustomFieldType?: FieldTypeFilterProps<T>['getCustomFieldType'];
onSupportedFieldFilter?: FieldTypeFilterProps<T>['onSupportedFieldFilter'];
onChangeFieldTypes?: FieldTypeFilterProps<T>['onChange'];
onChangeFieldTypes: FieldTypeFilterProps<T>['onChange'];
nameFilter: FieldNameSearchProps['nameFilter'];
screenReaderDescriptionId?: FieldNameSearchProps['screenReaderDescriptionId'];
onChangeNameFilter: FieldNameSearchProps['onChange'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('UnifiedFieldList useFieldFilters()', () => {
expect(result.current.onFilterField).toBeUndefined();

act(() => {
result.current.fieldListFiltersProps.onChangeFieldTypes!(['number']);
result.current.fieldListFiltersProps.onChangeFieldTypes(['number']);
});

expect(result.current.onFilterField).toBeDefined();
Expand All @@ -102,7 +102,7 @@ describe('UnifiedFieldList useFieldFilters()', () => {
expect(result.current.fieldListFiltersProps.getCustomFieldType).toBe(props.getCustomFieldType);

act(() => {
result.current.fieldListFiltersProps.onChangeFieldTypes!(['bytes', '@timestamp']);
result.current.fieldListFiltersProps.onChangeFieldTypes(['bytes', '@timestamp']);
});

expect(result.current.onFilterField).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { renderHook } from '@testing-library/react-hooks';
import { act } from 'react-test-renderer';
import {
stubDataViewWithoutTimeField,
stubLogstashDataView as dataView,
Expand Down Expand Up @@ -592,4 +593,48 @@ describe('UnifiedFieldList useGroupedFields()', () => {

expect(fieldGroups.SelectedFields?.fields).toBe(customSortedFields);
});

it('should include filters props', async () => {
const { result, waitForNextUpdate } = renderHook(useGroupedFields, {
initialProps: {
dataViewId: dataView.id!,
allFields,
services: mockedServices,
},
});

await waitForNextUpdate();

const { fieldListFiltersProps, fieldListGroupedProps } = result.current;
const fieldGroups = fieldListGroupedProps.fieldGroups;

expect(fieldGroups.AvailableFields?.fields?.length).toBe(25);
expect(fieldGroups.AvailableFields?.fieldSearchHighlight).toBeUndefined();
expect(fieldListFiltersProps.screenReaderDescriptionId).toBe(
fieldListGroupedProps.screenReaderDescriptionId
);

act(() => {
fieldListFiltersProps.onChangeNameFilter('Me');
});

const {
fieldListFiltersProps: newFieldListFiltersProps,
fieldListGroupedProps: newFieldListGroupedProps,
} = result.current;
const newFieldGroups = newFieldListGroupedProps.fieldGroups;
expect(newFieldGroups.AvailableFields?.fields?.length).toBe(4);
expect(newFieldGroups.AvailableFields?.fieldSearchHighlight).toBe('me');
expect(newFieldListFiltersProps.screenReaderDescriptionId).toBe(
newFieldListGroupedProps.screenReaderDescriptionId
);

act(() => {
newFieldListFiltersProps.onChangeFieldTypes?.(['date']);
});

expect(result.current.fieldListGroupedProps.fieldGroups.AvailableFields?.fields?.length).toBe(
3
);
});
});

0 comments on commit 4327b66

Please sign in to comment.