diff --git a/doc/release/RELEASE-NOTES.md b/doc/release/RELEASE-NOTES.md index 34e083ca3..6fb0e6a94 100644 --- a/doc/release/RELEASE-NOTES.md +++ b/doc/release/RELEASE-NOTES.md @@ -61,6 +61,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html All other traffic will be redirected to the React application. ### Bugfix +* [OSDEV-1698](https://opensupplyhub.atlassian.net/browse/OSDEV-1698) - SLC: Refactored the "Submit Another Location" button link to direct users to the search-by-name-and-address form at /contribute/single-location?tab=name-address. * [OSDEV-1700](https://opensupplyhub.atlassian.net/browse/OSDEV-1700) - SLC: Keep only one previous OS ID in the search result if it matches the search query. * [OSDEV-1697](https://opensupplyhub.atlassian.net/browse/OSDEV-1697) - Added a redirect to the main page upon closing the SLC modal window to prevent the creation of multiple moderation events. * [OSDEV-1695](https://opensupplyhub.atlassian.net/browse/OSDEV-1695) - [SLC] Enabled the claim button for updated production locations when a moderation event has a pending status. Disabled claim button explicitly if production location has pending claim status. diff --git a/src/react/src/__tests__/components/ProductionLocationDialog.test.js b/src/react/src/__tests__/components/ProductionLocationDialog.test.js index 60e542714..aa765cbc5 100644 --- a/src/react/src/__tests__/components/ProductionLocationDialog.test.js +++ b/src/react/src/__tests__/components/ProductionLocationDialog.test.js @@ -1,11 +1,17 @@ import React from 'react'; import { render, screen, fireEvent } from '@testing-library/react'; -import { BrowserRouter as Router } from 'react-router-dom'; +import { BrowserRouter as Router, useHistory } from 'react-router-dom'; import ProductionLocationDialog from '../../components/Contribute/ProductionLocationDialog'; import ProductionLocationDialogCloseButton from '../../components/Contribute/ProductionLocationDialogCloseButton'; -import history from '../../util/history'; +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useHistory: jest.fn(), +})); + +const mockHistoryPush = jest.fn(); + describe('ProductionLocationDialog', () => { const defaultProps = { osID: 'US2021250D1DTN7', @@ -52,6 +58,13 @@ describe('ProductionLocationDialog', () => { } } + beforeEach(() => { + useHistory.mockReturnValue({ + push: mockHistoryPush, + listen: jest.fn(() => jest.fn()), + }); + }); + test('renders dialog content', () => { render( @@ -136,11 +149,49 @@ describe('ProductionLocationDialog', () => { const claimButton = getByRole('button', { name: /Continue to Claim/i }); expect(claimButton).toHaveAttribute('href', `/facilities/${defaultProps.osID}/claim`); - }) + }); + + test('Search OS Hub button should link to the main page', () => { + const { getByRole } = render( + + + + ); + + const searchOSHubButton = getByRole('button', { name: /Search OS Hub/i }); + fireEvent.click(searchOSHubButton); + + expect(mockHistoryPush).toHaveBeenCalledWith('/'); + }); + + test('Submit another Location button should link to the SLC search page', () => { + const { getByRole } = render( + + + + ); + + const submitAnotherLocationButton = getByRole('button', { name: /Submit another Location/i }); + fireEvent.click(submitAnotherLocationButton); + + expect(mockHistoryPush).toHaveBeenCalledWith('/contribute/single-location?tab=name-address'); + }); test('redirect to the main page when clicking close button', () => { render( - + { const closeButton = screen.getByRole('button', { name: /close/i }); fireEvent.click(closeButton); - expect(history.location.pathname).toBe('/'); + expect(mockHistoryPush).toHaveBeenCalledWith('/'); }); }); diff --git a/src/react/src/components/Contribute/ProductionLocationDialog.jsx b/src/react/src/components/Contribute/ProductionLocationDialog.jsx index 27751e81c..33db7ae94 100644 --- a/src/react/src/components/Contribute/ProductionLocationDialog.jsx +++ b/src/react/src/components/Contribute/ProductionLocationDialog.jsx @@ -26,7 +26,6 @@ import DialogTooltip from './DialogTooltip'; import ProductionLocationDialogFields from './ProductionLocationDialogFields'; import { mainRoute, - searchByNameAndAddressResultRoute, contributeProductionLocationRoute, MODERATION_STATUSES_ENUM, PRODUCTION_LOCATION_CLAIM_STATUSES_ENUM, @@ -143,8 +142,8 @@ const ProductionLocationDialog = ({ const statusLabel = startCase(toLower(moderationStatus)); const handleGoToMainPage = () => history.push(mainRoute); - const handleGoToSearchByNameAndAddressResult = () => - history.push(searchByNameAndAddressResultRoute); + const handleGoToSearchByNameAndAddress = () => + history.push(`${contributeProductionLocationRoute}?tab=name-address`); const deleteIcon = moderationStatus === MODERATION_STATUSES_ENUM.PENDING ? ( @@ -285,7 +284,7 @@ const ProductionLocationDialog = ({