-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5884302
commit d46a134
Showing
5 changed files
with
194 additions
and
12 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Settings/BankingAccountTypeSettings/BankingAccountTypeSettings.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { render } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import { ControlledVocab } from '@folio/stripes/smart-components'; | ||
|
||
import BankingAccountTypeSettings from './BankingAccountTypeSettings'; | ||
|
||
jest.mock('@folio/stripes-smart-components/lib/ControlledVocab', () => jest.fn(({ | ||
rowFilter, | ||
label, | ||
rowFilterFunction, | ||
preCreateHook, | ||
listSuppressor, | ||
}) => ( | ||
<> | ||
{label} | ||
<div onChange={rowFilterFunction}>{rowFilter}</div> | ||
<button | ||
data-testid="button-new" | ||
type="button" | ||
onClick={() => { | ||
preCreateHook(); | ||
listSuppressor(); | ||
}} | ||
> | ||
New | ||
</button> | ||
</> | ||
))); | ||
|
||
const stripesMock = { | ||
connect: component => component, | ||
hasPerm: jest.fn(() => true), | ||
}; | ||
|
||
const renderBankingAccountTypeSettings = () => render( | ||
<BankingAccountTypeSettings | ||
stripes={stripesMock} | ||
/>, | ||
); | ||
|
||
describe('BankingAccountTypeSettings', () => { | ||
it('should check action suppression', () => { | ||
renderBankingAccountTypeSettings(); | ||
|
||
const { actionSuppressor } = ControlledVocab.mock.calls[0][0]; | ||
|
||
expect(stripesMock.hasPerm).toHaveBeenCalled(); | ||
expect(actionSuppressor.edit()).toBeFalsy(); | ||
expect(actionSuppressor.delete()).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Settings/BankingInformationSettings/BankingInformationSettings.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { render, screen, act } from '@folio/jest-config-stripes/testing-library/react'; | ||
import user from '@folio/jest-config-stripes/testing-library/user-event'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import BankingInformationSettings from './BankingInformationSettings'; | ||
|
||
jest.mock('react-query', () => ({ | ||
...jest.requireActual('react-query'), | ||
useQueryClient: jest.fn(() => ({ | ||
invalidateQueries: jest.fn(), | ||
})), | ||
})); | ||
|
||
jest.mock('../hooks/useBankingInformation', () => ({ | ||
useBankingInformation: jest.fn(() => ({ isLoading: false, enabled: false })), | ||
})); | ||
|
||
const renderBankingInformationSettings = () => render( | ||
<BankingInformationSettings />, | ||
); | ||
|
||
describe('BankingInformationSettings component', () => { | ||
it('should display pane headings', () => { | ||
renderBankingInformationSettings(); | ||
|
||
const paneTitle = screen.getAllByText('ui-organizations.settings.bankingInformation'); | ||
|
||
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 save banking options', async () => { | ||
const mockPutMethod = jest.fn(() => ({ | ||
json: () => Promise.resolve('ok'), | ||
})); | ||
|
||
useOkapiKy | ||
.mockClear() | ||
.mockReturnValue({ | ||
put: mockPutMethod, | ||
}); | ||
|
||
renderBankingInformationSettings(); | ||
|
||
const enabledButton = screen.getByText('ui-organizations.settings.bankingInformation.enabled'); | ||
const saveButton = screen.getByText('ui-organizations.settings.accountTypes.save.button'); | ||
|
||
await act(async () => { | ||
await user.click(enabledButton); | ||
await user.click(saveButton); | ||
}); | ||
|
||
expect(mockPutMethod).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
|
||
import { | ||
renderHook, | ||
waitFor, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { useBankingInformation } from './useBankingInformation'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const MOCK_BANKING_INFORMATION = { | ||
'id': 'cb007def-4b68-496c-ad78-ea8e039e819d', | ||
'key': 'BANKING_INFORMATION_ENABLED', | ||
'value': 'true', | ||
}; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useBankingInformation', () => { | ||
beforeEach(() => { | ||
useOkapiKy | ||
.mockClear() | ||
.mockReturnValue({ | ||
get: () => ({ | ||
json: () => Promise.resolve({ settings: [MOCK_BANKING_INFORMATION] }), | ||
}), | ||
}); | ||
}); | ||
|
||
it('should fetch all organization types', async () => { | ||
const { result } = renderHook(() => useBankingInformation(), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current).toEqual({ | ||
enabled: true, | ||
isLoading: false, | ||
id: MOCK_BANKING_INFORMATION.id, | ||
key: MOCK_BANKING_INFORMATION.key, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters