diff --git a/CHANGELOG.md b/CHANGELOG.md index e20416b..9e27c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [UIPQB-162](https://folio-org.atlassian.net/browse/UIPQB-162) Errors when query includes a modified custom field. * [UIPQB-175](https://folio-org.atlassian.net/browse/UIPQB-175) Displays the "Smth went wrong" page, when the user clicks on "Select operator" dropdown and selects any of them, if there are deleted custom fields. * [UIPQB-164](https://folio-org.atlassian.net/browse/UIPQB-164) Columns are reset when user modifies query. +* [UIPQB-179](https://folio-org.atlassian.net/browse/UIPQB-179) Fix string-based booleans improperly displaying. ## [1.2.7](https://github.com/folio-org/ui-plugin-query-builder/tree/v1.2.7) (2024-12-26) diff --git a/src/QueryBuilder/ResultViewer/utils.js b/src/QueryBuilder/ResultViewer/utils.js index 37be439..79863c3 100644 --- a/src/QueryBuilder/ResultViewer/utils.js +++ b/src/QueryBuilder/ResultViewer/utils.js @@ -11,16 +11,27 @@ export const formatValueByDataType = (value, dataType, intl, additionalParams = switch (dataType) { case DATA_TYPES.BooleanType: - return value - ? - : ; + // booleans may be returned as true booleans, or strings 'true' or 'false' + if (typeof value === 'string') { + return value === 'true' ? ( + + ) : ( + + ); + } else { + return value ? ( + + ) : ( + + ); + } case DATA_TYPES.DateType: return ; case DATA_TYPES.ArrayType: if (additionalParams?.isInstanceLanguages) { - return value.map(lang => formattedLanguageName(lang, intl)).join(' | '); + return value.map((lang) => formattedLanguageName(lang, intl)).join(' | '); } return value.join(' | '); diff --git a/src/QueryBuilder/ResultViewer/utils.test.js b/src/QueryBuilder/ResultViewer/utils.test.js new file mode 100644 index 0000000..dfaf2ac --- /dev/null +++ b/src/QueryBuilder/ResultViewer/utils.test.js @@ -0,0 +1,39 @@ +import '@testing-library/jest-dom'; +import { render } from '@testing-library/react'; +import { IntlProvider } from 'react-intl'; +import { DATA_TYPES } from '../../constants/dataTypes'; +import { formatValueByDataType } from './utils'; + +describe('formatValueByDataType returns correct value', () => { + test.each([ + [undefined, DATA_TYPES.StringType, ''], + [null, DATA_TYPES.StringType, ''], + + [true, DATA_TYPES.BooleanType, 'ui-plugin-query-builder.options.true'], + [false, DATA_TYPES.BooleanType, 'ui-plugin-query-builder.options.false'], + ['true', DATA_TYPES.BooleanType, 'ui-plugin-query-builder.options.true'], + ['false', DATA_TYPES.BooleanType, 'ui-plugin-query-builder.options.false'], + + ['2024-01-01T12:30:00Z', DATA_TYPES.StringType, '2024-01-01T12:30:00Z'], + ['2024-01-01T12:30:00Z', DATA_TYPES.DateType, '1/1/2024'], + ['2024-01-01T12:30:00Z', DATA_TYPES.DateType, '1/1/2024'], + + [[], DATA_TYPES.ArrayType, ''], + [['a'], DATA_TYPES.ArrayType, 'a'], + [['a', 'b', 'c'], DATA_TYPES.ArrayType, 'a | b | c'], + + [1234, DATA_TYPES.IntegerType, '1234'], + [12.34, DATA_TYPES.NumberType, '12.34'], + + [false, DATA_TYPES.StringType, ''], + ['foo', DATA_TYPES.StringType, 'foo'], + ])('value=%j of type=%p renders to %p', (value, type, expected) => { + const formatted = formatValueByDataType(value, type, null); + + if (typeof formatted === 'string') { + expect(formatted).toBe(expected); + } else { + expect(render({formatted}).container.innerHTML).toBe(expected); + } + }); +});