fix(native-filters): Range filter max/min default display value (#21680)

This commit is contained in:
Kamil Gabryjelski 2022-10-04 13:26:47 +02:00 committed by GitHub
parent 3057e4270c
commit f784455264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View File

@ -18,7 +18,7 @@
*/
import { AppSection, GenericDataType } from '@superset-ui/core';
import React from 'react';
import { render } from 'spec/helpers/testing-library';
import { render, screen } from 'spec/helpers/testing-library';
import RangeFilterPlugin from './RangeFilterPlugin';
import { SingleValueType } from './SingleValueType';
import transformProps from './transformProps';
@ -121,41 +121,49 @@ describe('RangeFilterPlugin', () => {
});
it('should call setDataMask with correct greater than filter', () => {
getWrapper({ enableSingleValue: SingleValueType.Minimum });
getWrapper({
enableSingleValue: SingleValueType.Minimum,
defaultValue: [20, 60],
});
expect(setDataMask).toHaveBeenCalledWith({
extraFormData: {
filters: [
{
col: 'SP_POP_TOTL',
op: '>=',
val: 70,
val: 20,
},
],
},
filterState: {
label: 'x ≥ 70',
value: [70, 100],
label: 'x ≥ 20',
value: [20, 100],
},
});
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '20');
});
it('should call setDataMask with correct less than filter', () => {
getWrapper({ enableSingleValue: SingleValueType.Maximum });
getWrapper({
enableSingleValue: SingleValueType.Maximum,
defaultValue: [20, 60],
});
expect(setDataMask).toHaveBeenCalledWith({
extraFormData: {
filters: [
{
col: 'SP_POP_TOTL',
op: '<=',
val: 70,
val: 60,
},
],
},
filterState: {
label: 'x ≤ 70',
value: [10, 70],
label: 'x ≤ 60',
value: [10, 60],
},
});
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '60');
});
it('should call setDataMask with correct exact filter', () => {

View File

@ -261,13 +261,13 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
useEffect(() => {
if (enableSingleMaxValue) {
handleAfterChange([min, minMax[minIndex]]);
handleAfterChange([min, minMax[maxIndex]]);
}
}, [enableSingleMaxValue]);
useEffect(() => {
if (enableSingleMinValue) {
handleAfterChange([minMax[maxIndex], max]);
handleAfterChange([minMax[minIndex], max]);
}
}, [enableSingleMinValue]);