Skip to content

Commit

Permalink
fix(Filters): make operator parsing case insensitive
Browse files Browse the repository at this point in the history
Closes UXD-1661
  • Loading branch information
ajkl2533 committed Oct 31, 2024
1 parent 1dbf935 commit 5ac4aa5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/Filters/FilterRow/FilterRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ const getConditionComponent = curry(
)(fieldValue, fields),
);

const getOperatorOptions = (operatorValue, operatorOptions) =>
find(propEq('value', operatorValue), operatorOptions);
export const getOperatorOptions = (
operatorValue: string,
operatorOptions: { value: string; label: string }[],
) => find(propEq('value', operatorValue.toLowerCase()), operatorOptions);

const getFieldOptions = map(normalizeOptions);

Expand Down
40 changes: 40 additions & 0 deletions src/components/Filters/FilterRow/filterRow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getOperatorOptions } from './FilterRow';

describe('getOperatorOptions', () => {
it('should return the correct operator option when a matching value exists', () => {
const operatorValue = 'or';
const operatorOptions = [
{ value: 'or', label: 'or' },
{ value: 'and', label: 'and' },
];
const result = getOperatorOptions(operatorValue, operatorOptions);
expect(result).toEqual({ value: 'or', label: 'or' });
});

it('should return the correct operator option when a matching value exists (CASE INSENSITIVE)', () => {
const operatorValue = 'OR';
const operatorOptions = [
{ value: 'or', label: 'or' },
{ value: 'and', label: 'and' },
];
const result = getOperatorOptions(operatorValue, operatorOptions);
expect(result).toEqual({ value: 'or', label: 'or' });
});

it('should return undefined when no matching operator value is found', () => {
const operatorValue = 'greaterThan';
const operatorOptions = [
{ value: 'or', label: 'or' },
{ value: 'and', label: 'and' },
];
const result = getOperatorOptions(operatorValue, operatorOptions);
expect(result).toBeUndefined();
});

it('should return undefined when operatorOptions array is empty', () => {
const operatorValue = 'or';
const operatorOptions = [];
const result = getOperatorOptions(operatorValue, operatorOptions);
expect(result).toBeUndefined();
});
});

0 comments on commit 5ac4aa5

Please sign in to comment.