From 6c53f467603b7061f485b35bc09d1c1e032d6a65 Mon Sep 17 00:00:00 2001 From: KetineniM Date: Fri, 14 Apr 2023 12:38:52 +0530 Subject: [PATCH 1/2] UIIN-1731 JEST/RTL test cases for HRIDHandlingSettings --- .../HRIDHandling/HRIDHandlingSettings.test.js | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/settings/HRIDHandling/HRIDHandlingSettings.test.js diff --git a/src/settings/HRIDHandling/HRIDHandlingSettings.test.js b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js new file mode 100644 index 000000000..299c27194 --- /dev/null +++ b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js @@ -0,0 +1,112 @@ +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 '../../../test/jest/__mock__/stripesComponents.mock'; +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: /Confirmation/i }); + expect(ConfirmationButton).toBeInTheDocument(); + userEvent.click(ConfirmationButton); + }); + + it('Cancellation Button', () => { + const CancellationButton = screen.getByRole('button', { name: /Cancellation/i }); + 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: /Confirmation/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(); + }); +}); From 696e5fc4cc29d05a914c621df3ff5203d2975589 Mon Sep 17 00:00:00 2001 From: KetineniM Date: Fri, 14 Apr 2023 14:17:35 +0530 Subject: [PATCH 2/2] Included stripesComponents mock file --- src/settings/HRIDHandling/HRIDHandlingSettings.test.js | 7 +++---- test/jest/__mock__/stripesComponents.mock.js | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/settings/HRIDHandling/HRIDHandlingSettings.test.js b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js index 299c27194..d7b23acd5 100644 --- a/src/settings/HRIDHandling/HRIDHandlingSettings.test.js +++ b/src/settings/HRIDHandling/HRIDHandlingSettings.test.js @@ -6,7 +6,6 @@ import userEvent from '@testing-library/user-event'; import '../../../test/jest/__mock__'; import { renderWithIntl } from '../../../test/jest/helpers'; -import '../../../test/jest/__mock__/stripesComponents.mock'; import HRIDHandlingSettings from './HRIDHandlingSettings'; describe('HRIDHandlingSettings component', () => { @@ -53,13 +52,13 @@ describe('HRIDHandlingSettings component', () => { const checkBox = screen.getByRole('checkbox', { id: 'checkbox-3' }); userEvent.click(checkBox); expect(checkBox).toBeChecked(); - const ConfirmationButton = screen.getByRole('button', { name: /Confirmation/i }); + const ConfirmationButton = screen.getByRole('button', { name: /confirm/i }); expect(ConfirmationButton).toBeInTheDocument(); userEvent.click(ConfirmationButton); }); it('Cancellation Button', () => { - const CancellationButton = screen.getByRole('button', { name: /Cancellation/i }); + const CancellationButton = screen.getByRole('button', { name: 'cancel' }); expect(CancellationButton).toBeInTheDocument(); userEvent.click(CancellationButton); }); @@ -81,7 +80,7 @@ describe('HRIDHandlingSettings component', () => { 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: /Confirmation/i }); + const ConfirmationButton = screen.getByRole('button', { name: /confirm/i }); userEvent.click(ConfirmationButton); expect(mutator.hridSettings.PUT).toHaveBeenCalled(); }); 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 });