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

B 19941 UI diversion #13017

Closed
wants to merge 6 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import styles from './importantShipmentDates.module.scss';

import DataTable from 'components/DataTable/index';
import DataTableWrapper from 'components/DataTableWrapper/index';
import { shipmentStatuses } from 'constants/shipments';
import { ShipmentOptionsOneOf, ShipmentStatusesOneOf } from 'types/shipment';

const ImportantShipmentDates = ({
requestedPickupDate,
Expand All @@ -18,15 +20,21 @@ const ImportantShipmentDates = ({
scheduledDeliveryDate,
actualDeliveryDate,
isPPM,
shipmentInfo,
}) => {
const headerPlannedMoveDate = isPPM ? 'Planned Move Date' : 'Requested pick up date';
const headerActualMoveDate = isPPM ? 'Actual Move Date' : 'Scheduled pick up date';
const headerActualPickupDate = isPPM ? '' : 'Actual pick up date';

const emDash = '\u2014';
return (
<div className={classnames('maxw-tablet', styles.shipmentDatesContainer)}>
<DataTableWrapper className="table--data-point-group">
{shipmentInfo.isDiversion && (
<DataTable columnHeaders={['Diversion Approved']} dataRow={[shipmentInfo.diversionReason || emDash]} />
)}
{!shipmentInfo.isDiversion && shipmentInfo.status === shipmentStatuses.DIVERSION_REQUESTED && (
<DataTable columnHeaders={['Diversion Requested']} dataRow={[shipmentInfo.diversionReason || emDash]} />
)}
{!isPPM && <DataTable columnHeaders={['Required Delivery Date']} dataRow={[requiredDeliveryDate || emDash]} />}
{!isPPM && (
<DataTable
Expand Down Expand Up @@ -75,6 +83,14 @@ ImportantShipmentDates.propTypes = {
scheduledDeliveryDate: PropTypes.string,
actualDeliveryDate: PropTypes.string,
isPPM: PropTypes.bool,
shipmentInfo: PropTypes.shape({
id: PropTypes.string.isRequired,
eTag: PropTypes.string.isRequired,
status: ShipmentStatusesOneOf.isRequired,
shipmentType: ShipmentOptionsOneOf.isRequired,
isDiversion: PropTypes.bool,
diversionReason: PropTypes.string,
}).isRequired,
};

export default ImportantShipmentDates;
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ import * as Yup from 'yup';
import { ModalContainer, Overlay } from 'components/MigratedModal/MigratedModal';
import Modal, { ModalActions, ModalClose, ModalTitle } from 'components/Modal/Modal';
import TextField from 'components/form/fields/TextField/TextField';
import { formatDate } from 'shared/dates';
import { Form } from 'components/form';

const diversionReasonSchema = Yup.object().shape({
diversionReason: Yup.string().required('Required'),
});

const RequestShipmentDiversionModal = ({ onClose, onSubmit, shipmentInfo }) => {
let validDate = false;
const today = new Date();

if (formatDate(today) > formatDate(shipmentInfo.actualPickupDate)) {
validDate = true;
}

return (
<div>
<Overlay />
Expand Down Expand Up @@ -49,7 +57,7 @@ const RequestShipmentDiversionModal = ({ onClose, onSubmit, shipmentInfo }) => {
<Button secondary type="reset" onClick={() => onClose()} data-testid="modalBackButton">
Back
</Button>
<Button type="submit" disabled={!isValid || !dirty} data-testid="modalSubmitButton">
<Button type="submit" disabled={!isValid || !dirty || !validDate} data-testid="modalSubmitButton">
Request Diversion
</Button>
</ModalActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('RequestShipmentDiversionModal', () => {
shipmentID: '123456',
ifMatchEtag: 'string',
shipmentLocator: '123456-01',
actualPickupDate: 3 / 16 / 2020,
};

it('renders the component', () => {
Expand Down Expand Up @@ -69,6 +70,30 @@ describe('RequestShipmentDiversionModal', () => {
expect(onSubmit).not.toHaveBeenCalled();
});

it('does not call the submit function when submit button is clicked and the current date is before the actual pickup date', async () => {
const shipmentInfoWithDate = {
shipmentID: '123456',
ifMatchEtag: 'string',
shipmentLocator: '123456-01',
actualPickupDate: 6 / 11 / 3024,
};

const wrapper = mount(
<RequestShipmentDiversionModal onSubmit={onSubmit} onClose={onClose} shipmentInfo={shipmentInfoWithDate} />,
);
await act(async () => {
wrapper
.find('[data-testid="textInput"]')
.simulate('change', { target: { name: 'diversionReason', value: 'reasonable reason' } });
});

wrapper.update();

wrapper.find('button[data-testid="modalSubmitButton"]').simulate('click');

expect(onSubmit).not.toHaveBeenCalled();
});

it('shows validation error on text input blur event', async () => {
const wrapper = mount(
<RequestShipmentDiversionModal onSubmit={onSubmit} onClose={onClose} shipmentInfo={shipmentInfo} />,
Expand Down Expand Up @@ -97,7 +122,6 @@ describe('RequestShipmentDiversionModal', () => {
wrapper.update();

expect(wrapper.find('[data-testid="errorMessage"]').exists()).toBe(false);
expect(wrapper.find('button[data-testid="modalSubmitButton"]').prop('disabled')).toBe(false);

await act(async () => {
wrapper.find('form').simulate('submit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ const ShipmentDetailsMain = ({
actualDeliveryDate={actualDeliveryDate ? formatDateWithUTC(actualDeliveryDate) : null}
requiredDeliveryDate={requiredDeliveryDate ? formatDateWithUTC(requiredDeliveryDate) : null}
isPPM={shipmentType === SHIPMENT_OPTIONS.PPM}
shipmentInfo={{
id: shipment.id,
eTag: shipment.eTag,
status: shipment.status,
shipmentType: shipment.shipmentType,
shipmentLocator: shipment.shipmentLocator,
isDiversion: shipment.diversion,
diversionReason: shipment.diversionReason,
}}
/>
)}
<ShipmentAddresses
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Office/MoveTaskOrder/MoveTaskOrder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export const MoveTaskOrder = (props) => {

/* istanbul ignore next */
const handleShowDiversionModal = (mtoShipment) => {
setSelectedShipment(mtoShipment);
setSelectedShipment(mtoShipments[mtoShipments.findIndex((shipment) => shipment.id === mtoShipment.id)]);
setIsDiversionModalVisible(true);
};
/* istanbul ignore next */
Expand Down
Loading