Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDSC-3890: EDSC shows empty granules for the collections list after hitting back to search on collections with customizable options #1697

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ChunkedOrderModal extends Component {
})
}
}
updatePath
>
Refine your search
</PortalLinkContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import {
render,
screen,
waitFor
} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import '@testing-library/jest-dom'
import { Router } from 'react-router'
import { Provider } from 'react-redux'
import { createMemoryHistory } from 'history'

import ChunkedOrderModal from '../ChunkedOrderModal'
import PortalLinkContainer from '../../../containers/PortalLinkContainer/PortalLinkContainer'

import configureStore from '../../../store/configureStore'

const mockOnToggleChunkedOrderModal = jest.fn()

beforeEach(() => {
jest.clearAllMocks()
})

// In order to pass out of scope variables into `jest` they must be prefixed with `mock`
jest.mock('../../../containers/PortalLinkContainer/PortalLinkContainer', () => jest.fn(({ children }) => (
<mock-PortalLinkContainer
onClick={mockOnToggleChunkedOrderModal}
>
{children}
</mock-PortalLinkContainer>
)))

const store = configureStore()

function setup(overrideProps = {}) {
Expand All @@ -31,7 +50,7 @@ function setup(overrideProps = {}) {
}
},
onSubmitRetrieval: jest.fn(),
onToggleChunkedOrderModal: jest.fn(),
onToggleChunkedOrderModal: mockOnToggleChunkedOrderModal,
...overrideProps
}

Expand Down Expand Up @@ -87,23 +106,28 @@ describe('ChunkedOrderModal component', () => {

test('should render a \'Refine your search\' link that keeps the project params intact and removes the focused collection', async () => {
const user = userEvent.setup()
const { history } = setup()

await user.click(screen.getByRole('button', { name: 'Refine your search' }))

expect(history.location.pathname).toEqual('/search')
expect(decodeURIComponent(history.location.search)).toContain('?p=!C100005-EDSC&pg[1][v]=t')
setup()
await user.click(screen.getByText('Refine your search'))

await waitFor(() => {
expect(PortalLinkContainer).toHaveBeenCalledTimes(1)
expect(PortalLinkContainer).toHaveBeenCalledWith(expect.objectContaining({
children: 'Refine your search',
to: {
pathname: '/search',
search: '?p=!C100005-EDSC&pg[1][v]=t'
},
updatePath: true
}), {})
})
})

describe('modal actions', () => {
test('\'Refine your search\' button should trigger onToggleChunkedOrderModal', async () => {
const user = userEvent.setup()
const { onToggleChunkedOrderModal } = setup()

await user.click(screen.getByRole('button', { name: 'Refine your search' }))

await user.click(screen.getByText('Refine your search'))
expect(onToggleChunkedOrderModal).toHaveBeenCalledTimes(1)
expect(onToggleChunkedOrderModal).toHaveBeenCalledWith(false)
})

test('\'Change access methods\' button should trigger onToggleChunkedOrderModal', async () => {
Expand Down