Skip to content

Commit

Permalink
fix(native-filters): Range filter max/min default display value (#21680)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Oct 4, 2022
1 parent 3057e42 commit f784455
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit f784455

Please sign in to comment.