From 67f8705e30d23a3d6ef77c1dbc15f06648474924 Mon Sep 17 00:00:00 2001 From: VSnehalatha Date: Fri, 23 Jun 2023 13:24:20 +0530 Subject: [PATCH 1/6] UIIN-1577 create Jest/RTL test for InstancesList.js --- .../InstancesList/InstancesList.test.js | 525 +++++++++++------- test/jest/__mock__/stripesConnect.mock.js | 3 + 2 files changed, 340 insertions(+), 188 deletions(-) create mode 100644 test/jest/__mock__/stripesConnect.mock.js diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index a48c26332..721cdbed8 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -1,27 +1,30 @@ +/* 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 { createMemoryHistory } from 'history'; -import { - act, - fireEvent, - screen, - waitFor, - cleanup, - within, -} from '@folio/jest-config-stripes/testing-library/react'; - -import '../../../test/jest/__mock__'; - -import { StripesContext, ModuleHierarchyProvider } from '@folio/stripes/core'; - +import { screen } from '@folio/jest-config-stripes/testing-library/react'; + +import '../../../test/jest/__mock__/stripesConnect.mock'; +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 { SORTABLE_SEARCH_RESULT_LIST_COLUMNS } from '../../constants'; const updateMock = jest.fn(); const mockQueryReplace = jest.fn(); @@ -31,11 +34,201 @@ const mockRecordsReset = jest.fn(); const mockGetLastSearchOffset = jest.fn(); const mockStoreLastSearchOffset = 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('../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', @@ -53,7 +246,7 @@ const data = { facets: [], }; const query = { - query: '', + query: true, sort: 'title', }; @@ -70,7 +263,7 @@ const resources = { hasLoaded: true, resource: 'facets', records: [], - other: { totalRecords: 0 } + other: { totalRecords: 0 }, }, resultCount: instancesFixture.length, resultOffset: 0, @@ -78,59 +271,63 @@ 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' }); }); @@ -146,7 +343,7 @@ describe('InstancesList', () => { expect(mockStoreLastSearch).toHaveBeenCalledWith(search); }); - describe('and browse result was selected', () => { + describe('browse result was selected', () => { it('should reset offset', () => { mockResultOffsetReplace.mockClear(); const params = { @@ -165,7 +362,7 @@ describe('InstancesList', () => { }); }); - describe('and browse result was not selected', () => { + describe('browse result was not selected', () => { it('should replace resultOffset', () => { mockResultOffsetReplace.mockClear(); @@ -180,29 +377,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); }); + 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); + }); }); - 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); }); @@ -219,133 +425,76 @@ describe('InstancesList', () => { }); }); - it('should pass the correct search by clicking on the `Browse` tab', () => { - cleanup(); - const search = '?qindex=subjects&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 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' }); - - waitFor(() => { - fireEvent.click(button); - expect(history.push).toHaveBeenCalledWith('/?layer=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 () => userEvent.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'); + 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(); }); }); diff --git a/test/jest/__mock__/stripesConnect.mock.js b/test/jest/__mock__/stripesConnect.mock.js new file mode 100644 index 000000000..1327fe127 --- /dev/null +++ b/test/jest/__mock__/stripesConnect.mock.js @@ -0,0 +1,3 @@ +import React from 'react'; + +jest.mock('@folio/stripes-core/src/stripesConnect', () => Component => props => ); From 6b47bd089ca39a9269326f9233556a99cc6d2e45 Mon Sep 17 00:00:00 2001 From: VSnehalatha <53073086+VSnehalatha@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:35:47 +0530 Subject: [PATCH 2/6] Update InstancesList.test.js --- .../InstancesList/InstancesList.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index 721cdbed8..b69618fdb 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -5,9 +5,9 @@ import { Router } from 'react-router-dom'; import { noop } from 'lodash'; import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; import { createMemoryHistory } from 'history'; -import { screen } from '@folio/jest-config-stripes/testing-library/react'; - -import '../../../test/jest/__mock__/stripesConnect.mock'; +import { + screen +} from '@folio/jest-config-stripes/testing-library/react'; import '../../../test/jest/__mock__/stripesConfig.mock'; import '../../../test/jest/__mock__/currencyData.mock'; import '../../../test/jest/__mock__/documentCreateRange.mock'; @@ -313,6 +313,7 @@ const renderInstancesList = ({ segment, ...rest }, rerender) => { getLastSearchOffset={mockGetLastSearchOffset} storeLastSearch={mockStoreLastSearch} storeLastSearchOffset={mockStoreLastSearchOffset} + storeLastSegment={jest.fn()} {...rest} /> @@ -340,7 +341,7 @@ describe('InstancesList', () => { it('should write location.search to the session storage', () => { const search = '?qindex=title&query=book&sort=title'; history.push({ search }); - expect(mockStoreLastSearch).toHaveBeenCalledWith(search); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search, "instances"); }); describe('browse result was selected', () => { @@ -382,13 +383,13 @@ describe('InstancesList', () => { const search = '?qindex=title&query=book&sort=title'; mockStoreLastSearch.mockClear(); history.push({ search }); - expect(mockStoreLastSearch).toHaveBeenCalledWith(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); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search, "instances"); }); }); @@ -410,7 +411,7 @@ describe('InstancesList', () => { rerender ); - expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset); + expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset, "instances"); }); }); }); @@ -450,7 +451,6 @@ describe('rendering InstancesList with holdings segment', () => { 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]); From f5b7ae2e9007b6339aab898f6151ab0c1c6aaaf0 Mon Sep 17 00:00:00 2001 From: VSnehalatha <53073086+VSnehalatha@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:37:23 +0530 Subject: [PATCH 3/6] Update InstancesList.test.js --- .../InstancesList/InstancesList.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index b69618fdb..721cdbed8 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -5,9 +5,9 @@ import { Router } from 'react-router-dom'; import { noop } from 'lodash'; import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; import { createMemoryHistory } from 'history'; -import { - screen -} from '@folio/jest-config-stripes/testing-library/react'; +import { screen } from '@folio/jest-config-stripes/testing-library/react'; + +import '../../../test/jest/__mock__/stripesConnect.mock'; import '../../../test/jest/__mock__/stripesConfig.mock'; import '../../../test/jest/__mock__/currencyData.mock'; import '../../../test/jest/__mock__/documentCreateRange.mock'; @@ -313,7 +313,6 @@ const renderInstancesList = ({ segment, ...rest }, rerender) => { getLastSearchOffset={mockGetLastSearchOffset} storeLastSearch={mockStoreLastSearch} storeLastSearchOffset={mockStoreLastSearchOffset} - storeLastSegment={jest.fn()} {...rest} /> @@ -341,7 +340,7 @@ describe('InstancesList', () => { it('should write location.search to the session storage', () => { const search = '?qindex=title&query=book&sort=title'; history.push({ search }); - expect(mockStoreLastSearch).toHaveBeenCalledWith(search, "instances"); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search); }); describe('browse result was selected', () => { @@ -383,13 +382,13 @@ describe('InstancesList', () => { const search = '?qindex=title&query=book&sort=title'; mockStoreLastSearch.mockClear(); history.push({ search }); - expect(mockStoreLastSearch).toHaveBeenCalledWith(search, "instances"); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search); }); 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"); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search); }); }); @@ -411,7 +410,7 @@ describe('InstancesList', () => { rerender ); - expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset, "instances"); + expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset); }); }); }); @@ -451,6 +450,7 @@ describe('rendering InstancesList with holdings segment', () => { 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]); From 7f801738d745f70e6598c5129c799e9b04f8ae95 Mon Sep 17 00:00:00 2001 From: VSnehalatha <53073086+VSnehalatha@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:19:50 +0530 Subject: [PATCH 4/6] Update InstancesList.test.js --- src/components/InstancesList/InstancesList.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index bffc5f97d..a9243eefe 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -3,9 +3,9 @@ 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 { screen } from '@folio/jest-config-stripes/testing-library/react'; +import { screen } from '@testing-library/react'; import '../../../test/jest/__mock__/stripesConnect.mock'; import '../../../test/jest/__mock__/stripesConfig.mock'; From c3d9d1e2088015d0dea871ebf8f06bd04e1d0fda Mon Sep 17 00:00:00 2001 From: VSnehalatha <53073086+VSnehalatha@users.noreply.github.com> Date: Fri, 28 Jul 2023 16:47:33 +0530 Subject: [PATCH 5/6] Update InstancesList.test.js --- .../InstancesList/InstancesList.test.js | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index a9243eefe..d681c0edf 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -5,9 +5,10 @@ import { Router } from 'react-router-dom'; import { noop } from 'lodash'; import userEvent from '@testing-library/user-event'; import { createMemoryHistory } from 'history'; -import { screen } from '@testing-library/react'; +import { + screen +} from '@testing-library/react'; -import '../../../test/jest/__mock__/stripesConnect.mock'; import '../../../test/jest/__mock__/stripesConfig.mock'; import '../../../test/jest/__mock__/currencyData.mock'; import '../../../test/jest/__mock__/documentCreateRange.mock'; @@ -33,12 +34,6 @@ 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'); @@ -319,6 +314,7 @@ const renderInstancesList = ({ segment, ...rest }, rerender) => { getLastSearchOffset={mockGetLastSearchOffset} storeLastSearch={mockStoreLastSearch} storeLastSearchOffset={mockStoreLastSearchOffset} + storeLastSegment={noop} {...rest} /> @@ -394,7 +390,7 @@ describe('InstancesList', () => { const search = '?qindex=title&query=book&sort=title&reset=true'; mockStoreLastSearch.mockClear(); history.push({ search }); - expect(mockStoreLastSearch).toHaveBeenCalledWith(search); + expect(mockStoreLastSearch).toHaveBeenCalledWith(search, 'instances'); }); }); @@ -444,22 +440,6 @@ describe('InstancesList', () => { expect(screen.getByText('Cancel Import')).toBeInTheDocument(); }); }); - - 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'); - }); - }); }); }); From 83ecf874f2231e75fe9a72cab2c8aae9eef1525e Mon Sep 17 00:00:00 2001 From: VSnehalatha <53073086+VSnehalatha@users.noreply.github.com> Date: Fri, 28 Jul 2023 16:49:35 +0530 Subject: [PATCH 6/6] Delete stripesConnect.mock.js --- test/jest/__mock__/stripesConnect.mock.js | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 test/jest/__mock__/stripesConnect.mock.js diff --git a/test/jest/__mock__/stripesConnect.mock.js b/test/jest/__mock__/stripesConnect.mock.js deleted file mode 100644 index 1327fe127..000000000 --- a/test/jest/__mock__/stripesConnect.mock.js +++ /dev/null @@ -1,3 +0,0 @@ -import React from 'react'; - -jest.mock('@folio/stripes-core/src/stripesConnect', () => Component => props => );