Skip to content

Commit

Permalink
test: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Oct 27, 2023
1 parent e2ae13b commit bc9d7b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';
import { render, screen, act } from '@folio/jest-config-stripes/testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import user from '@folio/jest-config-stripes/testing-library/user-event';
import { useOkapiKy } from '@folio/stripes/core';

import BankingInformationSettings from './BankingInformationSettings';
import { useBankingInformation } from '../hooks';
Expand Down Expand Up @@ -50,4 +52,33 @@ describe('BankingInformationSettings component', () => {

expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should save banking options', async () => {
useBankingInformation.mockClear().mockReturnValue({
isLoading: false,
enabled: true,
refetch: mockRefetch,
});
const mockPutMethod = jest.fn(() => ({
json: () => Promise.resolve('ok'),
}));

useOkapiKy
.mockClear()
.mockReturnValue({
put: mockPutMethod,
});

renderBankingInformationSettings();

const disabledButton = screen.getByText('ui-organizations.settings.bankingInformation.disabled');
const saveButton = screen.getByText('ui-organizations.settings.accountTypes.save.button');

await act(async () => {
await user.click(disabledButton);
await user.click(saveButton);
});

expect(mockPutMethod).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion src/Settings/hooks/useBankingInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useBankingInformation = () => {
[namespace],
() => ky.get(SETTINGS_API, {
searchParams: BANKING_INFORMATION_SEARCH_QUERY,
}).json().catch(() => null),
}).json(),
);

const bankingInformation = get(data, 'settings[0]', {});
Expand Down

0 comments on commit bc9d7b0

Please sign in to comment.