From fb4a2dcc4496a7365521cfeaddf10e9bb7ed4b7e Mon Sep 17 00:00:00 2001 From: Priyanka Terala <104053200+Terala-Priyanka@users.noreply.github.com> Date: Fri, 19 Jan 2024 19:29:30 +0530 Subject: [PATCH] STSMACOM-799 - Make helpText prop as optional for all types of custom field components (#1432) * STSMACOM-799 - Make helpText prop as optional for all types of custom field components * STSMACOM-799 - add test for checkbox type custom field * STSMACOM-799 - update unit test * STSMACOM-799 - cleanup * STSMACOM-799 - update tests * STSMACOM-799 - updates tests * STSMACOM-799 - add unit test * STSMACOM-799 - update unit test --- CHANGELOG.md | 3 ++- .../view-sections/CheckboxSection.js | 4 ++-- .../view-sections/RadioButtonSetSections.js | 4 ++-- .../view-sections/SelectDropdownSection.js | 4 ++-- .../view-sections/TextboxSection.js | 4 ++-- .../view-sections/shared-values/HelpTextValue.js | 2 +- .../tests/EditCustomFieldsRecord-test.js | 2 +- .../tests/EditCustomFieldsSettings-test.js | 8 ++++---- .../tests/ViewCustomFieldsRecord-test.js | 2 +- .../tests/ViewCustomFieldsSettings-test.js | 10 ++++++++++ .../ViewCustomFieldsSettings/tests/interactor.js | 2 +- tests/network/config.js | 16 +++++++++++++++- 12 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae0ed452..fdaf0f62b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Export new `advancedSearchQueryToRows` helper to be used in Inventory app to reduce code duplication. Refs STSMACOM-787. * Show the username in the "last updated" accordion in the Note editing pane. Fixes STSMACOM-748. * Added `indexRef` and `inputRef` props to ``. Refs STSMACOM-788. -* Extend NotesAccordion and NotesSmartAccodion components to accept a prop hideNewButton. Refs STSMACOM-789. +* Extend NotesAccordion and NotesSmartAccordion components to accept a prop hideNewButton. Refs STSMACOM-789. * Extend `Tags` component to accept `mutateEntity` prop. Refs STSMACOM-792. * Refactor CSS away from postcss-color-function. Refs STSMACOM-791. * `` now passes the `entityType` when making PUT requests to `/custom-fields`. Refs FCFIELDS-44. @@ -15,6 +15,7 @@ * Show successful toast notifications for Create and Edit actions in ``. Refs STSMACOM-796. * `` - last updated by column - show "System" when items are created by system user. Refs STSMACOM-797. * Add field type `DATE_PICKER` to custom fields components. Refs STSMACOM-800. +* Make `helpText` prop as optional for all types of custom field components. Refs STSMACOM-799. ## [9.0.0](https://github.com/folio-org/stripes-smart-components/tree/v9.0.0) (2023-10-11) [Full Changelog](https://github.com/folio-org/stripes-smart-components/compare/v8.0.0...v9.0.0) diff --git a/lib/CustomFields/components/FieldAccordion/view-sections/CheckboxSection.js b/lib/CustomFields/components/FieldAccordion/view-sections/CheckboxSection.js index da9ec7781..8c183eb0b 100644 --- a/lib/CustomFields/components/FieldAccordion/view-sections/CheckboxSection.js +++ b/lib/CustomFields/components/FieldAccordion/view-sections/CheckboxSection.js @@ -9,14 +9,14 @@ import { } from './shared-values'; const propTypes = { - helpText: PropTypes.string.isRequired, + helpText: PropTypes.string, name: PropTypes.string.isRequired, }; const CheckboxSection = props => ( - + { props.helpText && } ); diff --git a/lib/CustomFields/components/FieldAccordion/view-sections/RadioButtonSetSections.js b/lib/CustomFields/components/FieldAccordion/view-sections/RadioButtonSetSections.js index 760e6b4bf..b578a4385 100644 --- a/lib/CustomFields/components/FieldAccordion/view-sections/RadioButtonSetSections.js +++ b/lib/CustomFields/components/FieldAccordion/view-sections/RadioButtonSetSections.js @@ -10,7 +10,7 @@ import { } from './shared-values'; const propTypes = { - helpText: PropTypes.string.isRequired, + helpText: PropTypes.string, name: PropTypes.string.isRequired, selectField: PropTypes.shape({ defaults: PropTypes.arrayOf(PropTypes.string), @@ -29,7 +29,7 @@ const RadioButtonSetSections = ({ <> - + { helpText && } diff --git a/lib/CustomFields/components/FieldAccordion/view-sections/SelectDropdownSection.js b/lib/CustomFields/components/FieldAccordion/view-sections/SelectDropdownSection.js index 5fa884c79..7f82cf8bf 100644 --- a/lib/CustomFields/components/FieldAccordion/view-sections/SelectDropdownSection.js +++ b/lib/CustomFields/components/FieldAccordion/view-sections/SelectDropdownSection.js @@ -12,7 +12,7 @@ import { import { fieldTypes } from '../../../constants'; const propTypes = { - helpText: PropTypes.string.isRequired, + helpText: PropTypes.string, name: PropTypes.string.isRequired, required: PropTypes.bool.isRequired, selectField: PropTypes.shape({ @@ -32,7 +32,7 @@ const SelectDropdownSection = props => { <> - + { props.helpText && } diff --git a/lib/CustomFields/components/FieldAccordion/view-sections/TextboxSection.js b/lib/CustomFields/components/FieldAccordion/view-sections/TextboxSection.js index 4deec1f80..d6b3222be 100644 --- a/lib/CustomFields/components/FieldAccordion/view-sections/TextboxSection.js +++ b/lib/CustomFields/components/FieldAccordion/view-sections/TextboxSection.js @@ -10,7 +10,7 @@ import { } from './shared-values'; const propTypes = { - helpText: PropTypes.string.isRequired, + helpText: PropTypes.string, name: PropTypes.string.isRequired, required: PropTypes.bool.isRequired, }; @@ -18,7 +18,7 @@ const propTypes = { const TextboxSection = props => ( - + { props.helpText && } ); diff --git a/lib/CustomFields/components/FieldAccordion/view-sections/shared-values/HelpTextValue.js b/lib/CustomFields/components/FieldAccordion/view-sections/shared-values/HelpTextValue.js index 54d273c33..4569102d1 100644 --- a/lib/CustomFields/components/FieldAccordion/view-sections/shared-values/HelpTextValue.js +++ b/lib/CustomFields/components/FieldAccordion/view-sections/shared-values/HelpTextValue.js @@ -10,7 +10,7 @@ import { const propTypes = { value: PropTypes.string.isRequired }; const HelpTextValue = ({ value }) => ( - value.length + value?.length ? ( { }); it('should show all visible custom fields', () => { - expect(editCustomFields.customFields().length).to.equal(6); + expect(editCustomFields.customFields().length).to.equal(7); }); describe('when Single Select field has a default option', () => { diff --git a/lib/CustomFields/pages/EditCustomFieldsSettings/tests/EditCustomFieldsSettings-test.js b/lib/CustomFields/pages/EditCustomFieldsSettings/tests/EditCustomFieldsSettings-test.js index be2058cd6..9cedbafb0 100644 --- a/lib/CustomFields/pages/EditCustomFieldsSettings/tests/EditCustomFieldsSettings-test.js +++ b/lib/CustomFields/pages/EditCustomFieldsSettings/tests/EditCustomFieldsSettings-test.js @@ -225,9 +225,9 @@ describe('EditCustomFieldsSettings', () => { describe('when creating a custom field with options', () => { beforeEach(async () => { await editCustomFields.addFieldButton.selectCustomFieldType(2); - await editCustomFields.customFields(6).fillName('Test field'); - await editCustomFields.customFields(6).options(0).fillOptionName('beta'); - await editCustomFields.customFields(6).options(1).fillOptionName('alpha'); + await editCustomFields.customFields(7).fillName('Test field'); + await editCustomFields.customFields(7).options(0).fillOptionName('beta'); + await editCustomFields.customFields(7).options(1).fillOptionName('alpha'); await editCustomFields.save(); }); @@ -237,7 +237,7 @@ describe('EditCustomFieldsSettings', () => { const { name, selectField, - } = body.customFields[6]; + } = body.customFields[7]; expect({ name, selectField }).to.deep.equal({ name: 'Test field', diff --git a/lib/CustomFields/pages/ViewCustomFieldsRecord/tests/ViewCustomFieldsRecord-test.js b/lib/CustomFields/pages/ViewCustomFieldsRecord/tests/ViewCustomFieldsRecord-test.js index 274a4e85e..665a4d7fb 100644 --- a/lib/CustomFields/pages/ViewCustomFieldsRecord/tests/ViewCustomFieldsRecord-test.js +++ b/lib/CustomFields/pages/ViewCustomFieldsRecord/tests/ViewCustomFieldsRecord-test.js @@ -64,7 +64,7 @@ describe('ViewCustomFieldsRecord', () => { }); it('should display current number of fields', () => { - expect(viewCustomFields.fields().length).to.equal(6); + expect(viewCustomFields.fields().length).to.equal(7); }); it('should display value for fields with a value', () => { diff --git a/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/ViewCustomFieldsSettings-test.js b/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/ViewCustomFieldsSettings-test.js index 81db0aa91..84b54dbf8 100644 --- a/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/ViewCustomFieldsSettings-test.js +++ b/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/ViewCustomFieldsSettings-test.js @@ -141,4 +141,14 @@ describe('ViewCustomFieldsSettings', () => { expect(disabledStates).to.deep.equal([true, true]); }); }); + + describe('when custom field is checkbox', () => { + it('should display checkbox name', () => { + expect(viewCustomFields.customFields(6).fields(0).value).to.equal('Checkbox'); + }); + + it('should not show help text section', () => { + expect(viewCustomFields.customFields(6).fields(1).value).to.equal('checkbox help text'); + }); + }); }); diff --git a/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/interactor.js b/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/interactor.js index 86cd997b2..586362d05 100644 --- a/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/interactor.js +++ b/lib/CustomFields/pages/ViewCustomFieldsSettings/tests/interactor.js @@ -10,7 +10,7 @@ import { import MultiColumnListInteractor from '@folio/stripes-components/lib/MultiColumnList/tests/interactor'; export default interactor(class ViewCustomFieldsSettings { - customFields = collection('[data-test-accordion-section', { + customFields = collection('[data-test-accordion-section]', { openAccordion: triggerable('[class^="defaultCollapseButton"]'), fields: collection('[class^="col-"]', { label: text('[class^="kvLabel--"]'), diff --git a/tests/network/config.js b/tests/network/config.js index e7f98b539..cafec5473 100644 --- a/tests/network/config.js +++ b/tests/network/config.js @@ -226,7 +226,7 @@ export default function config() { } } }, { - 'id': '6', + 'id':'6', 'name': 'Date', 'refId': 'date1', 'type': 'DATE_PICKER', @@ -235,6 +235,20 @@ export default function config() { 'required': false, 'order': 6, 'helpText': 'Enter a date here', + }, { + 'id': '7', + 'name': 'Checkbox', + 'refId': 'cb_1', + 'type': 'SINGLE_CHECKBOX', + 'entityType': 'user', + 'visible': true, + 'required': false, + 'isRepeatable': false, + 'order': 7, + 'helpText': 'checkbox help text', + 'checkboxField': { + 'default': false + }, }], });