Skip to content

Commit

Permalink
Merge pull request #14653 from transcom/INT-B-22239-Show-Deleted-Agen…
Browse files Browse the repository at this point in the history
…t-In-Move-History

INT-B-22239 show deleted agent in move history
  • Loading branch information
brianmanley-caci authored Jan 24, 2025
2 parents 42ce655 + 5dda619 commit 6c69f1c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import 'shared/styles/colors';

.shipmentType {
display: block;
color: $base;
margin-bottom: 8px 0;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';

import styles from './UpdateMTOShipmentAgent.module.scss';

import { formatMoveHistoryAgent } from 'utils/formatters';
import fieldMappings from 'constants/MoveHistory/Database/FieldMappings';
import o from 'constants/MoveHistory/UIDisplay/Operations';
import a from 'constants/MoveHistory/Database/Actions';
import t from 'constants/MoveHistory/Database/Tables';
Expand All @@ -26,10 +29,34 @@ const formatChangedValues = (historyRecord) => {
return { ...historyRecord, changedValues: newChangedValues };
};

const formatDeletedAgentRecord = (historyRecord) => {
const mtoShipmentLabel = getMtoShipmentLabel(historyRecord);
const historyLabel = `${mtoShipmentLabel.shipment_type} shipment #${mtoShipmentLabel.shipment_locator}`;
const agentTypeFieldName = historyRecord.oldValues.agent_type.toLowerCase();
const agentType = fieldMappings[agentTypeFieldName];
const agent = formatMoveHistoryAgent(historyRecord.oldValues)[agentTypeFieldName];

return (
<>
<span className={styles.shipmentType}>
Deleted {agentType} on {historyLabel}
</span>
<div>
<b>{agentType}</b>: {agent}
</div>
</>
);
};

export default {
action: a.UPDATE,
eventName: o.updateMTOShipment,
tableName: t.mto_agents,
getEventNameDisplay: () => 'Updated shipment',
getDetails: (historyRecord) => <LabeledDetails historyRecord={formatChangedValues(historyRecord)} />,
getDetails: (historyRecord) => {
if (historyRecord.changedValues.deleted_at) {
return formatDeletedAgentRecord(historyRecord);
}
return <LabeledDetails historyRecord={formatChangedValues(historyRecord)} />;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@ describe('when given an mto shipment agents update with mto agents table history
},
context: [{ shipment_type: 'HHG', shipment_locator: 'RQ38D4-01', shipment_id_abbr: 'a1b2c' }],
},
DELETED_RECEIVING_AGENT: {
action: 'UPDATE',
eventName: 'updateMTOShipment',
tableName: 'mto_agents',
changedValues: {
deleted_at: '2025-01-21T15:39:24.890356+00:00',
email: null,
first_name: null,
last_name: null,
phone: null,
},
oldValues: {
agent_type: 'RECEIVING_AGENT',
email: '[email protected]',
first_name: 'John',
last_name: 'Smith',
phone: '555-765-4321',
},
context: [{ shipment_type: 'HHG', shipment_locator: 'RQ38D4-01', shipment_id_abbr: 'a1b2c' }],
},
DELETED_RELEASING_AGENT: {
action: 'UPDATE',
eventName: 'updateMTOShipment',
tableName: 'mto_agents',
changedValues: {
deleted_at: '2025-01-21T16:39:24.890356+00:00',
email: null,
first_name: null,
last_name: null,
phone: null,
},
oldValues: {
agent_type: 'RELEASING_AGENT',
email: '[email protected]',
first_name: 'Jane',
last_name: 'Smith',
phone: '555-123-4567',
},
context: [{ shipment_type: 'NTS', shipment_locator: 'RQ38D4-01', shipment_id_abbr: 'a1b2c' }],
},
};

describe('when agent type is Releasing', () => {
Expand Down Expand Up @@ -75,12 +115,30 @@ describe('when given an mto shipment agents update with mto agents table history
expect(screen.getAllByText('HHG shipment #RQ38D4-01'));
});

it('it displays the proper labeled details for the given releasing agent', () => {
it('it displays the proper labeled details for the given receiving agent', () => {
const template = getTemplate(historyRecord.RECEIVE);

render(template.getDetails(historyRecord.RECEIVE));
expect(screen.getByText('Receiving agent')).toBeInTheDocument();
expect(screen.getByText(': Nancy Drew, 555-555-5555, [email protected]')).toBeInTheDocument();
});
});

describe('when agent is deleted', () => {
it('displays deleted receiving agent', () => {
const template = getTemplate(historyRecord.DELETED_RECEIVING_AGENT);
render(template.getDetails(historyRecord.DELETED_RECEIVING_AGENT));
expect(screen.getByText('Deleted Receiving agent on HHG shipment #RQ38D4-01')).toBeInTheDocument();
expect(screen.getByText('Receiving agent')).toBeInTheDocument();
expect(screen.getByText(': John Smith, 555-765-4321, [email protected]')).toBeInTheDocument();
});

it('displays deleted releasing agent', () => {
const template = getTemplate(historyRecord.DELETED_RELEASING_AGENT);
render(template.getDetails(historyRecord.DELETED_RELEASING_AGENT));
expect(screen.getByText('Deleted Releasing agent on NTS shipment #RQ38D4-01')).toBeInTheDocument();
expect(screen.getByText('Releasing agent')).toBeInTheDocument();
expect(screen.getByText(': Jane Smith, 555-123-4567, [email protected]')).toBeInTheDocument();
});
});
});

0 comments on commit 6c69f1c

Please sign in to comment.