diff --git a/CHANGELOG.md b/CHANGELOG.md index 4806372f..17916e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,14 +27,16 @@ * Added requestDate token. Refs UIREQ-962. * Update `request-storage` okapi interface to `6.0` version. Refs UIREQ-963. * UI tests replacement with RTL/Jest for src/PatronBlockModal.js. Refs UIREQ-878. -* Create Jest/RTL test for RequestsFiltersConfig.js. Refs: UIREQ-938 +* Create Jest/RTL test for RequestsFiltersConfig.js. Refs UIREQ-938. * Create Jest/RTL test for SortableList.js. Refs UIREQ-941. -* create Jest/RTL test for draggableRowFormatter.js, Refs UIREQ-942 +* Create Jest/RTL test for draggableRowFormatter.js. Refs UIREQ-942. * UI tests replacement with RTL/Jest for src/UserDetail.js. Refs UIREQ-881. * TLR: "Create title level request" checkbox not preselected on "New request" page. Refs UIREQ-955. * Do not publish test artifacts to NPM. Refs STRIPES-865. -* Create Jest/RTL test for NoteViewRoute.js Refs: UIREQ-945. +* Create Jest/RTL test for NoteViewRoute.js. Refs UIREQ-945. * Cover ItemInformation by jest/RTL tests. Refs UIREQ-949. +* Cover InstanceInformation by jest/RTL tests. Refs UIREQ-950. +* Fix inconsistency in RTL/Jest tests. Refs UIREQ-979. ## [8.0.2](https://github.com/folio-org/ui-requests/tree/v8.0.2) (2023-03-29) [Full Changelog](https://github.com/folio-org/ui-requests/compare/v8.0.1...v8.0.2) diff --git a/src/components/InstanceInformation/InstanceInformation.js b/src/components/InstanceInformation/InstanceInformation.js index 14dde401..b08acaca 100644 --- a/src/components/InstanceInformation/InstanceInformation.js +++ b/src/components/InstanceInformation/InstanceInformation.js @@ -26,7 +26,7 @@ import { import css from '../../requests.css'; -const INSTANCE_SEGMENT_FOR_PLUGIN = 'instances'; +export const INSTANCE_SEGMENT_FOR_PLUGIN = 'instances'; class InstanceInformation extends Component { static propTypes = { @@ -183,6 +183,7 @@ class InstanceInformation extends Component { return ( ({ + memoizeValidation: (fn) => () => fn, + isFormEditing: jest.fn(() => false), +})); +jest.mock('..', () => ({ + TitleInformation: jest.fn(() =>
TitleInformation
), +})); + +const basicProps = { + triggerValidation: jest.fn(), + findInstance: jest.fn(() => null), + onSetSelectedInstance: jest.fn(), + form: { + change: jest.fn(), + }, + values: { + instance: { + hrid: 'hrid', + }, + keyOfInstanceIdField: 1, + }, + request: { + id: 'requestId', + }, + selectedInstance: { + title: 'instance title', + contributors: {}, + publication: {}, + editions: {}, + identifiers: {}, + }, + instanceRequestCount: 1, + instanceId: 'instanceId', + isLoading: false, + submitting: false, +}; +const labelIds = { + scanOrEnterBarcode: 'ui-requests.instance.scanOrEnterBarcode', + instanceHrid: 'ui-requests.instance.value', + enterButton: 'ui-requests.enter', + selectInstanceRequired: 'ui-requests.errors.selectInstanceRequired', + instanceUuidOrHridDoesNotExist: 'ui-requests.errors.instanceUuidOrHridDoesNotExist', + titleLookupPlugin: 'ui-requests.titleLookupPlugin', +}; +const testIds = { + instanceHridField: 'instanceHridField', + errorMessage: 'errorMessage', +}; +const renderInstanceInfoWithHrid = (onBlur) => { + Field.mockImplementation(jest.fn(({ + children, + 'data-testid': testId, + validate, + }) => { + return children({ + meta: {}, + input: { + validate, + 'data-testid': testId, + value: 'hrid', + onBlur, + }, + }); + })); + + render( + + ); +}; + +describe('InstanceInformation', () => { + afterEach(() => { + basicProps.onSetSelectedInstance.mockClear(); + Field.mockClear(); + cleanup(); + }); + + describe('when "isFormEditing" returns false', () => { + beforeEach(() => { + render( + + ); + }); + + it('should render "scanOrEnterBarcode" placeholder', () => { + const scanOrEnterBarcodePlaceholder = screen.getByPlaceholderText(labelIds.scanOrEnterBarcode); + + expect(scanOrEnterBarcodePlaceholder).toBeVisible(); + }); + + it('should render instance hrid "Field" with correct props', () => { + const expectedProps = { + name: REQUEST_FORM_FIELD_NAMES.INSTANCE_HRID, + validate: expect.any(Function), + validateFields: [], + }; + + expect(Field).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); + }); + + it('should render instance hrid label', () => { + const instanceHridLabel = screen.getByText(labelIds.instanceHrid); + + expect(instanceHridLabel).toBeVisible(); + }); + + it('should trigger "findInstance" when Enter key is pressed', () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.keyDown(instanceHridField, { key: ENTER_EVENT_KEY }); + + expect(basicProps.findInstance).toHaveBeenCalledWith(basicProps.values.instance.hrid); + }); + + it('should not trigger "findInstance" when Control key is pressed', () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.keyDown(instanceHridField, { key: 'Control' }); + + expect(basicProps.findInstance).not.toHaveBeenCalledWith(); + }); + + it('should trigger "form.change" with correct arguments', () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + const event = { + target: { + value: 'instanceHrid', + }, + }; + + fireEvent.change(instanceHridField, event); + + expect(basicProps.form.change).toHaveBeenCalledWith(REQUEST_FORM_FIELD_NAMES.INSTANCE_HRID, event.target.value); + }); + + it('should render "TextField" with correct props', () => { + const expectedProps = { + required: true, + error: null, + placeholder: [labelIds.scanOrEnterBarcode], + onChange: expect.any(Function), + onBlur: expect.any(Function), + onKeyDown: expect.any(Function), + }; + + expect(TextField).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); + }); + + it('should render "TextField" with validation error', () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + const enterButton = screen.getByText(labelIds.enterButton); + const event = { + target: { + value: 'instanceHrid', + }, + }; + const error = 'error'; + + Field.mockImplementationOnce(jest.fn(({ + children, + 'data-testid': testId, + validate, + }) => { + return children({ + meta: { + error, + touched: true, + }, + input: { + validate, + 'data-testid': testId, + }, + }); + })); + + fireEvent.click(enterButton); + fireEvent.change(instanceHridField, event); + + expect(TextField).toHaveBeenCalledWith(expect.objectContaining({ error }), {}); + }); + + it('should render "Pluggable" with correct props', () => { + const expectedProps = { + searchButtonStyle: 'link', + type: 'find-instance', + selectInstance: expect.any(Function), + config: { + availableSegments: [{ + name: INSTANCE_SEGMENT_FOR_PLUGIN, + }], + }, + }; + + expect(Pluggable).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); + }); + + it('should render title lookup plugin label', () => { + const titleLookupPluginLabel = screen.getByText(labelIds.titleLookupPlugin); + + expect(titleLookupPluginLabel).toBeVisible(); + }); + + it('should trigger "findInstance" with correct argument', () => { + const hrid = 'hrid'; + const searchButton = screen.getByText('Search Instance'); + + fireEvent.click(searchButton); + + expect(basicProps.findInstance).toHaveBeenCalledWith(hrid); + }); + }); + + describe('when "isFormEditing" returns true', () => { + beforeEach(() => { + isFormEditing.mockReturnValueOnce(true); + + render( + + ); + }); + + it('should not render "scanOrEnterBarcode" placeholder', () => { + const scanOrEnterBarcodePlaceholder = screen.queryByPlaceholderText(labelIds.scanOrEnterBarcode); + + expect(scanOrEnterBarcodePlaceholder).not.toBeInTheDocument(); + }); + + it('should not render instance hrid field', () => { + const instanceHridField = screen.queryByTestId(testIds.instanceHridField); + + expect(instanceHridField).not.toBeInTheDocument(); + }); + + it('should not render instance hrid label', () => { + const instanceHridLabel = screen.queryByText(labelIds.instanceHrid); + + expect(instanceHridLabel).not.toBeInTheDocument(); + }); + }); + + describe('handleBlur', () => { + const onBlur = jest.fn(); + + afterEach(() => { + onBlur.mockClear(); + }); + + it('should trigger "input.onBlur" if instance hrid is presented', () => { + renderInstanceInfoWithHrid(onBlur); + + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.click(instanceHridField); + fireEvent.blur(instanceHridField); + + expect(onBlur).toHaveBeenCalled(); + }); + + it('should trigger "input.onBlur" if there is no instance hrid', () => { + Field.mockImplementation(jest.fn(({ + children, + 'data-testid': testId, + validate, + }) => { + return children({ + meta: {}, + input: { + validate, + 'data-testid': testId, + value: '', + onBlur, + }, + }); + })); + + render( + + ); + + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.click(instanceHridField); + fireEvent.blur(instanceHridField); + + expect(onBlur).toHaveBeenCalled(); + }); + + it('should not trigger "input.onBlur" if instance hrid was validated previously', () => { + renderInstanceInfoWithHrid(onBlur); + + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + // first input focus + fireEvent.click(instanceHridField); + fireEvent.blur(instanceHridField); + onBlur.mockClear(); + + // second input focus after validation of initial value + fireEvent.click(instanceHridField); + fireEvent.blur(instanceHridField); + + expect(onBlur).not.toHaveBeenCalled(); + }); + }); + + describe('Validation', () => { + afterEach(() => { + basicProps.findInstance.mockClear(); + TextField.mockClear(); + }); + + beforeEach(() => { + TextField.mockImplementation(({ + onChange, + validate, + ...rest + }) => { + const [error, setError] = useState(''); + const handleChange = async (e) => { + setError(await validate(e.target.value)); + onChange(e); + }; + + return ( +
+ + {error} +
+ ); + }); + }); + + describe('when instance hrid is not presented', () => { + const event = { + target: { + value: '', + }, + }; + + it('should not render error message', async () => { + render( + + ); + + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.change(instanceHridField, event); + + await waitFor(() => { + const errorMessage = screen.getByTestId(testIds.errorMessage); + + expect(errorMessage).toBeEmpty(); + }); + }); + + it('should render "selectInstanceRequired" error message', async () => { + const props = { + ...basicProps, + selectedInstance: { + id: 'hrid', + }, + }; + + render( + + ); + + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.change(instanceHridField, event); + + await waitFor(() => { + const errorMessage = screen.queryByText(labelIds.selectInstanceRequired); + + expect(errorMessage).toBeVisible(); + }); + }); + }); + + describe('when instance hrid is presented', () => { + const event = { + target: { + value: 'instanceId', + }, + }; + + beforeEach(() => { + render( + + ); + }); + + it('should not render error message', async () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.change(instanceHridField, event); + + await waitFor(() => { + const errorMessage = screen.getByTestId(testIds.errorMessage); + + expect(errorMessage).toBeEmpty(); + }); + }); + + it('should render "instanceUuidOrHridDoesNotExist" error message', async () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + fireEvent.keyDown(instanceHridField, { key: ENTER_EVENT_KEY }); + fireEvent.change(instanceHridField, event); + + await waitFor(() => { + const errorMessage = screen.queryByText(labelIds.instanceUuidOrHridDoesNotExist); + + expect(errorMessage).toBeVisible(); + }); + }); + + it('should not render error message if instance found', async () => { + const instanceHridField = screen.getByTestId(testIds.instanceHridField); + + basicProps.findInstance.mockReturnValue({}); + fireEvent.keyDown(instanceHridField, { key: ENTER_EVENT_KEY }); + fireEvent.change(instanceHridField, event); + + await waitFor(() => { + const errorMessage = screen.getByTestId(testIds.errorMessage); + + expect(errorMessage).toBeEmpty(); + }); + }); + }); + }); + + describe('"Enter" button', () => { + describe('when instance hrid is presented', () => { + beforeEach(() => { + render( + + ); + }); + + it('should render "Enter" button', () => { + const enterButton = screen.getByText(labelIds.enterButton); + + expect(enterButton).toBeVisible(); + }); + + it('should trigger "onSetSelectedInstance" with correct argument', () => { + const enterButton = screen.getByText(labelIds.enterButton); + + fireEvent.click(enterButton); + + expect(basicProps.onSetSelectedInstance).toHaveBeenCalledWith(null); + }); + + it('should trigger "findInstance" with correct argument', () => { + const enterButton = screen.getByText(labelIds.enterButton); + + fireEvent.click(enterButton); + + expect(basicProps.findInstance).toHaveBeenCalledWith(basicProps.values.instance.hrid); + }); + }); + + describe('when instance hrid is not presented', () => { + const props = { + ...basicProps, + values: { + instance: { + hrid: '', + }, + }, + }; + + beforeEach(() => { + render( + + ); + }); + + it('should not trigger "onSetSelectedInstance"', () => { + const enterButton = screen.getByText(labelIds.enterButton); + + fireEvent.click(enterButton); + + expect(basicProps.onSetSelectedInstance).not.toHaveBeenCalled(); + }); + }); + }); + + describe('Spinner', () => { + afterEach(() => { + Icon.mockClear(); + }); + + describe('when data is loading', () => { + const props = { + ...basicProps, + isLoading: true, + }; + + beforeEach(() => { + render( + + ); + }); + + it('should render loading "Icon" with correct props', () => { + expect(Icon).toHaveBeenCalledWith(BASE_SPINNER_PROPS, {}); + }); + }); + + describe('when data is not loading', () => { + beforeEach(() => { + render( + + ); + }); + + it('should not render loading "Icon"', () => { + expect(Icon).not.toHaveBeenCalled(); + }); + }); + }); + + describe('TitleInformation', () => { + afterEach(() => { + TitleInformation.mockClear(); + }); + + describe('when instance is selected', () => { + it('should render "TitleInformation" with correct props', () => { + render( + + ); + + const expectedProps = { + instanceId: basicProps.instanceId, + titleLevelRequestsCount: basicProps.instanceRequestCount, + title: basicProps.selectedInstance.title, + contributors: basicProps.selectedInstance.contributors, + publications: basicProps.selectedInstance.publication, + editions: basicProps.selectedInstance.editions, + identifiers: basicProps.selectedInstance.identifiers, + }; + + expect(TitleInformation).toHaveBeenCalledWith(expectedProps, {}); + }); + + it('should render "TitleInformation" with "request.instanceId"', () => { + const instanceId = 'instanceId'; + const props = { + ...basicProps, + request: { + ...basicProps.request, + instanceId, + }, + }; + const expectedProps = { + instanceId, + }; + + render( + + ); + + expect(TitleInformation).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); + }); + + it('should render "TitleInformation" with "selectedInstance.id"', () => { + const selectedInstanceId = 'selectedInstanceId'; + const props = { + ...basicProps, + selectedInstance: { + ...basicProps.selectedInstance, + id: selectedInstanceId, + }, + }; + const expectedProps = { + instanceId: selectedInstanceId, + }; + + render( + + ); + + expect(TitleInformation).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {}); + }); + }); + + describe('when instance is not selected', () => { + const props = { + ...basicProps, + selectedInstance: undefined, + }; + + beforeEach(() => { + render( + + ); + }); + + it('should not render "TitleInformation"', () => { + expect(TitleInformation).not.toHaveBeenCalled(); + }); + }); + }); +}); diff --git a/src/components/ReferredRecord/ReferredRecord.test.js b/src/components/ReferredRecord/ReferredRecord.test.js index 05a0642c..26d7e54c 100644 --- a/src/components/ReferredRecord/ReferredRecord.test.js +++ b/src/components/ReferredRecord/ReferredRecord.test.js @@ -1,5 +1,10 @@ import '../../../test/jest/__mock__'; -import { render, screen } from '@testing-library/react'; + +import { + render, + screen, +} from '@testing-library/react'; + import ReferredRecord from './ReferredRecord'; const propsData = { @@ -12,32 +17,30 @@ const propsData = { requesterId: 'testRequesterId', requesterName: 'testRequesterName', }; - const labelIds = { entityTypeRequest: 'ui-requests.notes.entityType.request', assignedFor: 'ui-requests.notes.assigned.for', assignedRequester: 'ui-requests.notes.assigned.requester', - assignedRequestDate: 'ui-requests.notes.assigned.requestDate' + assignedRequestDate: 'ui-requests.notes.assigned.requestDate', }; - const renderReferredRecord = (prop) => render(); describe('ReferredRecord', () => { beforeEach(() => renderReferredRecord(propsData)); - it('entityType.request should render', () => { + it('should render entityType.request', () => { expect(screen.getByText(labelIds.entityTypeRequest)).toBeInTheDocument(); }); - it('assigned.for should render', () => { + it('should render assigned.for', () => { expect(screen.getByText(labelIds.assignedFor)).toBeInTheDocument(); }); - it('assigned.requester should render', () => { + it('should render assigned.requester', () => { expect(screen.getByText(labelIds.assignedRequester)).toBeInTheDocument(); }); - it('assigned.requestDate should render', () => { + it('should render assigned.requestDate', () => { expect(screen.getByText(labelIds.assignedRequestDate)).toBeInTheDocument(); }); }); diff --git a/src/components/RequestsFilters/RequestsFiltersConfig.test.js b/src/components/RequestsFilters/RequestsFiltersConfig.test.js index a0b244ef..c5a94cb4 100644 --- a/src/components/RequestsFilters/RequestsFiltersConfig.test.js +++ b/src/components/RequestsFilters/RequestsFiltersConfig.test.js @@ -1,6 +1,9 @@ -import { requestFilterTypes } from '../../constants'; import filtersConfig from './RequestsFiltersConfig'; +import { + requestFilterTypes, +} from '../../constants'; + describe('RequestsFiltersConfig', () => { it('should have a filter for requestType', () => { const requestTypeFilter = filtersConfig.find(f => f.name === 'requestType'); @@ -10,6 +13,7 @@ describe('RequestsFiltersConfig', () => { values: [], operator: '==', }; + expect(requestTypeFilter).toEqual(expectedResult); }); @@ -20,8 +24,9 @@ describe('RequestsFiltersConfig', () => { cql: 'status', values: [], operator: '==', - label: 'ui-requests.requestMeta.status' + label: 'ui-requests.requestMeta.status', }; + expect(requestStatusFilter).toEqual(expectedResult); }); @@ -33,6 +38,7 @@ describe('RequestsFiltersConfig', () => { values: [], operator: '==', }; + expect(requestLevelsFilter).toEqual(expectedResult); }); @@ -45,16 +51,19 @@ describe('RequestsFiltersConfig', () => { operator: '==', parse: expect.any(Function), }; + expect(tagsFilter).toEqual(expectedResult); }); it('should return the expected query string for a single tag', () => { const tagsFilter = filtersConfig.find(f => f.name === 'tags'); + expect(tagsFilter.parse('tag1')).toEqual('tags.tagList==*"*tag1*"*'); }); it('should return the expected query string for an array of tags', () => { const tagsFilter = filtersConfig.find(f => f.name === 'tags'); + expect(tagsFilter.parse(['tag1', 'tag2'])).toEqual('tags.tagList==(*"*tag1*"* or *"*tag2*"*)'); }); @@ -66,6 +75,7 @@ describe('RequestsFiltersConfig', () => { values: [], operator: '==', }; + expect(pickupServicePointFilter).toEqual(expectedResult); }); }); diff --git a/src/components/SortableList/SortableList.test.js b/src/components/SortableList/SortableList.test.js index 22d13cb0..2f10fee4 100644 --- a/src/components/SortableList/SortableList.test.js +++ b/src/components/SortableList/SortableList.test.js @@ -1,10 +1,24 @@ -import { render, screen } from '@testing-library/react'; +import { + render, + screen, +} from '@testing-library/react'; + import '../../../test/jest/__mock__'; + import SortableList from './SortableList'; jest.mock('react-beautiful-dnd', () => ({ ...jest.requireActual('react-beautiful-dnd'), - Droppable: jest.fn(({ children }) => children({ droppableProps: { droppableid: 'droppableId1', className: 'droppable-area', role: 'list', onDragEnd: jest.fn() }, placeholder:
Placeholder
, innerRef: jest.fn() }, {})) + Droppable: jest.fn(({ children }) => children({ + droppableProps: { + droppableid: 'droppableId1', + className: 'droppable-area', + role: 'list', + onDragEnd: jest.fn(), + }, + placeholder:
Placeholder
, + innerRef: jest.fn(), + }, {})), })); const mockonDragEnd = jest.fn(); @@ -29,15 +43,15 @@ describe('SortableList', () => { renderSortableList(propsData); }); - it('Should render the SortableList component with provided droppableId', () => { + it('should render the SortableList component with provided droppableId', () => { expect(document.querySelector('[droppableid="droppableId1"]')).toBeInTheDocument(); }); - it('Should render the MultiColumnList', () => { + it('should render the MultiColumnList', () => { expect(screen.getByText('MultiColumnList')).toBeInTheDocument(); }); - it('Should render the Provided Placeholder', () => { + it('should render the Provided Placeholder', () => { expect(screen.getByText('Placeholder')).toBeInTheDocument(); }); }); diff --git a/src/components/SortableList/draggableRowFormatter.test.js b/src/components/SortableList/draggableRowFormatter.test.js index 7dbe0a2a..9d659299 100644 --- a/src/components/SortableList/draggableRowFormatter.test.js +++ b/src/components/SortableList/draggableRowFormatter.test.js @@ -1,4 +1,8 @@ -import { render, screen } from '@testing-library/react'; +import { + render, + screen, +} from '@testing-library/react'; + import draggableRowFormatter from './draggableRowFormatter'; jest.mock('react-beautiful-dnd', () => ({ @@ -9,7 +13,7 @@ jest.mock('react-beautiful-dnd', () => ({
{prop.children()}
); - } + }, })); const cells = [ @@ -23,33 +27,35 @@ const propsData = { rowData: 'rowData', rowProps: { isRowDraggable: jest.fn(), - additionalClasses: ['my-additional-class'] + additionalClasses: ['my-additional-class'], }, snapshot: { - isDragging: false + isDragging: false, }, provided: { draggableProps: { style: { - backgroundColor: 'white' - } + backgroundColor: 'white', + }, }, dragHandleProps: '', - innerRef: () => {} + innerRef: () => {}, }, - cells + cells, }; const renderDraggableRowFormatter = (prop) => { const Component = () => draggableRowFormatter(prop); + return ( render() ); }; describe('draggableRowFormatter', () => { - it('draggableRowFormatter component should render correctly', () => { + it('should render correctly draggableRowFormatter component', () => { renderDraggableRowFormatter(propsData); + expect(screen.getByRole('row', { name: /Cell 1 Cell 2 Cell 3/i })).toBeInTheDocument(); }); }); diff --git a/src/routes/NoteEditRoute.test.js b/src/routes/NoteEditRoute.test.js index 9fc1407f..c9a96ea8 100644 --- a/src/routes/NoteEditRoute.test.js +++ b/src/routes/NoteEditRoute.test.js @@ -1,31 +1,40 @@ import '__mock__/'; -import { render, screen } from '@testing-library/react'; -import { historyData } from '../../test/jest/fixtures/historyData'; + +import { + render, + screen, +} from '@testing-library/react'; + +import { + historyData, +} from '../../test/jest/fixtures/historyData'; import NoteEditRoute from './NoteEditRoute'; jest.mock('react-router', () => ({ ...jest.requireActual('react-router'), - Redirect: () =>
Request
+ Redirect: () =>
Request
, })); const locationData = historyData.location; const match = { params: { - noteId: 'editNoteRouteID' + noteId: 'editNoteRouteID', }, path: 'editPath', - url: '{{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules' + url: '{{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules', }; - const renderNoteEditRoute = (locationProps, historyProps) => render( ); + describe('NoteEditRoute', () => { - it('NoteEditPage should render when location.state is not empty', () => { + it('should render NoteEditPage when location.state is not empty', () => { renderNoteEditRoute(locationData, historyData); + expect(screen.getByText('NoteEditPage')).toBeInTheDocument(); }); - it('Request page should render when location.state is empty', () => { + + it('should render request page when location.state is empty', () => { const historyProp = { ...historyData, location : { @@ -36,7 +45,9 @@ describe('NoteEditRoute', () => { }, }; const locationProp = historyProp.location; + renderNoteEditRoute(locationProp, historyProp); + expect(screen.getByText('Request')).toBeInTheDocument(); }); }); diff --git a/src/routes/NoteViewRoute.test.js b/src/routes/NoteViewRoute.test.js index 4d1e45b0..086df576 100644 --- a/src/routes/NoteViewRoute.test.js +++ b/src/routes/NoteViewRoute.test.js @@ -1,25 +1,36 @@ -import '__mock__/'; -import { render, screen } from '@testing-library/react'; +import { + render, + screen, +} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { historyData } from '../../test/jest/fixtures/historyData'; + +import '__mock__/'; + import NoteViewRoute from './NoteViewRoute'; +import { + historyData, +} from '../../test/jest/fixtures/historyData'; jest.mock('react-router', () => ({ ...jest.requireActual('react-router'), - Redirect: () =>
Request
+ Redirect: () =>
Request
, })); const locationData = historyData.location; const match = { params: { - noteId: 'viewNoteRouteID' + noteId: 'viewNoteRouteID', }, path: 'viewPath', - url: '{{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules' + url: '{{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules', }; const renderNoteViewRoute = (locationProps, historyProps) => render( - + ); describe('NoteViewRoute', () => { @@ -27,15 +38,19 @@ describe('NoteViewRoute', () => { beforeEach(() => { renderNoteViewRoute(locationData, historyData); }); + it('NoteViewPage should render when location.state is not empty', () => { expect(screen.getByText('NoteViewPage')).toBeInTheDocument(); }); + it('history.replace function to be called when onEdit clicked', () => { userEvent.click(screen.getByRole('button', { name: 'onEdit' })); + expect(historyData.replace).toBeCalled(); }); }); - it('Request page should render when location.state is empty', () => { + + it('should render request page when location.state is empty', () => { const historyProp = { ...historyData, location : { @@ -47,7 +62,9 @@ describe('NoteViewRoute', () => { }, }; const locationProp = historyProp.location; + renderNoteViewRoute(locationProp, historyProp); + expect(screen.getByText('Request')).toBeInTheDocument(); }); }); diff --git a/src/utils.test.js b/src/utils.test.js index e025cfff..c333aeaa 100644 --- a/src/utils.test.js +++ b/src/utils.test.js @@ -232,7 +232,7 @@ describe('getInstanceQueryString', () => { }); describe('generateUserName', () => { - it('Should return full name', () => { + it('should return full name', () => { const firstName = 'Bob'; const lastName = 'Marley'; const middleName = 'Test'; @@ -241,7 +241,7 @@ describe('generateUserName', () => { .toEqual(`${lastName}, ${firstName} ${middleName}`); }); - it('Should return last name and first name', () => { + it('should return last name and first name', () => { const firstName = 'Bob'; const lastName = 'Marley'; const middleName = undefined; @@ -250,7 +250,7 @@ describe('generateUserName', () => { .toEqual(`${lastName}, ${firstName}`); }); - it('Should return last name only', () => { + it('should return last name only', () => { const firstName = undefined; const lastName = 'Marley'; const middleName = undefined; @@ -259,7 +259,7 @@ describe('generateUserName', () => { .toEqual(lastName); }); - it('Should return last name only if lastName and middleName presented', () => { + it('should return last name only if lastName and middleName presented', () => { const firstName = undefined; const lastName = 'Marley'; const middleName = 'Test'; diff --git a/test/jest/__mock__/stripesCore.mock.js b/test/jest/__mock__/stripesCore.mock.js index 2acd999a..6bd2baea 100644 --- a/test/jest/__mock__/stripesCore.mock.js +++ b/test/jest/__mock__/stripesCore.mock.js @@ -23,7 +23,20 @@ jest.mock('@folio/stripes/core', () => ({ /> ), stripesConnect: Component => props => , - Pluggable: jest.fn(() => null), + Pluggable: jest.fn(({ + searchLabel, + selectInstance, + }) => ( + <> +
{searchLabel}
+ + + )), IfPermission: jest.fn(({ children }) =>
{children}
), TitleManager: jest.fn(jest.fn(() => null)), AppIcon: jest.fn(() => null), diff --git a/translations/ui-requests/de.json b/translations/ui-requests/de.json index d2acc40f..8e64a046 100644 --- a/translations/ui-requests/de.json +++ b/translations/ui-requests/de.json @@ -95,7 +95,7 @@ "showTags": "Tags anzeigen", "tags.tagList": "Tags", "item.copyNumbers": "Exemplarnummer", - "requestNotAllowed": "Bestandsanfrage nicht erlaubt", + "requestNotAllowed": "Bestandsanfrage nicht zulässig", "additionalReasons": "Details der Sperre anzeigen, um zusätzliche Gründe für die Sperre anzuzeigen...", "pickupServicePoint.name": "Abholservicestelle", "item.id": "Exemplar-ID",