Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Nov 15, 2023
1 parent 516f91d commit caafd45
Show file tree
Hide file tree
Showing 10 changed files with 1,074 additions and 1,029 deletions.
18 changes: 15 additions & 3 deletions src/Organizations/OrganizationCreate/OrganizationCreate.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';

import { OrganizationForm } from '../OrganizationForm';

import { OrganizationCreate } from './OrganizationCreate';

jest.mock('../OrganizationForm', () => ({
Expand All @@ -17,19 +16,32 @@ const mutatorMock = {
const historyMock = {
push: jest.fn(),
};

const getFieldState = jest.fn();

const queryClient = new QueryClient();

const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);

const renderOrganizationCreate = (props) => render(
<OrganizationCreate
location={{}}
history={historyMock}
mutator={mutatorMock}
{...props}
/>,
{ wrapper },
);

describe('OrganizationCreate', () => {
beforeEach(() => {
OrganizationForm.mockClear();

getFieldState.mockClear();
historyMock.push.mockClear();
mutatorMock.createOrganizationOrg.POST.mockClear();
});
Expand Down Expand Up @@ -61,6 +73,6 @@ describe('OrganizationCreate', () => {

renderOrganizationCreate();

OrganizationForm.mock.calls[0][0].onSubmit({});
OrganizationForm.mock.calls[0][0].onSubmit({}, { getFieldState });
});
});
34 changes: 31 additions & 3 deletions src/Organizations/OrganizationEdit/OrganizationEdit.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';

import { render, screen } from '@folio/jest-config-stripes/testing-library/react';

import { useOrganizationBankingInformation } from '../../common/hooks';
import { OrganizationForm } from '../OrganizationForm';

import { OrganizationEdit } from './OrganizationEdit';

jest.mock('../../common/hooks', () => ({
...jest.requireActual('../../common/hooks'),
useOrganizationBankingInformation: jest.fn(),
}));
jest.mock('../OrganizationForm', () => ({
OrganizationForm: jest.fn().mockReturnValue('OrganizationForm'),
}));
Expand All @@ -13,6 +18,13 @@ const organization = {
name: 'Amazon',
id: 'orgUid',
};

const bankingInformation = [{
id: 'banking-information-id',
bankName: 'bankName',
isPrimary: true,
}];

const mutatorMock = {
editOrganizationOrg: {
GET: jest.fn(),
Expand All @@ -27,6 +39,17 @@ const matchMock = {
id: organization.id,
},
};

const getFieldState = jest.fn();

const queryClient = new QueryClient();

const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);

const renderOrganizationEdit = (props) => render(
<OrganizationEdit
match={matchMock}
Expand All @@ -35,15 +58,20 @@ const renderOrganizationEdit = (props) => render(
mutator={mutatorMock}
{...props}
/>,
{ wrapper },
);

describe('OrganizationEdit', () => {
beforeEach(() => {
OrganizationForm.mockClear();

getFieldState.mockClear();
historyMock.push.mockClear();
mutatorMock.editOrganizationOrg.GET.mockClear().mockReturnValue(Promise.resolve(organization));
mutatorMock.editOrganizationOrg.PUT.mockClear();
useOrganizationBankingInformation
.mockClear()
.mockReturnValue({ bankingInformation, isLoading: false });
});

it('should display organization form', async () => {
Expand Down Expand Up @@ -71,6 +99,6 @@ describe('OrganizationEdit', () => {

await screen.findByText('OrganizationForm');

OrganizationForm.mock.calls[0][0].onSubmit({});
OrganizationForm.mock.calls[0][0].onSubmit({}, { getFieldState });
});
});
Loading

0 comments on commit caafd45

Please sign in to comment.