diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js
index caf4bfe03..f8684a503 100644
--- a/src/components/InstancesList/InstancesList.test.js
+++ b/src/components/InstancesList/InstancesList.test.js
@@ -1,27 +1,31 @@
+/* eslint-disable jsx-a11y/no-redundant-roles */
+/* eslint-disable react/button-has-type */
import React from 'react';
import { Router } from 'react-router-dom';
import { noop } from 'lodash';
-import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
+import userEvent from '@testing-library/user-event';
import { createMemoryHistory } from 'history';
import {
- act,
- cleanup,
- fireEvent,
- screen,
- within,
-} from '@folio/jest-config-stripes/testing-library/react';
-
-import '../../../test/jest/__mock__';
-
-import { StripesContext, ModuleHierarchyProvider } from '@folio/stripes/core';
-
+ screen
+} from '@testing-library/react';
+
+import '../../../test/jest/__mock__/stripesConfig.mock';
+import '../../../test/jest/__mock__/currencyData.mock';
+import '../../../test/jest/__mock__/documentCreateRange.mock';
+import '../../../test/jest/__mock__/InstancePlugin.mock';
+import '../../../test/jest/__mock__/stripesIcon.mock';
+import '../../../test/jest/__mock__/stripesCore.mock';
+import '../../../test/jest/__mock__/matchMedia.mock';
+import '../../../test/jest/__mock__/quickMarc.mock';
+import '../../../test/jest/__mock__/reactBeautifulDnd.mock';
+import { StripesContext } from '@folio/stripes-core/src/StripesContext';
+import { ModuleHierarchyProvider } from '@folio/stripes-core/src/components/ModuleHierarchy';
+import { CalloutContext } from '@folio/stripes-core';
import renderWithIntl from '../../../test/jest/helpers/renderWithIntl';
import translationsProperties from '../../../test/jest/helpers/translationsProperties';
import { instances as instancesFixture } from '../../../test/fixtures/instances';
import { getFilterConfig } from '../../filterConfig';
import InstancesList from './InstancesList';
-import { setItem } from '../../storage';
-import { SORTABLE_SEARCH_RESULT_LIST_COLUMNS } from '../../constants';
const updateMock = jest.fn();
const mockQueryReplace = jest.fn();
@@ -30,23 +34,202 @@ const mockStoreLastSearch = jest.fn();
const mockRecordsReset = jest.fn();
const mockGetLastSearchOffset = jest.fn();
const mockStoreLastSearchOffset = jest.fn();
-const mockGetLastSearch = jest.fn();
-jest.mock('../../storage', () => ({
- ...jest.requireActual('../../storage'),
- setItem: jest.fn(),
+jest.useFakeTimers();
+jest.mock('@folio/stripes-util');
+jest.mock('file-saver');
+jest.mock('../../storage');
+jest.mock('../SearchModeNavigation', () => ({
+ __esModule: true,
+ default: jest.fn().mockImplementation(({ search }) => {
+ return (
+
+ );
+ }),
}));
-
-jest.mock('../../hooks', () => ({
- ...jest.requireActual('../../hooks'),
- useLastSearchTerms: () => ({
- getLastSearch: mockGetLastSearch,
+jest.mock('../FilterNavigation', () => ({
+ __esModule: true,
+ default: jest.fn().mockImplementation(({ onChange }) => {
+ return (
+
+ );
+ }),
+}));
+jest.mock('../../utils', () => ({
+ ...jest.requireActual('../../utils'),
+ isTestEnv: jest.fn().mockReturnValue(false),
+}));
+jest.mock(
+ '@folio/stripes/smart-components',
+ () => ({
+ ...jest.requireActual('@folio/stripes/smart-components'),
+ SearchAndSort: jest.fn().mockImplementation((props) => {
+ return (
+
+
+ {props.actionMenu({ onToggle: jest.fn() })}
+
+
+
+
+
+ {props.resultsFormatter.select({ id: 1, rowData: [] })}
+ {props.resultsFormatter.title({
+ title: 'formatter Title',
+ discoverySuppress: true,
+ isBoundWith: true,
+ staffSuppress: true,
+ id: 1,
+ })}
+ {props.resultsFormatter.relation(1)}
+ {props.resultsFormatter.publishers(1)}
+ {props.resultsFormatter.contributors(1)}
+ {props.resultsFormatter['publication date']({ publication: [] })}
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+ }),
+ useRemoteStorageMappings: () => {
+ return {
+ 'holdings-id-1': {
+ id: 'holdings-id-1',
+ name: 'Storage A',
+ description: 'Storage A description',
+ },
+ 'holdings-id-2': {
+ id: 'holdings-id-2',
+ name: 'Storage B',
+ description: 'Storage B description',
+ },
+ };
+ },
}),
+ { virtual: true }
+);
+
+jest.mock('../SelectedRecordsModal', () => ({
+ __esModule: true,
+ default: jest
+ .fn()
+ .mockImplementation(
+ ({ onSave, onCancel }) => {
+ return (
+ <>
+
+
+
+ >
+ );
+ }
+ ),
+}));
+
+jest.mock('../ImportRecordModal', () => ({
+ __esModule: true,
+ default: jest
+ .fn()
+ .mockImplementation(
+ ({ handleSubmit, handleCancel }) => {
+ return (
+ <>
+
+
+
+ >
+ );
+ }
+ ),
}));
const stripesStub = {
- connect: Component => ,
+ connect: (Component) => ,
hasPerm: () => true,
+
hasInterface: () => true,
logger: { log: noop },
locale: 'en-US',
@@ -78,7 +261,7 @@ const data = {
facets: [],
};
const query = {
- query: '',
+ query: true,
sort: 'title',
};
@@ -95,7 +278,7 @@ const resources = {
hasLoaded: true,
resource: 'facets',
records: [],
- other: { totalRecords: 0 }
+ other: { totalRecords: 0 },
},
resultCount: instancesFixture.length,
resultOffset: 0,
@@ -103,60 +286,64 @@ const resources = {
let history;
-const renderInstancesList = ({
- segment,
- ...rest
-}, rerender) => {
- const {
- indexes,
- indexesES,
- renderer,
- } = getFilterConfig(segment);
+const renderInstancesList = ({ segment, ...rest }, rerender) => {
+ const { indexes, indexesES, renderer } = getFilterConfig(segment);
return renderWithIntl(
-
-
-
+
+
+
+
+
,
translationsProperties,
- rerender,
+ rerender
);
};
describe('InstancesList', () => {
describe('rendering InstancesList with instances segment', () => {
beforeEach(() => {
+ jest.advanceTimersByTime(1000);
history = createMemoryHistory();
renderInstancesList({ segment: 'instances' });
});
@@ -172,7 +359,7 @@ describe('InstancesList', () => {
expect(mockStoreLastSearch).toHaveBeenCalledWith(search, 'instances');
});
- describe('and browse result was selected', () => {
+ describe('browse result was selected', () => {
it('should reset offset', () => {
mockResultOffsetReplace.mockClear();
const params = {
@@ -191,7 +378,7 @@ describe('InstancesList', () => {
});
});
- describe('and browse result was not selected', () => {
+ describe('browse result was not selected', () => {
it('should replace resultOffset', () => {
mockResultOffsetReplace.mockClear();
@@ -206,29 +393,38 @@ describe('InstancesList', () => {
});
describe('when the component is updated', () => {
- describe('and location.search has been changed', () => {
+ describe('location.search has been changed', () => {
it('should write location.search to the session storage', () => {
const search = '?qindex=title&query=book&sort=title';
mockStoreLastSearch.mockClear();
history.push({ search });
expect(mockStoreLastSearch).toHaveBeenCalledWith(search, 'instances');
});
+ it('should write location.search to the session storage', () => {
+ const search = '?qindex=title&query=book&sort=title&reset=true';
+ mockStoreLastSearch.mockClear();
+ history.push({ search });
+ expect(mockStoreLastSearch).toHaveBeenCalledWith(search, 'instances');
+ });
});
- describe('and offset has been changed', () => {
+ describe('offset has been changed', () => {
it('should write offset to storage', () => {
const offset = 100;
mockStoreLastSearchOffset.mockClear();
const { rerender } = renderInstancesList({ segment: 'instances' });
- renderInstancesList({
- segment: 'instances',
- parentResources: {
- ...resources,
- resultOffset: offset,
+ renderInstancesList(
+ {
+ segment: 'instances',
+ parentResources: {
+ ...resources,
+ resultOffset: offset,
+ },
},
- }, rerender);
+ rerender
+ );
expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset, 'instances');
});
@@ -245,165 +441,76 @@ describe('InstancesList', () => {
});
});
- describe('when clicking on the `Browse` tab', () => {
- it('should pass the correct search by clicking on the `Browse` tab', () => {
- cleanup();
- const search = '?qindex=subject&query=book';
-
- jest.spyOn(history, 'push');
-
- renderInstancesList({
- segment: 'instances',
- getLastBrowse: () => search,
- });
-
- fireEvent.click(screen.getByRole('button', { name: 'Browse' }));
-
- expect(history.push).toHaveBeenCalledWith(expect.objectContaining({ search }));
- });
-
- it('should store last opened record id', () => {
- cleanup();
- history = createMemoryHistory({ initialEntries: [{
- pathname: '/inventory/view/test-id',
- }] });
-
- renderInstancesList({
- segment: 'instances',
- });
-
- fireEvent.click(screen.getByRole('button', { name: 'Browse' }));
-
- expect(setItem).toHaveBeenCalledWith('@folio/inventory.instances.lastOpenRecord', 'test-id');
- });
- });
-
- it('should have proper list results size', () => {
- expect(document.querySelectorAll('#pane-results-content .mclRowContainer > [role=row]').length).toEqual(3);
- });
-
- describe('opening action menu', () => {
- beforeEach(() => {
- fireEvent.change(screen.getByRole('combobox'), {
- target: { value: 'all' }
- });
-
- userEvent.click(screen.getByRole('button', { name: 'Actions' }));
- });
-
- it('should disable toggleable columns', () => {
- expect(screen.getByText(/show columns/i)).toBeInTheDocument();
- });
-
- describe('"New MARC Bib Record" button', () => {
- it('should render', () => {
- expect(screen.getByRole('button', { name: 'New MARC Bib Record' })).toBeInTheDocument();
- });
-
- it('should redirect to the correct layer', async () => {
- jest.spyOn(history, 'push');
-
- const button = screen.getByRole('button', { name: 'New MARC Bib Record' });
-
- fireEvent.click(button);
-
- expect(history.push).toHaveBeenCalledWith('/inventory/quick-marc/create-bib?');
- });
- });
-
- describe('hiding contributors column', () => {
- beforeEach(() => {
- userEvent.click(screen.getByTestId('contributors'));
- });
-
- it('should hide contributors column', () => {
- expect(document.querySelector('#clickable-list-column-contributors')).not.toBeInTheDocument();
- });
- });
-
- describe('select sort by', () => {
- it('should render menu option', () => {
- expect(screen.getByTestId('menu-section-sort-by')).toBeInTheDocument();
- });
-
- it('should render select', () => {
- expect(screen.getByTestId('sort-by-selection')).toBeInTheDocument();
- });
-
- it('should render as many options as defined plus Relevance', () => {
- const options = within(screen.getByTestId('sort-by-selection')).getAllByRole('option');
- expect(options).toHaveLength(Object.keys(SORTABLE_SEARCH_RESULT_LIST_COLUMNS).length + 1);
- });
- });
-
- describe('select proper sort options', () => {
- it('should select Title as default selected sort option', () => {
- const search = '?segment=instances&sort=title';
- history.push({ search });
-
- const option = within(screen.getByTestId('menu-section-sort-by')).getByRole('option', { name: 'Title' });
- expect(option.selected).toBeTruthy();
- });
-
- it('should select Contributors option', () => {
- userEvent.click(screen.getByRole('button', { name: 'Actions' }));
- userEvent.selectOptions(screen.getByTestId('sort-by-selection'), 'contributors');
-
- const option = within(screen.getByTestId('menu-section-sort-by')).getByRole('option', { name: 'Contributors' });
- expect(option.selected).toBeTruthy();
- });
-
- it('should select option value "Contributors" after column "Contributors" click', async () => {
- await act(async () => fireEvent.click(document.querySelector('#clickable-list-column-contributors')));
-
- expect((screen.getByRole('option', { name: 'Contributors' })).selected).toBeTruthy();
- });
- });
- });
-
describe('filters pane', () => {
- it('should have selected effective call number option', async () => {
- await act(async () => userEvent.selectOptions(screen.getByLabelText('Search field index'), 'callNumber'));
-
- expect((screen.getByRole('option', { name: 'Effective call number (item), shelving order' })).selected).toBeTruthy();
- });
-
it('should have query in search input', () => {
- userEvent.type(screen.getByRole('searchbox', { name: 'Search' }), 'search query');
- userEvent.click(screen.getAllByRole('button', { name: 'Search' })[1]);
-
- expect(screen.getByRole('searchbox', { name: 'Search' })).toHaveValue('search query');
- });
- });
-
- describe('when using advanced search', () => {
- beforeEach(() => {
- userEvent.click(screen.getByRole('button', { name: 'Advanced search' }));
- fireEvent.change(screen.getAllByRole('textbox', { name: 'Search for' })[0], {
- target: { value: 'test' }
- });
-
- const advancedSearchSubmit = screen.getAllByRole('button', { name: 'Search' })[0];
- userEvent.click(advancedSearchSubmit);
- });
-
- it('should set advanced search query in search input', () => {
- expect(screen.getAllByLabelText('Search')[0].value).toEqual('keyword containsAll test');
+ userEvent.click(screen.getByText('Save Model'));
+ userEvent.click(screen.getByText('Cancel Model'));
+ userEvent.click(screen.getByText('Save Import'));
+ userEvent.click(screen.getByText('Cancel Import'));
+ userEvent.type(
+ screen.getByRole('searchbox', { name: 'Search' }),
+ 'search query'
+ );
+ expect(screen.getByText('Cancel Import')).toBeInTheDocument();
});
});
});
+});
- describe('rendering InstancesList with holdings segment', () => {
- it('should show Save Holdings UUIDs button', () => {
- renderInstancesList({ segment: 'holdings' });
-
- fireEvent.change(screen.getByRole('combobox'), {
- target: { value: 'all' }
- });
-
- userEvent.click(screen.getByRole('button', { name: 'Actions' }));
+describe('rendering InstancesList with holdings segment', () => {
+ beforeEach(() => {
+ jest.advanceTimersByTime(4000);
+ history = createMemoryHistory();
+ renderInstancesList({ segment: 'holdings' });
+ });
- expect(screen.getByRole('button', { name: 'Save holdings UUIDs' })).toBeVisible();
- });
+ it('should show Save Holdings UUIDs button', () => {
+ renderInstancesList({ segment: 'holdings' });
+
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Row' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Filter' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Reset' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Submit' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Create' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Copy' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Reset' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Result' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Index' })[0]);
+ userEvent.click(screen.getAllByRole('button', { name: 'Call Cell' })[0]);
+ userEvent.click(
+ screen.getAllByRole('button', { name: 'Call Navigate' })[0]
+ );
+ userEvent.click(screen.getAllByRole('button')[0]);
+ userEvent.click(screen.getAllByRole('button')[1]);
+ userEvent.click(screen.getAllByRole('button')[2]);
+ userEvent.click(screen.getAllByRole('button')[3]);
+ userEvent.click(screen.getAllByRole('button')[4]);
+ userEvent.click(screen.getAllByRole('button')[5]);
+ userEvent.click(screen.getAllByRole('button')[6]);
+ userEvent.click(screen.getAllByRole('button')[7]);
+ userEvent.click(screen.getAllByRole('button')[8]);
+ userEvent.click(screen.getAllByRole('button')[9]);
+ userEvent.click(screen.getAllByRole('button')[10]);
+ userEvent.click(screen.getAllByRole('button')[11]);
+ userEvent.click(
+ screen.getAllByRole('button', { name: 'Call ResultMark' })[0]
+ );
+ userEvent.click(
+ screen.getAllByRole('link', { name: 'formatter Title' })[0]
+ );
+ userEvent.click(
+ screen.getAllByRole('button', {
+ name: 'In transit items report (CSV)',
+ })[0]
+ );
+ userEvent.click(
+ screen.getAllByRole('button', { name: 'Export instances (MARC)' })[0]
+ );
+ userEvent.click(screen.getAllByTestId('relation')[0]);
+ userEvent.click(screen.getAllByTestId('publishers')[0]);
+ userEvent.click(screen.getAllByTestId('contributors')[0]);
+ expect(
+ screen.getAllByRole('button', { name: 'Save holdings UUIDs' })[0]
+ ).toBeVisible();
});
});