Skip to content

Commit

Permalink
tests: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Oct 20, 2023
1 parent 7b3e655 commit 8efd321
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
60 changes: 60 additions & 0 deletions src/Settings/SettingsPage.test.js
Original file line number Diff line number Diff line change
@@ -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(
<MemoryRouter>
<SettingsPage {...defaultProps} {...props} />
</MemoryRouter>,
);

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();
});
});
1 change: 1 addition & 0 deletions src/Settings/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useBankingInformation } from './useBankingInformation';

0 comments on commit 8efd321

Please sign in to comment.