From 81f4927b1cc2b1693f02407edf161394b390e3b9 Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Fri, 27 Oct 2023 20:42:15 +0500 Subject: [PATCH] refactor: query key and checkbox component --- .../BankingInformationSettings.test.js | 11 +--- .../BankingInformationSettingsForm.js | 58 +++++++------------ .../BankingInformationSettingsForm.test.js | 9 ++- src/Settings/constants.js | 3 +- 4 files changed, 28 insertions(+), 53 deletions(-) diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js b/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js index 295a9c14..721c0ab3 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js @@ -35,13 +35,6 @@ describe('BankingInformationSettings component', () => { expect(paneTitle).toHaveLength(2); }); - it('should display radio buttons', async () => { - renderBankingInformationSettings(); - - expect(screen.getByText('ui-organizations.settings.bankingInformation.enabled')).toBeInTheDocument(); - expect(screen.getByText('ui-organizations.settings.bankingInformation.disabled')).toBeInTheDocument(); - }); - it('should render Loading component', () => { useBankingInformation.mockReturnValue({ isLoading: true, @@ -71,11 +64,11 @@ describe('BankingInformationSettings component', () => { renderBankingInformationSettings(); - const disabledButton = screen.getByText('ui-organizations.settings.bankingInformation.disabled'); + const checkbox = screen.getByRole('checkbox', { name: 'ui-organizations.settings.bankingInformation' }); const saveButton = screen.getByText('ui-organizations.settings.accountTypes.save.button'); await act(async () => { - await user.click(disabledButton); + await user.click(checkbox); await user.click(saveButton); }); diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.js b/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.js index aaf626cd..2626a442 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.js @@ -5,13 +5,11 @@ import { Field } from 'react-final-form'; import { Button, + Checkbox, Col, - Headline, Pane, PaneFooter, PaneHeader, - RadioButton, - RadioButtonGroup, Row, } from '@folio/stripes/components'; import stripesForm from '@folio/stripes/final-form'; @@ -21,24 +19,21 @@ const BankingInformationSettingsForm = ({ pristine, submitting, }) => { - const paneFooter = useMemo( - () => { - const end = ( - - ); + const paneFooter = useMemo(() => { + const end = ( + + ); - return ; - }, - [handleSubmit, pristine, submitting], - ); + return ; + }, [handleSubmit, pristine, submitting]); const paneTitle = ; @@ -50,27 +45,14 @@ const BankingInformationSettingsForm = ({ footer={paneFooter} > - - - - - } name="value" - component={RadioButtonGroup} - > - } - id="enabled" - value="true" - /> - } - id="disabled" - value="false" - /> - + type="checkbox" + vertical + /> diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.test.js b/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.test.js index 783472c6..43e9d389 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.test.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettingsForm.test.js @@ -19,21 +19,20 @@ const renderBankingInformationSettingsForm = (props = DEFAULT_PROPS) => render( ); describe('BankingInformationSettingsForm component', () => { - it('should display radio buttons', async () => { + it('should render component', async () => { renderBankingInformationSettingsForm(); - expect(screen.getByText('ui-organizations.settings.bankingInformation.enabled')).toBeInTheDocument(); - expect(screen.getByText('ui-organizations.settings.bankingInformation.disabled')).toBeInTheDocument(); + expect(screen.getAllByLabelText('ui-organizations.settings.bankingInformation')).toHaveLength(2); }); it('should save banking options', async () => { renderBankingInformationSettingsForm(); - const disabledButton = screen.getByText('ui-organizations.settings.bankingInformation.disabled'); + const checkbox = screen.getByRole('checkbox', { name: 'ui-organizations.settings.bankingInformation' }); const saveButton = screen.getByText('ui-organizations.settings.accountTypes.save.button'); await act(async () => { - await user.click(disabledButton); + await user.click(checkbox); await user.click(saveButton); }); diff --git a/src/Settings/constants.js b/src/Settings/constants.js index 241cec60..a58f4def 100644 --- a/src/Settings/constants.js +++ b/src/Settings/constants.js @@ -1,7 +1,8 @@ export const SETTINGS_API = 'organizations-storage/settings'; export const BANKING_ACCOUNT_TYPES_API = 'organizations-storage/banking-account-types'; +export const BANKING_INFORMATION_ENABLED_QUERY_KEY = 'key=BANKING_INFORMATION_ENABLED'; export const BANKING_INFORMATION_SEARCH_QUERY = { - query: 'key=BANKING_INFORMATION_ENABLED', + query: BANKING_INFORMATION_ENABLED_QUERY_KEY, limit: 1, };