From 8efd32186b3e15f086a6a3b5a542945e18d003be Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Fri, 20 Oct 2023 19:26:23 +0500 Subject: [PATCH] tests: add test cases --- .../BankingInformationSettings.js | 2 +- .../BankingInformationSettings.test.js | 7 ++- src/Settings/SettingsPage.js | 2 +- src/Settings/SettingsPage.test.js | 60 +++++++++++++++++++ src/Settings/hooks/index.js | 1 + 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/Settings/SettingsPage.test.js create mode 100644 src/Settings/hooks/index.js diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettings.js b/src/Settings/BankingInformationSettings/BankingInformationSettings.js index 0f42d106..2e94f3c4 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettings.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettings.js @@ -18,7 +18,7 @@ import { useNamespace, } from '@folio/stripes/core'; -import { useBankingInformation } from '../hooks/useBankingInformation'; +import { useBankingInformation } from '../hooks'; import { SETTINGS_API } from '../constants'; const BankingInformationSettings = () => { diff --git a/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js b/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js index 2bae5f6f..32c84f5a 100644 --- a/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js +++ b/src/Settings/BankingInformationSettings/BankingInformationSettings.test.js @@ -11,8 +11,11 @@ jest.mock('react-query', () => ({ })), })); -jest.mock('../hooks/useBankingInformation', () => ({ - useBankingInformation: jest.fn(() => ({ isLoading: false, enabled: false })), +jest.mock('../hooks', () => ({ + useBankingInformation: jest.fn(() => ({ + isLoading: false, + enabled: false, + })), })); const renderBankingInformationSettings = () => render( diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index 3ec0cfbb..e422f927 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl'; import { Settings } from '@folio/stripes/smart-components'; import { Loading } from '@folio/stripes/components'; -import { useBankingInformation } from './hooks/useBankingInformation'; +import { useBankingInformation } from './hooks'; import { CategorySettings } from './CategorySettings'; import { TypeSettings } from './TypeSettings'; import { BankingInformationSettings } from './BankingInformationSettings'; diff --git a/src/Settings/SettingsPage.test.js b/src/Settings/SettingsPage.test.js new file mode 100644 index 00000000..c42a9fc1 --- /dev/null +++ b/src/Settings/SettingsPage.test.js @@ -0,0 +1,60 @@ +import React from 'react'; +import { MemoryRouter } from 'react-router-dom'; + +import { screen, render } from '@folio/jest-config-stripes/testing-library/react'; + +import SettingsPage from './SettingsPage'; +import { useBankingInformation } from './hooks'; + +jest.mock('@folio/stripes/core'); +jest.mock('@folio/stripes/smart-components'); + +jest.mock('./hooks', () => ({ + useBankingInformation: jest.fn(() => ({ + isLoading: false, + enabled: false, + })), +})); + +const stripesMock = { + connect: component => component, + hasPerm: jest.fn(() => true), +}; + +const defaultProps = { + stripes: stripesMock, + match: { + path: 'url', + }, + location: { + search: '?name=test', + pathname: '', + }, +}; + +const renderSettingsPage = (props) => render( + + + , +); + +describe('SettingsPage', () => { + it('should return categories, types and banking information links', async () => { + renderSettingsPage(); + + expect(screen.getByText('ui-organizations.settings.categories')).toBeInTheDocument(); + expect(screen.getByText('ui-organizations.settings.types')).toBeInTheDocument(); + expect(screen.getByText('ui-organizations.settings.bankingInformation')).toBeInTheDocument(); + }); + + it('should return banking account types link', async () => { + useBankingInformation.mockReturnValue({ + isLoading: false, + enabled: true, + }); + + renderSettingsPage(); + + expect(screen.getByText('ui-organizations.settings.bankingAccountTypes')).toBeInTheDocument(); + }); +}); diff --git a/src/Settings/hooks/index.js b/src/Settings/hooks/index.js new file mode 100644 index 00000000..2144f705 --- /dev/null +++ b/src/Settings/hooks/index.js @@ -0,0 +1 @@ +export { useBankingInformation } from './useBankingInformation';