Skip to content

Commit

Permalink
UIORGS-389 Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Nov 16, 2023
1 parent 4cccf41 commit 84421e3
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';

import { BankingInformationCard } from './BankingInformationCard';

const bankingInformation = {
isPrimary: true,
bankName: 'Bank name',
bankAccountNumber: 'Acc No',
transitNumber: 't-123',
categoryId: 'category-id',
accountTypeId: 'acc-type-id',
notes: 'Notes',
};

const defaultProps = {
bankingAccountTypesMap: {
[bankingInformation.accountTypeId]: { name: 'Acc type' },
},
bankingInformation,
categoriesMap: {
[bankingInformation.categoryId]: { value: 'Category' },
},
};

const renderBankingInformationCard = (props = {}) => render(
<BankingInformationCard
{...defaultProps}
{...props}
/>,
);

describe('BankingInformationCard', () => {
it('should render banking information item values', () => {
renderBankingInformationCard();

expect(screen.getByText('ui-organizations.primaryItem')).toBeInTheDocument();
expect(screen.getByText(defaultProps.categoriesMap[bankingInformation.categoryId].value)).toBeInTheDocument();
expect(
screen.getByText(defaultProps.bankingAccountTypesMap[bankingInformation.accountTypeId].name),
).toBeInTheDocument();
expect(screen.getByText(bankingInformation.bankAccountNumber)).toBeInTheDocument();
expect(screen.getByText(bankingInformation.bankName)).toBeInTheDocument();
expect(screen.getByText(bankingInformation.notes)).toBeInTheDocument();
expect(screen.getByText(bankingInformation.transitNumber)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';

import { organization } from 'fixtures';
import {
useBankingAccountTypes,
useCategories,
useOrganizationBankingInformation,
} from '../../../common/hooks';
import { OrganizationBankingInfo } from './OrganizationBankingInfo';

jest.mock('../../../common/hooks', () => ({
...jest.requireActual('../../../common/hooks'),
useBankingAccountTypes: jest.fn(),
useCategories: jest.fn(),
useOrganizationBankingInformation: jest.fn(),
}));

const defaultProps = {
organization,
};

const bankingAccountTypes = [
{ id: 'bank-acc-type-id-1', name: 'Acc type 1' },
{ id: 'bank-acc-type-id-2', name: 'Acc type 2' },
];

const categories = [
{ id: 'category-id-1', value: 'Category 1' },
{ id: 'category-id-2', value: 'Category 2' },
];

const bankingInformation = [
{
id: 'bank-info-id-1',
isPrimary: true,
bankName: 'Bank name 1',
bankAccountNumber: 'Bank acc No 1',
transitNumber: 't-1',
accountTypeId: bankingAccountTypes[0].id,
categoryId: categories[0].id,
notes: 'Notes',
},
{
id: 'bank-info-id-2',
bankName: 'Bank name 2',
accountTypeId: bankingAccountTypes[1].id,
categoryId: categories[1].id,
},
{
id: 'bank-info-id-3',
bankName: 'Bank name 3',
accountTypeId: 'deleted-acc-type-id',
categoryId: 'deleted-category-id',
},
{
id: 'bank-info-id-4',
bankName: 'Bank name 4',
},
];

const renderOrganizationBankingInfo = (props = {}) => render(
<OrganizationBankingInfo
{...defaultProps}
{...props}
/>,
);

describe('OrganizationBankingInfo', () => {
beforeEach(() => {
useBankingAccountTypes
.mockClear()
.mockReturnValue({ bankingAccountTypes, isFetching: false });
useCategories
.mockClear()
.mockReturnValue({ categories, isFetching: false });
useOrganizationBankingInformation
.mockClear()
.mockReturnValue({ bankingInformation, isFetching: false });
});

it('should render card for each of banking information items', () => {
renderOrganizationBankingInfo();

expect(screen.getAllByText(/^Bank name.*/)).toHaveLength(bankingInformation.length);
});
});
11 changes: 11 additions & 0 deletions src/Organizations/OrganizationDetails/OrganizationDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock('@folio/stripes-acq-components', () => ({
}));
jest.mock('@folio/stripes-smart-components/lib/Notes/NotesSmartAccordion', () => () => 'NotesSmartAccordion');
jest.mock('./OrganizationAccounts', () => ({ OrganizationAccounts: () => 'OrganizationAccounts' }));
jest.mock('./OrganizationBankingInfo', () => ({ OrganizationBankingInfo: () => 'OrganizationBankingInfo' }));
jest.mock('./IntegrationDetails', () => ({ IntegrationDetails: () => 'IntegrationDetails' }));
jest.mock('./OrganizationAgreements', () => ({ OrganizationAgreements: () => 'OrganizationAgreements' }));
jest.mock('./OrganizationVendorInfo', () => ({ OrganizationVendorInfo: () => 'OrganizationVendorInfo' }));
Expand Down Expand Up @@ -140,6 +141,16 @@ describe('OrganizationDetails', () => {
expect(screen.getByText('ui-organizations.view.duplicateAccounts')).toBeDefined();
});

it('should display banking information accordion when org is vendor and related settings are enabled', () => {
renderOrganizationDetails({
...defaultProps,
isBankingInformationEnabled: true,
organization: { name: 'Amazon', isVendor: true },
});

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

describe('Actions', () => {
it('should call onEdit when edit action is pressed', async () => {
const onEdit = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';

import { organizationTypes } from 'fixtures';

import { match, location, history } from '../../../test/jest/routerMocks';
import { useTypes } from '../../common/hooks';
import {
useBankingInformationSettings,
useTypes,
} from '../../common/hooks';
import OrganizationDetails from './OrganizationDetails';
import { OrganizationDetailsContainer } from './OrganizationDetailsContainer';

Expand All @@ -14,6 +15,7 @@ jest.mock('@folio/stripes-acq-components', () => ({
}));
jest.mock('../../common/hooks', () => ({
...jest.requireActual('../../common/hooks'),
useBankingInformationSettings: jest.fn(),
useTypes: jest.fn(),
}));
jest.mock('./OrganizationDetails', () => jest.fn(() => 'OrganizationDetails'));
Expand Down Expand Up @@ -49,6 +51,9 @@ const renderOrganizationDetailsContainer = () => render(
describe('OrganizationDetailsContainer', () => {
beforeEach(() => {
mutatorMock.organizationDetailsOrg.GET.mockClear().mockReturnValue(Promise.resolve(organization));
useBankingInformationSettings
.mockClear()
.mockReturnValue({ enabled: true, isLoading: false });
useTypes
.mockClear()
.mockReturnValue({ orgTypes: { organizationTypes, totalRecords: organizationTypes.length } });
Expand Down

0 comments on commit 84421e3

Please sign in to comment.