mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* fix #81465 (FilterByValueTransformerEditor.tsx): Exclude-null now it's getting initialised properly by default The default matcher of a new filter by value condition has been changed from greater to isNull. Added a file FilterByValueTransformerEditor.test.tsx with a test to confirm this change * update tests and run linter * filter-by-values-exclude-null/ update test definition --------- Co-authored-by: jev forsberg <jev.forsberg@grafana.com>
This commit is contained in:
parent
cd05568459
commit
d23918fd95
@ -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(
|
||||||
|
<FilterByValueTransformerEditor input={input} options={options} onChange={onChangeMock} />
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -49,7 +49,7 @@ export const FilterByValueTransformerEditor = (props: TransformerUIProps<FilterB
|
|||||||
}
|
}
|
||||||
|
|
||||||
const filters = cloneDeep(options.filters);
|
const filters = cloneDeep(options.filters);
|
||||||
const matcher = valueMatchers.get(ValueMatcherID.greater);
|
const matcher = valueMatchers.get(ValueMatcherID.isNull);
|
||||||
|
|
||||||
filters.push({
|
filters.push({
|
||||||
fieldName: getFieldDisplayName(field, frame, input),
|
fieldName: getFieldDisplayName(field, frame, input),
|
||||||
|
Loading…
Reference in New Issue
Block a user