diff --git a/src/edit/common/LocationSelectionWithCheck.test.js b/src/edit/common/LocationSelectionWithCheck.test.js new file mode 100644 index 000000000..4dffa7986 --- /dev/null +++ b/src/edit/common/LocationSelectionWithCheck.test.js @@ -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( + + + , + 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); + }); +}); diff --git a/test/jest/__mock__/stripesSmartComponents.mock.js b/test/jest/__mock__/stripesSmartComponents.mock.js index bd2f50bfa..c6a5b0811 100644 --- a/test/jest/__mock__/stripesSmartComponents.mock.js +++ b/test/jest/__mock__/stripesSmartComponents.mock.js @@ -2,8 +2,6 @@ import React from 'react'; jest.mock('@folio/stripes/smart-components', () => ({ ...jest.requireActual('@folio/stripes/smart-components'), - LocationLookup: () =>
LocationLookup
, - ViewMetaData: () =>
ViewMetaData
, ControlledVocab: () =>
ControlledVocab
, ConfigManager: (props) => { const { getInitialValues, onBeforeSave, children } = props; @@ -16,6 +14,10 @@ jest.mock('@folio/stripes/smart-components', () => ({ ; return component; }, + LocationLookup: () =>
LocationLookup
, + LocationSelection: jest.fn(({ onSelect }) => ( + + )), useRemoteStorageMappings: () => { return ({ 'holdings-id-1': { @@ -29,6 +31,6 @@ jest.mock('@folio/stripes/smart-components', () => ({ 'description': 'Storage B description' } }); - } + }, + ViewMetaData: () =>
ViewMetaData
, }), { virtual: true }); -