Skip to content

Commit

Permalink
Merge pull request #13885 from transcom/b20884-INT2-fix_prime_weight_…
Browse files Browse the repository at this point in the history
…tool_tip

B20884-INT2-fix prime weight tool tip
  • Loading branch information
JamesHawks224 authored Oct 11, 2024
2 parents a62ed74 + 602cf51 commit e38e70c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
35 changes: 25 additions & 10 deletions src/components/ShipmentList/ShipmentList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const ShipmentListItem = ({
showShipmentWeight,
isOverweight,
isMissingWeight,
showShipmentTooltip,
}) => {
const isMobileHome = shipment.shipmentType === SHIPMENT_OPTIONS.MOBILE_HOME;
const isPPM = shipment.shipmentType === SHIPMENT_OPTIONS.PPM;
Expand Down Expand Up @@ -65,15 +66,17 @@ export const ShipmentListItem = ({
{showNumber && ` ${shipmentNumber}`}
</strong>{' '}
<br />
{(shipment.shipmentType === SHIPMENT_OPTIONS.HHG ||
shipment.shipmentType === SHIPMENT_OPTIONS.NTS ||
isBoat) && (
<>
<span>{formatWeight(shipment.primeEstimatedWeight * WEIGHT_ADJUSTMENT)} </span>
<ToolTip text="110% Prime Estimated Weight" icon="circle-question" closeOnLeave />
</>
)}
{shipment.shipmentType === SHIPMENT_OPTIONS.NTSR && (
{showShipmentTooltip &&
(shipment.shipmentType === SHIPMENT_OPTIONS.HHG ||
shipment.shipmentType === SHIPMENT_OPTIONS.NTS ||
isBoat ||
isMobileHome) && (
<>
<span>{formatWeight(shipment.primeEstimatedWeight * WEIGHT_ADJUSTMENT)} </span>
<ToolTip text="110% Prime Estimated Weight" icon="circle-question" closeOnLeave />
</>
)}
{showShipmentTooltip && shipment.shipmentType === SHIPMENT_OPTIONS.NTSR && (
<>
<span>{formatWeight(shipment.ntsRecordedWeight * WEIGHT_ADJUSTMENT)} </span>
<ToolTip text="110% Previously Recorded Weight" icon="circle-question" closeOnLeave />
Expand Down Expand Up @@ -144,6 +147,7 @@ ShipmentListItem.propTypes = {
showNumber: bool,
showIncomplete: bool,
showShipmentWeight: bool,
showShipmentTooltip: bool,
isOverweight: bool,
isMissingWeight: bool,
};
Expand All @@ -152,13 +156,21 @@ ShipmentListItem.defaultProps = {
showNumber: true,
showIncomplete: false,
showShipmentWeight: false,
showShipmentTooltip: false,
isOverweight: false,
isMissingWeight: false,
onShipmentClick: null,
onDeleteClick: null,
};

const ShipmentList = ({ shipments, onShipmentClick, onDeleteClick, moveSubmitted, showShipmentWeight }) => {
const ShipmentList = ({
shipments,
onShipmentClick,
onDeleteClick,
moveSubmitted,
showShipmentWeight,
showShipmentTooltip,
}) => {
const shipmentNumbersByType = {};
const shipmentCountByType = {};
shipments.forEach((shipment) => {
Expand Down Expand Up @@ -226,6 +238,7 @@ const ShipmentList = ({ shipments, onShipmentClick, onDeleteClick, moveSubmitted
shipmentNumber={shipmentNumber}
showNumber={showNumber}
showShipmentWeight={showShipmentWeight}
showShipmentTooltip={showShipmentTooltip}
canEditOrDelete={canEditOrDelete}
isOverweight={isOverweight}
showIncomplete={isIncomplete}
Expand All @@ -246,10 +259,12 @@ ShipmentList.propTypes = {
onDeleteClick: func,
moveSubmitted: bool.isRequired,
showShipmentWeight: bool,
showShipmentTooltip: bool,
};

ShipmentList.defaultProps = {
showShipmentWeight: false,
showShipmentTooltip: false,
onShipmentClick: null,
onDeleteClick: null,
};
Expand Down
48 changes: 47 additions & 1 deletion src/components/ShipmentList/ShipmentList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';

import ShipmentList from './ShipmentList';

import { SHIPMENT_OPTIONS } from 'shared/constants';
import { SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants';
import { formatWeight } from 'utils/formatters';

beforeEach(() => {
Expand Down Expand Up @@ -97,6 +97,52 @@ describe('ShipmentList component', () => {
});
});

describe('ShipmentList shipment weight tooltip', () => {
const defaultProps = {
moveSubmitted: false,
};

it.each([
[SHIPMENT_OPTIONS.HHG, 'ID-2', '110% Prime Estimated Weight'],
[SHIPMENT_OPTIONS.NTS, 'ID-3', '110% Prime Estimated Weight'],
[SHIPMENT_OPTIONS.NTSR, 'ID-4', '110% Previously Recorded Weight'],
[SHIPMENT_TYPES.BOAT_HAUL_AWAY, 'ID-5', '110% Prime Estimated Weight'],
[SHIPMENT_TYPES.BOAT_TOW_AWAY, 'ID-6', '110% Prime Estimated Weight'],
[SHIPMENT_OPTIONS.MOBILE_HOME, 'ID-7', '110% Prime Estimated Weight'],
])('shipment weight tooltip, show is true. %s', async (type, id, expectedTooltipText) => {
// Render component
const props = { ...defaultProps, showShipmentTooltip: true, shipments: [{ id, shipmentType: type }] };
render(<ShipmentList {...props} />);

// Verify tooltip exists
const tooltipIcon = screen.getByTestId('tooltip-container');
expect(tooltipIcon).toBeInTheDocument();

// Click the tooltip
await userEvent.hover(tooltipIcon);

// Verify tooltip text
const tooltipText = await screen.findByText(expectedTooltipText);
expect(tooltipText).toBeInTheDocument();
});

it.each([
[SHIPMENT_OPTIONS.HHG, 'ID-2'],
[SHIPMENT_OPTIONS.NTS, 'ID-3'],
[SHIPMENT_OPTIONS.NTSR, 'ID-4'],
[SHIPMENT_TYPES.BOAT_HAUL_AWAY, 'ID-5'],
[SHIPMENT_TYPES.BOAT_TOW_AWAY, 'ID-6'],
[SHIPMENT_OPTIONS.MOBILE_HOME, 'ID-7'],
])('shipment weight tooltip, show is false. %s', async (type, id) => {
// Render component
const props = { ...defaultProps, showShipmentTooltip: false, shipments: [{ id, shipmentType: type }] };
render(<ShipmentList {...props} />);

// Verify tooltip doesn't exist
expect(screen.queryByTestId('tooltip-container')).not.toBeInTheDocument();
});
});

describe('Shipment List being used for billable weight', () => {
it('renders maximum billable weight, actual billable weight, actual weight and weight allowance with no flags', () => {
const shipments = [
Expand Down
1 change: 1 addition & 0 deletions src/shared/ToolTip/ToolTip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ToolTip = ({ text, position, icon, color, closeOnLeave, title }) => {
return (
<div
className={styles.tooltipContainer}
data-testid="tooltip-container"
onMouseEnter={() => setIsVisible(true)}
onMouseLeave={() => closeOnMouseLeave()}
onClick={() => determineIsVisible()}
Expand Down
10 changes: 10 additions & 0 deletions src/shared/ToolTip/ToolTip.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';

import ToolTip from './ToolTip';

Expand Down Expand Up @@ -85,4 +86,13 @@ describe('ToolTip', () => {
expect(tooltipTitle.exists()).toBe(false);
expect(tooltipBody.text()).toBe(bodyText);
});

it('verify data-testid is present', () => {
const text = 'Test Text';
render(<ToolTip text={text} icon="circle-question" position="left" />);

// Verify data-testid is present
const tooltipIcon = screen.getByTestId('tooltip-container');
expect(tooltipIcon).toBeInTheDocument();
});
});

0 comments on commit e38e70c

Please sign in to comment.