diff --git a/src/components/Filters/FilterRow/FilterRow.tsx b/src/components/Filters/FilterRow/FilterRow.tsx index 2591b3c77..a21f18ffc 100644 --- a/src/components/Filters/FilterRow/FilterRow.tsx +++ b/src/components/Filters/FilterRow/FilterRow.tsx @@ -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); diff --git a/src/components/Filters/FilterRow/filterRow.test.tsx b/src/components/Filters/FilterRow/filterRow.test.tsx new file mode 100644 index 000000000..278b243d2 --- /dev/null +++ b/src/components/Filters/FilterRow/filterRow.test.tsx @@ -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(); + }); +});