Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/edit/common/LocationSelectionWithCheck.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import '../../../test/jest/__mock__';
import React from 'react';
import userEvent from '@testing-library/user-event';
import { QueryClient, QueryClientProvider } from 'react-query';
import { renderWithIntl, translationsProperties } from '../../../test/jest/helpers';
import { LocationSelectionWithCheck } from './LocationSelectionWithCheck';

const queryClient = new QueryClient();
const input = {
name: 'location',
value: '123',
onChange: jest.fn(),
};
const meta = {
initial: '2'
};

const defaultProps = {
input,
meta
};

const renderLocationSelectionWithCheck = () => renderWithIntl(
<QueryClientProvider client={queryClient}>
<LocationSelectionWithCheck {...defaultProps} />
</QueryClientProvider>,
translationsProperties
);

describe('LocationSelectionWithCheck', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('component should render correctly', () => {
const { getByText } = renderLocationSelectionWithCheck();
expect(getByText('LocationLookup')).toBeInTheDocument();
expect(getByText('ConfirmationModal')).toBeInTheDocument();
});
it('warning message should render on clicking select button', () => {
const { container, getByRole, getByText } = renderLocationSelectionWithCheck();
userEvent.click(getByRole('button', { name: 'Select' }));
expect(getByRole('alert')).not.toBeEmptyDOMElement();
expect(getByText('Inactive location')).toBeInTheDocument();
expect(container.getElementsByClassName('inner type-warning').length).toBe(1);
});
it('Warning message should disapper after clicking confin button', () => {
const { container, getByRole } = renderLocationSelectionWithCheck();
userEvent.click(getByRole('button', { name: 'Select' }));
userEvent.click(getByRole('button', { name: 'confirm' }));
expect(container.getElementsByClassName('inner type-warning').length).toBe(0);
});
it('Warning message should disapper after clicking cancel button', () => {
const { container, getByRole } = renderLocationSelectionWithCheck();
userEvent.click(getByRole('button', { name: 'Select' }));
userEvent.click(getByRole('button', { name: 'cancel' }));
expect(container.getElementsByClassName('inner type-warning').length).toBe(0);
});
});
10 changes: 6 additions & 4 deletions test/jest/__mock__/stripesSmartComponents.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react';

jest.mock('@folio/stripes/smart-components', () => ({
...jest.requireActual('@folio/stripes/smart-components'),
LocationLookup: () => <div>LocationLookup</div>,
ViewMetaData: () => <div>ViewMetaData</div>,
ControlledVocab: () => <div>ControlledVocab</div>,
ConfigManager: (props) => {
const { getInitialValues, onBeforeSave, children } = props;
Expand All @@ -16,6 +14,10 @@ jest.mock('@folio/stripes/smart-components', () => ({
</div>;
return component;
},
LocationLookup: () => <div>LocationLookup</div>,
LocationSelection: jest.fn(({ onSelect }) => (
<button data-testid="LocationSelectionSelectBtn" type="button" onClick={onSelect}>Select</button>
)),
useRemoteStorageMappings: () => {
return ({
'holdings-id-1': {
Expand All @@ -29,6 +31,6 @@ jest.mock('@folio/stripes/smart-components', () => ({
'description': 'Storage B description'
}
});
}
},
ViewMetaData: () => <div>ViewMetaData</div>,
}), { virtual: true });