diff --git a/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.test.tsx b/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.test.tsx new file mode 100644 index 00000000000..fd19c7a3b8f --- /dev/null +++ b/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.test.tsx @@ -0,0 +1,70 @@ +import { render, fireEvent } from '@testing-library/react'; +import React from 'react'; + +import { DataFrame, FieldType, ValueMatcherID, valueMatchers } from '@grafana/data'; +import { FilterByValueMatch, FilterByValueType } from '@grafana/data/src/transformations/transformers/filterByValue'; + +import { FilterByValueTransformerEditor } from './FilterByValueTransformerEditor'; + +describe('FilterByValueTransformerEditor', () => { + it('correctly applies the default isNull option when onAddFilter is first called', () => { + // Mock onChange function + const onChangeMock = jest.fn(); + + // Mock options + const options = { + type: FilterByValueType.include, + match: FilterByValueMatch.all, + filters: [], + }; + + // Mock input + const input: DataFrame[] = [ + { + fields: [ + { + name: 'person', + type: FieldType.string, + config: { displayName: 'Person' }, + values: ['john', 'jill', 'jeremy', ''], + }, + { + name: 'city', + type: FieldType.string, + config: { displayName: 'City' }, + values: ['london', 'budapest', '', 'lisbon'], + }, + ], + length: 4, + }, + ]; + + // Render the component + const { getByText } = render( + + ); + + // Find and click the "Add condition" button + fireEvent.click(getByText('Add condition')); + + // Check if onChange was called with the correct filter + expect(onChangeMock).toHaveBeenCalledWith({ + filters: [ + { + fieldName: 'Person', + config: { + id: ValueMatcherID.isNull, + options: valueMatchers.get(ValueMatcherID.isNull).getDefaultOptions({ + name: 'person', + type: FieldType.string, + config: { displayName: 'Person' }, + values: ['john', 'jill', 'jeremy', ''], + }), + }, + }, + ], + match: FilterByValueMatch.all, + type: FilterByValueType.include, + }); + }); +}); diff --git a/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.tsx b/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.tsx index bb5ecf34abf..f342e5a96c4 100644 --- a/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.tsx +++ b/public/app/features/transformers/FilterByValueTransformer/FilterByValueTransformerEditor.tsx @@ -49,7 +49,7 @@ export const FilterByValueTransformerEditor = (props: TransformerUIProps