diff --git a/src/settings/HRIDHandling/HRIDHandlingSettings.test.js b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js new file mode 100644 index 000000000..d7b23acd5 --- /dev/null +++ b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js @@ -0,0 +1,111 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import userEvent from '@testing-library/user-event'; + +import '../../../test/jest/__mock__'; +import { renderWithIntl } from '../../../test/jest/helpers'; + +import HRIDHandlingSettings from './HRIDHandlingSettings'; + +describe('HRIDHandlingSettings component', () => { + const mutator = { + hridSettings: { + PUT: jest.fn(() => Promise.resolve()), + }, + }; + const resources = { + hridSettings: { + records: [ + { + id: '1', + commonRetainLeadingZeroes: true, + itemRetainLeadingZeroes: false, + instanceRetainLeadingZeroes: true, + holdingsRetainLeadingZeroes: false, + authorityRetainLeadingZeroes: true, + instance: { + prefix: 'INST', + startNumber: 1, + }, + }, + ], + }, + }; + + beforeEach(() => { + mutator.hridSettings.PUT.mockClear(); + renderWithIntl( + + + + ); + }); + afterEach(() => { + jest.clearAllMocks(); + }); + + it('renders checkbox for removing leading zeroes', () => { + const checkBox = screen.getByRole('checkbox', { id: 'checkbox-3' }); + userEvent.click(checkBox); + expect(checkBox).toBeChecked(); + const ConfirmationButton = screen.getByRole('button', { name: /confirm/i }); + expect(ConfirmationButton).toBeInTheDocument(); + userEvent.click(ConfirmationButton); + }); + + it('Cancellation Button', () => { + const CancellationButton = screen.getByRole('button', { name: 'cancel' }); + expect(CancellationButton).toBeInTheDocument(); + userEvent.click(CancellationButton); + }); + it('allows the user to input values for "startWith" and "assignPrefix" fields', () => { + const startWithFields = [ + screen.getByLabelText(/ui-inventory.hridHandling.label.startWith */i, { selector: 'input[name="instances.startNumber"]' }), + screen.getByLabelText(/ui-inventory.hridHandling.label.startWith */i, { selector: 'input[name="holdings.startNumber"]' }), + screen.getByLabelText(/ui-inventory.hridHandling.label.startWith */i, { selector: 'input[name="items.startNumber"]' }), + ]; + const assignPrefixFields = [ + screen.getByLabelText(/ui-inventory.hridHandling.label.assignPrefix/i, { selector: 'input[name="instances.prefix"]' }), + screen.getByLabelText(/ui-inventory.hridHandling.label.assignPrefix/i, { selector: 'input[name="holdings.prefix"]' }), + screen.getByLabelText(/ui-inventory.hridHandling.label.assignPrefix/i, { selector: 'input[name="items.prefix"]' }), + ]; + const testValues = ['100', 'prefix-', '200', 'prefix2-', '300', 'prefix3-']; + startWithFields.forEach((field, index) => userEvent.type(field, testValues[index * 2])); + assignPrefixFields.forEach((field, index) => userEvent.type(field, testValues[index * 2 + 1])); + startWithFields.forEach((field, index) => expect(field.value).toBe(testValues[index * 2])); + assignPrefixFields.forEach((field, index) => expect(field.value).toBe(testValues[index * 2 + 1])); + const saveAndCloseButton = screen.getByRole('button', { name: /stripes-components.saveAndClose/i }); + userEvent.click(saveAndCloseButton); + const ConfirmationButton = screen.getByRole('button', { name: /confirm/i }); + userEvent.click(ConfirmationButton); + expect(mutator.hridSettings.PUT).toHaveBeenCalled(); + }); +}); + +describe('HRIDHandlingSettings - commonRetainLeadingZeroes', () => { + const initialSettings = { + commonRetainLeadingZeroes: false, + locations: { + startNumber: '00000000001', + }, + holdings: { + startNumber: '00000000002', + }, + }; + it('rendedr commonRetainLeadingZeroes', () => { + renderWithIntl( + + + + ); + const checkBox = screen.getByRole('checkbox', { id: 'checkbox-3' }); + expect(checkBox).toBeChecked(); + }); +}); diff --git a/test/jest/__mock__/stripesComponents.mock.js b/test/jest/__mock__/stripesComponents.mock.js index 6af025fbf..e038377c2 100644 --- a/test/jest/__mock__/stripesComponents.mock.js +++ b/test/jest/__mock__/stripesComponents.mock.js @@ -2,7 +2,7 @@ import React from 'react'; jest.mock('@folio/stripes/components', () => ({ ...jest.requireActual('@folio/stripes/components'), - ConfirmationModal: jest.fn(({ heading, message, onConfirm, onCancel }) => ( + ConfirmationModal: jest.fn(({ heading, message, onConfirm, onCancel, onRemove }) => (
ConfirmationModal {heading} @@ -10,6 +10,7 @@ jest.mock('@folio/stripes/components', () => ({
+
)), @@ -28,5 +29,4 @@ jest.mock('@folio/stripes/components', () => ({ Loading: () =>
Loading
, LoadingPane: () =>
LoadingPane
, LoadingView: () =>
LoadingView
, - LoadingPane: () =>
LoadingPane
, }), { virtual: true });