Skip to content

Commit

Permalink
jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Dec 9, 2024
1 parent 0e18097 commit 3631bbc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useHistory,
useParams,
useLocation,
} from 'react-router';
} from 'react-router-dom';

import { AppIcon } from '@folio/stripes/core';
import {
Expand Down Expand Up @@ -312,6 +312,7 @@ const OrganizationIntegrationView = ({ orgId }) => {
{isDuplicateConfirmation && (
<ConfirmationModal
id="duplicate-integration-modal"
confirmLabel={<FormattedMessage id="ui-organizations.integration.confirmation.confirm" />}
heading={<FormattedMessage id="ui-organizations.integrationDetails.duplicate.confirmModal.heading" />}
message={(
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React from 'react';
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';
import {
MemoryRouter,
useHistory,
useParams,
} from 'react-router-dom';

import {
render,
screen,
} from '@folio/jest-config-stripes/testing-library/react';
import { queryHelpers } from '@folio/jest-config-stripes/testing-library/dom';
import user from '@folio/jest-config-stripes/testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';
import { useHistory, useParams } from 'react-router';

import {
HasCommand,
Expand All @@ -20,8 +26,10 @@ import {
} from '../../common/hooks';
import OrganizationIntegrationView from './OrganizationIntegrationView';

jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
import { getDuplicateTimestamp } from '../utils';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: jest.fn(),
useParams: jest.fn(),
}));
Expand All @@ -43,6 +51,10 @@ jest.mock('../../common/hooks', () => ({
useIntegrationConfig: jest.fn(),
useIntegrationConfigMutation: jest.fn().mockReturnValue({ mutateIntegrationConfig: jest.fn() }),
}));
jest.mock('../utils', () => ({
...jest.requireActual('../utils'),
getDuplicateTimestamp: jest.fn(),
}));

const queryAllByClass = queryHelpers.queryAllByAttribute.bind(null, 'class');

Expand All @@ -54,19 +66,23 @@ const renderOrganizationIntegrationView = (props = defaultProps) => render(
);

describe('OrganizationIntegrationView', () => {
const mutateIntegrationConfig = jest.fn();

beforeEach(() => {
getDuplicateTimestamp.mockReturnValue('01/01/2025');
global.document.createRange = global.document.originalCreateRange;

useParams.mockClear().mockReturnValue({ id: integrationConfig.id });
useOrganization.mockClear().mockReturnValue({
useParams.mockReturnValue({ id: integrationConfig.id });
useOrganization.mockReturnValue({
organization: { id: defaultProps.orgId, accounts: [] },
isLoading: false,
});
useIntegrationConfigMutation.mockClear().mockReturnValue({ });
useIntegrationConfig.mockClear().mockReturnValue({ integrationConfig });
useIntegrationConfigMutation.mockReturnValue({ mutateIntegrationConfig });
useIntegrationConfig.mockReturnValue({ integrationConfig });
});

afterEach(() => {
jest.clearAllMocks();
global.document.createRange = global.document.mockCreateRange;
});

Expand Down Expand Up @@ -131,6 +147,23 @@ describe('OrganizationIntegrationView', () => {
search: '',
});
});

it('should duplicate integration config', async () => {
const pushMock = jest.fn();

useHistory.mockReturnValue({ push: pushMock });

renderOrganizationIntegrationView();

await user.click(screen.getByTestId('duplicate-integration-action'));
await user.click(screen.getByText('ui-organizations.integration.confirmation.confirm'));

expect(mutateIntegrationConfig).toHaveBeenCalled();
expect(pushMock).toHaveBeenCalledWith({
pathname: `/organizations/view/${orgId}`,
search: '',
});
});
});

describe('Shortcuts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ exports[`OrganizationIntegrationView should render correct view structure 1`] =
</span>
</span>
</button>
<button
class="button dropdownItem"
data-testid="duplicate-integration-action"
type="button"
>
<span
class="inner"
>
<span>
Icon
</span>
</span>
</button>
<button
class="button dropdownItem"
data-testid="remove-integration-action"
Expand Down

0 comments on commit 3631bbc

Please sign in to comment.