Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -52,6 +58,13 @@ describe('ProductionLocationDialog', () => {
}
}

beforeEach(() => {
useHistory.mockReturnValue({
push: mockHistoryPush,
listen: jest.fn(() => jest.fn()),
});
});

test('renders dialog content', () => {
render(
<Router>
Expand Down Expand Up @@ -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(
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
osID={defaultProps.osID}
moderationStatus='APPROVED'
claimStatus='unclaimed'
/>
</Router>
);

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(
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
osID={defaultProps.osID}
moderationStatus='APPROVED'
claimStatus='unclaimed'
/>
</Router>
);

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(
<Router history={history}>
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
Expand All @@ -160,6 +211,6 @@ describe('ProductionLocationDialog', () => {
const closeButton = screen.getByRole('button', { name: /close/i });

fireEvent.click(closeButton);
expect(history.location.pathname).toBe('/');
expect(mockHistoryPush).toHaveBeenCalledWith('/');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import DialogTooltip from './DialogTooltip';
import ProductionLocationDialogFields from './ProductionLocationDialogFields';
import {
mainRoute,
searchByNameAndAddressResultRoute,
contributeProductionLocationRoute,
MODERATION_STATUSES_ENUM,
PRODUCTION_LOCATION_CLAIM_STATUSES_ENUM,
Expand Down Expand Up @@ -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 ? (
Expand Down Expand Up @@ -285,7 +284,7 @@ const ProductionLocationDialog = ({
<Button
variant="contained"
color="secondary"
onClick={handleGoToSearchByNameAndAddressResult}
onClick={handleGoToSearchByNameAndAddress}
className={classes.button}
>
Submit another Location
Expand Down