From 0b862c8518c7d51c66530b61baa2bde51ddbeec0 Mon Sep 17 00:00:00 2001 From: loganwc Date: Mon, 16 Dec 2024 17:08:23 +0000 Subject: [PATCH 01/10] mobile home and boat shipments now have 2nd and 3rd address on create for prime sim --- .../Shipment/PrimeUIShipmentCreate.jsx | 70 +++++++++++++++++++ .../Shipment/PrimeUIShipmentCreate.test.jsx | 41 +++++++++++ 2 files changed, 111 insertions(+) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx index 36139c32e23..c265b67e98c 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx @@ -177,6 +177,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress, diversion, divertedFromShipmentId, + hasSecondaryPickupAddress, + hasSecondaryDestinationAddress, + hasTertiaryPickupAddress, + hasTertiaryDestinationAddress, boatShipment: { year, make, @@ -192,6 +196,23 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { }, } = values; + let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } = + values; + if (hasSecondaryPickupAddress !== 'true') { + secondaryPickupAddress = {}; + tertiaryPickupAddress = {}; + } + if (hasTertiaryPickupAddress !== 'true') { + tertiaryPickupAddress = {}; + } + if (hasSecondaryDestinationAddress !== 'true') { + secondaryDestinationAddress = {}; + tertiaryDestinationAddress = {}; + } + if (hasTertiaryDestinationAddress !== 'true') { + tertiaryDestinationAddress = {}; + } + // Sum the feet and inches fields into only inches for backend/db const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10); const totalWidthInInches = parseInt(widthInFeet, 10) * 12 + parseInt(widthInInches, 10); @@ -219,6 +240,20 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress), diversion: diversion || null, divertedFromShipmentId: divertedFromShipmentId || null, + hasSecondaryPickupAddress: hasSecondaryPickupAddress === 'true', + hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true', + hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true', + hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true', + secondaryPickupAddress: isEmpty(secondaryPickupAddress) + ? null + : formatAddressForPrimeAPI(secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + ? null + : formatAddressForPrimeAPI(secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + ? null + : formatAddressForPrimeAPI(tertiaryDestinationAddress), }; } else if (isMobileHome) { const { @@ -229,6 +264,10 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress, diversion, divertedFromShipmentId, + hasSecondaryPickupAddress, + hasSecondaryDestinationAddress, + hasTertiaryPickupAddress, + hasTertiaryDestinationAddress, mobileHomeShipment: { year, make, @@ -242,6 +281,23 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { }, } = values; + let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } = + values; + if (hasSecondaryPickupAddress !== 'true') { + secondaryPickupAddress = {}; + tertiaryPickupAddress = {}; + } + if (hasTertiaryPickupAddress !== 'true') { + tertiaryPickupAddress = {}; + } + if (hasSecondaryDestinationAddress !== 'true') { + secondaryDestinationAddress = {}; + tertiaryDestinationAddress = {}; + } + if (hasTertiaryDestinationAddress !== 'true') { + tertiaryDestinationAddress = {}; + } + // Sum the feet and inches fields into only inches for backend/db const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10); const totalWidthInInches = parseInt(widthInFeet, 10) * 12 + parseInt(widthInInches, 10); @@ -265,6 +321,20 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress), diversion: diversion || null, divertedFromShipmentId: divertedFromShipmentId || null, + hasSecondaryPickupAddress: hasSecondaryPickupAddress === 'true', + hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true', + hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true', + hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true', + secondaryPickupAddress: isEmpty(secondaryPickupAddress) + ? null + : formatAddressForPrimeAPI(secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + ? null + : formatAddressForPrimeAPI(secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + ? null + : formatAddressForPrimeAPI(tertiaryDestinationAddress), }; } else { const { diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index eec912b1793..ffa73be8202 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -171,3 +171,44 @@ describe('Create PPM', () => { }); }); }); + +describe('Create Mobile Home', () => { + it('test with 2nd addresses', async () => { + createPrimeMTOShipmentV3.mockReturnValue({}); + + render(mockedComponent); + + waitFor(async () => { + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'MOBILE_HOME'); + + // Start controlled test case to verify everything is working. + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Street'); + + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="pickupAddress.streetAddress2"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street'); + + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 Street'); + + const saveButton = await screen.getByRole('button', { name: 'Save' }); + + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + + await waitFor(() => { + expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + }); + }); + }); +}); From 6fd4cf00ec3760c0699326c369db94106ed774c2 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 18 Dec 2024 16:55:54 +0000 Subject: [PATCH 02/10] added 3rd address and fixed 2nd address test --- .../Shipment/PrimeUIShipmentCreate.test.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index ffa73be8202..815c90fc14b 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -173,7 +173,7 @@ describe('Create PPM', () => { }); describe('Create Mobile Home', () => { - it('test with 2nd addresses', async () => { + it('test with 2nd and 3rd addresses', async () => { createPrimeMTOShipmentV3.mockReturnValue({}); render(mockedComponent); @@ -191,10 +191,19 @@ describe('Create Mobile Home', () => { expect(secondAddressToggle).toBeInTheDocument(); await userEvent.click(secondAddressToggle); - input = await document.querySelector('input[name="pickupAddress.streetAddress2"]'); + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street'); + await userEvent.type(input, '123 Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 2'); input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); From 0c3f4ff41df6322fd73b362893f1a479a095b715 Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 18 Dec 2024 16:59:22 +0000 Subject: [PATCH 03/10] change typo --- src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index 815c90fc14b..7d3d732c89c 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -203,7 +203,7 @@ describe('Create Mobile Home', () => { input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 2'); + await userEvent.type(input, '123 Street 3'); input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); From ae862c0d915133e9a581508fe4ec94fce0f9c13a Mon Sep 17 00:00:00 2001 From: loganwc Date: Wed, 18 Dec 2024 20:17:14 +0000 Subject: [PATCH 04/10] added more test coverage to prime ui shipment create --- .../Shipment/PrimeUIShipmentCreate.test.jsx | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index 7d3d732c89c..fd49eff9b16 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -221,3 +221,66 @@ describe('Create Mobile Home', () => { }); }); }); + +describe('When creating shipment', () => { + it('disabling 2nd/3rd address clears out the data', async () => { + createPrimeMTOShipmentV3.mockReturnValue({}); + + render(mockedComponent); + + waitFor(async () => { + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'HHG'); + + // Start controlled test case to verify everything is working. + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Street'); + + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 3'); + + const disable3rdAddressToggle = document.querySelector('[data-testid="no-tertiary-pickup"]'); + expect(disable3rdAddressToggle).toBeInTheDocument(); + await userEvent.click(disable3rdAddressToggle); + + const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); + expect(disable2ndAddressToggle).toBeInTheDocument(); + await userEvent.click(disable2ndAddressToggle); + + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 Street'); + + const saveButton = await screen.getByRole('button', { name: 'Save' }); + + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + + await waitFor(() => { + expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith( + expect.objectContaining({ + secondaryPickupAddress: {}, + tertiaryPickupAddress: {}, + }), + ); + }); + }); + }); +}); From 26ba792683c0dc9337eed78b1711f58f394f6bfa Mon Sep 17 00:00:00 2001 From: loganwc Date: Mon, 23 Dec 2024 16:15:46 +0000 Subject: [PATCH 05/10] moved test from create to form --- .../Shipment/PrimeUIShipmentCreate.test.jsx | 63 ---------------- .../PrimeUIShipmentCreateForm.test.jsx | 75 ++++++++++++++++++- 2 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index fd49eff9b16..7d3d732c89c 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -221,66 +221,3 @@ describe('Create Mobile Home', () => { }); }); }); - -describe('When creating shipment', () => { - it('disabling 2nd/3rd address clears out the data', async () => { - createPrimeMTOShipmentV3.mockReturnValue({}); - - render(mockedComponent); - - waitFor(async () => { - await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'HHG'); - - // Start controlled test case to verify everything is working. - let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup - await userEvent.type(input, '123 Street'); - - const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); - expect(secondAddressToggle).toBeInTheDocument(); - await userEvent.click(secondAddressToggle); - - input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 2'); - - const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); - expect(thirdAddressToggle).toBeInTheDocument(); - await userEvent.click(thirdAddressToggle); - - input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 3'); - - const disable3rdAddressToggle = document.querySelector('[data-testid="no-tertiary-pickup"]'); - expect(disable3rdAddressToggle).toBeInTheDocument(); - await userEvent.click(disable3rdAddressToggle); - - const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); - expect(disable2ndAddressToggle).toBeInTheDocument(); - await userEvent.click(disable2ndAddressToggle); - - input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter something - await userEvent.type(input, '123 Street'); - - const saveButton = await screen.getByRole('button', { name: 'Save' }); - - expect(saveButton).not.toBeDisabled(); - await userEvent.click(saveButton); - - await waitFor(() => { - expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith( - expect.objectContaining({ - secondaryPickupAddress: {}, - tertiaryPickupAddress: {}, - }), - ); - }); - }); - }); -}); diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx index 80ea98a6f8a..833caf7e17a 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx @@ -181,7 +181,7 @@ function renderShipmentCreateForm(props) { jest.mock('utils/featureFlags', () => ({ ...jest.requireActual('utils/featureFlags'), - isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(false)), + isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve()), })); const mockNavigate = jest.fn(); @@ -493,4 +493,77 @@ describe('PrimeUIShipmentCreateForm', () => { // now the text input should be invisible expect(await screen.queryByTestId('divertedFromShipmentIdInput')).toBeNull(); }); + + it.each( + ['BOAT_HAUL_AWAY', 'BOAT_TOW_AWAY', 'MOBILE_HOME'], + 'when creating a %s clears 2nd/3rd address fields when secondary/tertiary checkbox is unchecked', + async (shipmentType) => { + // isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(false)); // Allow for testing of boats and mobile homes + isBooleanFlagEnabled.mockResolvedValue(true); + + const shipmentTypeInput = await screen.findByLabelText('Shipment type'); + expect(shipmentTypeInput).toBeInTheDocument(); + + // Select the boat or mobile home shipment type + await userEvent.selectOptions(shipmentTypeInput, [shipmentType]); + + // Make sure that a PPM-specific field is not visible. + expect(await screen.queryByLabelText('Expected Departure Date')).not.toBeInTheDocument(); + + // Check for usual HHG fields + expect(await screen.findByRole('heading', { name: 'Diversion', level: 2 })).toBeInTheDocument(); + expect(await screen.findByLabelText('Diversion')).not.toBeChecked(); + + // Checking to make sure the text box isn't shown prior to clicking the box + expect(screen.queryByTestId('divertedFromShipmentIdInput')).toBeNull(); + + // Check the diversion box + const diversionCheckbox = await screen.findByLabelText('Diversion'); + await userEvent.click(diversionCheckbox); + + // now the text input should be visible + expect(await screen.findByTestId('divertedFromShipmentIdInput')).toBeInTheDocument(); + + // Now check for a boat and mobile home shipment specific field + expect(await screen.findByLabelText('Length (Feet)')).toBeVisible(); + + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Pickup Street'); + + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Pickup Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Pickup Street 3'); + + const disable3rdAddressToggle = document.querySelector('[data-testid="no-tertiary-pickup"]'); + expect(disable3rdAddressToggle).toBeInTheDocument(); + await userEvent.click(disable3rdAddressToggle); + + const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); + expect(disable2ndAddressToggle).toBeInTheDocument(); + await userEvent.click(disable2ndAddressToggle); + + expect(input).not.toBeInTheDocument(); + + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 destination Street'); + }, + ); }); From 2bd0fd268eaef53939a04f341f41bb59f84b4579 Mon Sep 17 00:00:00 2001 From: loganwc Date: Mon, 23 Dec 2024 16:20:41 +0000 Subject: [PATCH 06/10] removed comment --- src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx index 833caf7e17a..8d82913f8c8 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx @@ -498,7 +498,6 @@ describe('PrimeUIShipmentCreateForm', () => { ['BOAT_HAUL_AWAY', 'BOAT_TOW_AWAY', 'MOBILE_HOME'], 'when creating a %s clears 2nd/3rd address fields when secondary/tertiary checkbox is unchecked', async (shipmentType) => { - // isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(false)); // Allow for testing of boats and mobile homes isBooleanFlagEnabled.mockResolvedValue(true); const shipmentTypeInput = await screen.findByLabelText('Shipment type'); From ad255d99ef504a7db5979c4220f5e0c9d4f28cbe Mon Sep 17 00:00:00 2001 From: loganwc Date: Thu, 26 Dec 2024 16:46:19 +0000 Subject: [PATCH 07/10] do the create tests for mobile home and boats --- .../Shipment/PrimeUIShipmentCreate.test.jsx | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index 7d3d732c89c..0198675ae53 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -173,51 +173,54 @@ describe('Create PPM', () => { }); describe('Create Mobile Home', () => { - it('test with 2nd and 3rd addresses', async () => { - createPrimeMTOShipmentV3.mockReturnValue({}); + it.each(['MOBILE_HOME', 'BOAT_TOW_AWAY', 'BOAT_HAUL_AWAY'])( + 'test with 2nd and 3rd addresses', + async (shipmentType) => { + createPrimeMTOShipmentV3.mockReturnValue({}); - render(mockedComponent); + render(mockedComponent); - waitFor(async () => { - await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'MOBILE_HOME'); + waitFor(async () => { + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), shipmentType); - // Start controlled test case to verify everything is working. - let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup - await userEvent.type(input, '123 Street'); + // Start controlled test case to verify everything is working. + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Street'); - const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); - expect(secondAddressToggle).toBeInTheDocument(); - await userEvent.click(secondAddressToggle); + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); - input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 2'); + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 2'); - const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); - expect(thirdAddressToggle).toBeInTheDocument(); - await userEvent.click(thirdAddressToggle); + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); - input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 3'); + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 3'); - input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter something - await userEvent.type(input, '123 Street'); + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 Street'); - const saveButton = await screen.getByRole('button', { name: 'Save' }); + const saveButton = await screen.getByRole('button', { name: 'Save' }); - expect(saveButton).not.toBeDisabled(); - await userEvent.click(saveButton); + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); - await waitFor(() => { - expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + await waitFor(() => { + expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + }); }); - }); - }); + }, + ); }); From 67500e13417d3e5601159ff12675d6c4dd791e44 Mon Sep 17 00:00:00 2001 From: loganwc Date: Thu, 26 Dec 2024 20:34:07 +0000 Subject: [PATCH 08/10] moved ff check out of form --- .../Shipment/PrimeUIShipmentCreate.jsx | 18 +- .../Shipment/PrimeUIShipmentCreate.test.jsx | 245 ++++++++++++++++-- .../Shipment/PrimeUIShipmentCreateForm.jsx | 18 +- .../PrimeUIShipmentCreateForm.test.jsx | 74 +----- 4 files changed, 247 insertions(+), 108 deletions(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx index c265b67e98c..9dae219dfbc 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Formik } from 'formik'; import * as Yup from 'yup'; import { useNavigate, useParams, generatePath } from 'react-router-dom'; @@ -21,13 +21,23 @@ import { setFlashMessage as setFlashMessageAction } from 'store/flash/actions'; import { requiredAddressSchema, partialRequiredAddressSchema } from 'utils/validation'; import PrimeUIShipmentCreateForm from 'pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm'; import { OptionalAddressSchema } from 'components/Customer/MtoShipmentForm/validationSchemas'; -import { SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants'; +import { FEATURE_FLAG_KEYS, SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants'; +import { isBooleanFlagEnabled } from 'utils/featureFlags'; const PrimeUIShipmentCreate = ({ setFlashMessage }) => { const [errorMessage, setErrorMessage] = useState(); const { moveCodeOrID } = useParams(); const navigate = useNavigate(); - + const [enableBoat, setEnableBoat] = useState(false); + const [enableMobileHome, setEnableMobileHome] = useState(false); + + useEffect(() => { + const fetchData = async () => { + setEnableBoat(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.BOAT)); + setEnableMobileHome(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.MOBILE_HOME)); + }; + fetchData(); + }, []); const handleClose = () => { navigate(generatePath(primeSimulatorRoutes.VIEW_MOVE_PATH, { moveCodeOrID })); }; @@ -676,7 +686,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { {({ isValid, isSubmitting, handleSubmit }) => { return (
- +
({ jest.mock('utils/featureFlags', () => ({ ...jest.requireActual('utils/featureFlags'), - isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(false)), + isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(true)), })); const moveDetailsURL = generatePath(primeSimulatorRoutes.VIEW_MOVE_PATH, { moveCodeOrID: moveId }); +const initialValues = { + shipmentType: '', + + // PPM + counselorRemarks: '', + ppmShipment: { + expectedDepartureDate: '', + sitExpected: false, + sitLocation: '', + sitEstimatedWeight: '', + sitEstimatedEntryDate: '', + sitEstimatedDepartureDate: '', + estimatedWeight: '', + hasProGear: false, + proGearWeight: '', + spouseProGearWeight: '', + pickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + destinationAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + hasSecondaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasTertiaryDestinationAddress: 'false', + }, + + // Boat Shipment + boatShipment: { + make: 'make', + model: 'model', + year: 1999, + hasTrailer: true, + isRoadworthy: true, + lengthInFeet: 16, + lengthInInches: 0, + widthInFeet: 1, + widthInInches: 1, + heightInFeet: 1, + heightInInches: 1, + }, + + // Mobile Home Shipment + mobileHomeShipment: { + make: 'mobile make', + model: 'mobile model', + year: 1999, + lengthInFeet: 16, + lengthInInches: 0, + widthInFeet: 1, + widthInInches: 1, + heightInFeet: 1, + heightInInches: 1, + }, + + // Other shipment types + requestedPickupDate: '', + estimatedWeight: '', + pickupAddress: {}, + destinationAddress: {}, + secondaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + secondaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryDeliveryAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + tertiaryPickupAddress: { + city: '', + postalCode: '', + state: '', + streetAddress1: '', + }, + hasSecondaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasTertiaryDestinationAddress: 'false', + diversion: '', + divertedFromShipmentId: '', +}; + const mockedComponent = ( - + + + + + ); @@ -145,7 +274,7 @@ describe('Create PPM', () => { await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'PPM'); // Start controlled test case to verify everything is working. - let input = await document.querySelector('input[name="ppmShipment.pickupAddress.streetAddress1"]'); + let input = await document.querySelector('input[name=ppmShipment.pickupAddress.streetAddress1]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup await userEvent.type(input, '123 Street'); @@ -159,7 +288,7 @@ describe('Create PPM', () => { await userEvent.type(input, '123 Street'); // Verify destination address street 1 is OPTIONAL. - input = await document.querySelector('input[name="ppmShipment.destinationAddress.streetAddress1"]'); + input = await document.querySelector('input[name=ppmShipment.destinationAddress.streetAddress1]'); expect(input).toBeInTheDocument(); // enter something await userEvent.type(input, '123 Street'); @@ -174,21 +303,51 @@ describe('Create PPM', () => { describe('Create Mobile Home', () => { it.each(['MOBILE_HOME', 'BOAT_TOW_AWAY', 'BOAT_HAUL_AWAY'])( - 'test with 2nd and 3rd addresses', + 'resets secondary and tertiary addresses when flags are not true for shipment type %s', async (shipmentType) => { + isBooleanFlagEnabled.mockImplementation(() => Promise.resolve(true)); createPrimeMTOShipmentV3.mockReturnValue({}); + // Render the component render(mockedComponent); + // Wait for the component to load waitFor(async () => { + expect(screen.getByLabelText('Shipment type')).toBeInTheDocument(); + + // Select shipment type await userEvent.selectOptions(screen.getByLabelText('Shipment type'), shipmentType); - // Start controlled test case to verify everything is working. - let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + await userEvent.type(screen.getByLabelText('Requested pickup'), '01 Nov 2020'); + + // Fill in required pickup and destination addresses + let input = document.querySelector('input[name=pickupAddress.streetAddress1]'); expect(input).toBeInTheDocument(); - // enter required street 1 for pickup await userEvent.type(input, '123 Street'); + input = document.querySelector('input[name=pickupAddress.city]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Folsom'); + input = document.querySelector('input[name=pickupAddress.state]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'CA'); + input = document.querySelector('input[name=pickupAddress.postalCode]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '95630'); + + input = document.querySelector('input[name=destinationAddress.streetAddress1]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '456 Destination St'); + input = document.querySelector('input[name=destinationAddress.city]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Bevy Hills'); + input = document.querySelector('input[name=destinationAddress.state]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'CA'); + input = document.querySelector('input[name=destinationAddress.postalCode]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '90210'); + // Enable and disable secondary and tertiary toggles const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); expect(secondAddressToggle).toBeInTheDocument(); await userEvent.click(secondAddressToggle); @@ -196,7 +355,7 @@ describe('Create Mobile Home', () => { input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 2'); + await userEvent.type(input, '123 Pickup Street 2'); const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); expect(thirdAddressToggle).toBeInTheDocument(); @@ -205,20 +364,74 @@ describe('Create Mobile Home', () => { input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); expect(input).toBeInTheDocument(); // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Street 3'); + await userEvent.type(input, '123 Pickup Street 3'); - input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); + expect(disable2ndAddressToggle).toBeInTheDocument(); + await userEvent.click(disable2ndAddressToggle); + + // input boat/mobile home model info + input = document.createElement('input[label="Year"]'); expect(input).toBeInTheDocument(); - // enter something - await userEvent.type(input, '123 Street'); + await userEvent.type(input, '2023'); - const saveButton = await screen.getByRole('button', { name: 'Save' }); + input = document.createElement('input[label="Make"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'Genesis'); + + input = document.createElement('input[label="Model"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, 'G70'); + + // input boat/mobile home dimensions + input = document.createElement('input[label="Length (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Length (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Width (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Width (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Height (Feet)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + + input = document.createElement('input[label="Height (Inches)"]'); + expect(input).toBeInTheDocument(); + await userEvent.type(input, '10'); + // Submit the form + const saveButton = screen.getByRole('button', { name: 'Save' }); expect(saveButton).not.toBeDisabled(); await userEvent.click(saveButton); - await waitFor(() => { - expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + // Verify that API call resets addresses when flags are not 'true' + expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith({ + body: expect.objectContaining({ + destinationAddress: null, + diversion: null, + divertedFromShipmentId: null, + hasSecondaryDestinationAddress: false, + hasSecondaryPickupAddress: false, + hasTertiaryDestinationAddress: false, + hasTertiaryPickupAddress: false, + secondaryDestinationAddress: {}, + secondaryPickupAddress: {}, + tertiaryDestinationAddress: {}, + tertiaryPickupAddress: {}, + moveTaskOrderID: '9c7b255c-2981-4bf8-839f-61c7458e2b4d', + pickupAddress: null, + primeEstimatedWeight: null, + requestedPickupDate: null, + }), }); }); }, diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx index 3f70fb3fb53..22fd5f366df 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx @@ -1,10 +1,8 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import { Radio, FormGroup, Label, Textarea } from '@trussworks/react-uswds'; import { Field, useField, useFormikContext } from 'formik'; -import { isBooleanFlagEnabled } from '../../../utils/featureFlags'; - -import { SHIPMENT_OPTIONS, SHIPMENT_TYPES, FEATURE_FLAG_KEYS } from 'shared/constants'; +import { SHIPMENT_OPTIONS, SHIPMENT_TYPES } from 'shared/constants'; import { CheckboxField, DatePickerInput, DropdownInput } from 'components/form/fields'; import MaskedTextField from 'components/form/fields/MaskedTextField/MaskedTextField'; import styles from 'components/Office/CustomerContactInfoForm/CustomerContactInfoForm.module.scss'; @@ -17,7 +15,7 @@ import { LOCATION_TYPES } from 'types/sitStatusShape'; const sitLocationOptions = dropdownInputOptions(LOCATION_TYPES); -const PrimeUIShipmentCreateForm = () => { +const PrimeUIShipmentCreateForm = ({ enableBoat, enableMobileHome }) => { const { values } = useFormikContext(); const { shipmentType } = values; const { sitExpected, hasProGear } = values.ppmShipment; @@ -25,8 +23,6 @@ const PrimeUIShipmentCreateForm = () => { const [, , checkBoxHelperProps] = useField('diversion'); const [, , divertedFromIdHelperProps] = useField('divertedFromShipmentId'); const [isChecked, setIsChecked] = useState(false); - const [enableBoat, setEnableBoat] = useState(false); - const [enableMobileHome, setEnableMobileHome] = useState(false); const hasShipmentType = !!shipmentType; const isPPM = shipmentType === SHIPMENT_OPTIONS.PPM; @@ -80,14 +76,6 @@ const PrimeUIShipmentCreateForm = () => { return undefined; }; - useEffect(() => { - const fetchData = async () => { - setEnableBoat(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.BOAT)); - setEnableMobileHome(await isBooleanFlagEnabled(FEATURE_FLAG_KEYS.MOBILE_HOME)); - }; - fetchData(); - }, []); - let shipmentTypeOptions = Object.values(SHIPMENT_TYPES).map((value) => ({ key: value, value })); if (!enableBoat) { // Disallow the Prime from choosing Boat shipments if the feature flag is not enabled diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx index 8d82913f8c8..80ea98a6f8a 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.test.jsx @@ -181,7 +181,7 @@ function renderShipmentCreateForm(props) { jest.mock('utils/featureFlags', () => ({ ...jest.requireActual('utils/featureFlags'), - isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve()), + isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(false)), })); const mockNavigate = jest.fn(); @@ -493,76 +493,4 @@ describe('PrimeUIShipmentCreateForm', () => { // now the text input should be invisible expect(await screen.queryByTestId('divertedFromShipmentIdInput')).toBeNull(); }); - - it.each( - ['BOAT_HAUL_AWAY', 'BOAT_TOW_AWAY', 'MOBILE_HOME'], - 'when creating a %s clears 2nd/3rd address fields when secondary/tertiary checkbox is unchecked', - async (shipmentType) => { - isBooleanFlagEnabled.mockResolvedValue(true); - - const shipmentTypeInput = await screen.findByLabelText('Shipment type'); - expect(shipmentTypeInput).toBeInTheDocument(); - - // Select the boat or mobile home shipment type - await userEvent.selectOptions(shipmentTypeInput, [shipmentType]); - - // Make sure that a PPM-specific field is not visible. - expect(await screen.queryByLabelText('Expected Departure Date')).not.toBeInTheDocument(); - - // Check for usual HHG fields - expect(await screen.findByRole('heading', { name: 'Diversion', level: 2 })).toBeInTheDocument(); - expect(await screen.findByLabelText('Diversion')).not.toBeChecked(); - - // Checking to make sure the text box isn't shown prior to clicking the box - expect(screen.queryByTestId('divertedFromShipmentIdInput')).toBeNull(); - - // Check the diversion box - const diversionCheckbox = await screen.findByLabelText('Diversion'); - await userEvent.click(diversionCheckbox); - - // now the text input should be visible - expect(await screen.findByTestId('divertedFromShipmentIdInput')).toBeInTheDocument(); - - // Now check for a boat and mobile home shipment specific field - expect(await screen.findByLabelText('Length (Feet)')).toBeVisible(); - - let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup - await userEvent.type(input, '123 Pickup Street'); - - const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); - expect(secondAddressToggle).toBeInTheDocument(); - await userEvent.click(secondAddressToggle); - - input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Pickup Street 2'); - - const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); - expect(thirdAddressToggle).toBeInTheDocument(); - await userEvent.click(thirdAddressToggle); - - input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter required street 1 for pickup 2 - await userEvent.type(input, '123 Pickup Street 3'); - - const disable3rdAddressToggle = document.querySelector('[data-testid="no-tertiary-pickup"]'); - expect(disable3rdAddressToggle).toBeInTheDocument(); - await userEvent.click(disable3rdAddressToggle); - - const disable2ndAddressToggle = document.querySelector('[data-testid="no-secondary-pickup"]'); - expect(disable2ndAddressToggle).toBeInTheDocument(); - await userEvent.click(disable2ndAddressToggle); - - expect(input).not.toBeInTheDocument(); - - input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); - expect(input).toBeInTheDocument(); - // enter something - await userEvent.type(input, '123 destination Street'); - }, - ); }); From 27b76a6bfbaead45643409f1b6dd7cf73117211b Mon Sep 17 00:00:00 2001 From: loganwc Date: Fri, 27 Dec 2024 17:04:23 +0000 Subject: [PATCH 09/10] big test --- .../Shipment/PrimeUIShipmentCreate.test.jsx | 91 +++++++++++++++---- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index 3af240f1842..0c10c40d7bd 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -301,7 +301,57 @@ describe('Create PPM', () => { }); }); -describe('Create Mobile Home', () => { +describe('Create PPM Home', () => { + it('test with 2nd and 3rd addresses', async () => { + createPrimeMTOShipmentV3.mockReturnValue({}); + + render(mockedComponent); + + waitFor(async () => { + await userEvent.selectOptions(screen.getByLabelText('Shipment type'), 'PPM'); + + // Start controlled test case to verify everything is working. + let input = await document.querySelector('input[name="pickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup + await userEvent.type(input, '123 Street'); + + const secondAddressToggle = document.querySelector('[data-testid="has-secondary-pickup"]'); + expect(secondAddressToggle).toBeInTheDocument(); + await userEvent.click(secondAddressToggle); + + input = await document.querySelector('input[name="secondaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 2'); + + const thirdAddressToggle = document.querySelector('[data-testid="has-tertiary-pickup"]'); + expect(thirdAddressToggle).toBeInTheDocument(); + await userEvent.click(thirdAddressToggle); + + input = await document.querySelector('input[name="tertiaryPickupAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter required street 1 for pickup 2 + await userEvent.type(input, '123 Street 3'); + + input = await document.querySelector('input[name="destinationAddress.streetAddress1"]'); + expect(input).toBeInTheDocument(); + // enter something + await userEvent.type(input, '123 Street'); + + const saveButton = await screen.getByRole('button', { name: 'Save' }); + + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + + await waitFor(() => { + expect(mockNavigate).toHaveBeenCalledWith(moveDetailsURL); + }); + }); + }); +}); + +describe('Create Mobile Home and Boat', () => { it.each(['MOBILE_HOME', 'BOAT_TOW_AWAY', 'BOAT_HAUL_AWAY'])( 'resets secondary and tertiary addresses when flags are not true for shipment type %s', async (shipmentType) => { @@ -414,25 +464,26 @@ describe('Create Mobile Home', () => { await userEvent.click(saveButton); // Verify that API call resets addresses when flags are not 'true' - expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith({ - body: expect.objectContaining({ - destinationAddress: null, - diversion: null, - divertedFromShipmentId: null, - hasSecondaryDestinationAddress: false, - hasSecondaryPickupAddress: false, - hasTertiaryDestinationAddress: false, - hasTertiaryPickupAddress: false, - secondaryDestinationAddress: {}, - secondaryPickupAddress: {}, - tertiaryDestinationAddress: {}, - tertiaryPickupAddress: {}, - moveTaskOrderID: '9c7b255c-2981-4bf8-839f-61c7458e2b4d', - pickupAddress: null, - primeEstimatedWeight: null, - requestedPickupDate: null, - }), - }); + }); + + expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith({ + body: expect.objectContaining({ + destinationAddress: null, + diversion: null, + divertedFromShipmentId: null, + hasSecondaryDestinationAddress: false, + hasSecondaryPickupAddress: false, + hasTertiaryDestinationAddress: false, + hasTertiaryPickupAddress: false, + secondaryDestinationAddress: null, + secondaryPickupAddress: null, + tertiaryDestinationAddress: null, + tertiaryPickupAddress: null, + moveTaskOrderID: '9c7b255c-2981-4bf8-839f-61c7458e2b4d', + pickupAddress: null, + primeEstimatedWeight: null, + requestedPickupDate: null, + }), }); }, ); From d456a0ade19934b1909a15b1c7a31728c939ec65 Mon Sep 17 00:00:00 2001 From: loganwc Date: Tue, 7 Jan 2025 00:39:54 +0000 Subject: [PATCH 10/10] just redid everything because stupid test coverage --- migrations/app/migrations_manifest.txt | 2 +- .../Shipment/PrimeUIShipmentCreate.jsx | 143 +++++------------- .../Shipment/PrimeUIShipmentCreate.test.jsx | 4 +- .../Shipment/PrimeUIShipmentCreateForm.jsx | 4 +- src/shared/utils.js | 38 +++++ src/shared/utils.test.js | 55 +++++++ 6 files changed, 138 insertions(+), 108 deletions(-) diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 18c13cdaa73..a5330171a14 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -1052,9 +1052,9 @@ 20241203024453_add_ppm_max_incentive_column.up.sql 20241204155919_update_ordering_proc.up.sql 20241204210208_retroactive_update_of_ppm_max_and_estimated_incentives_prd.up.sql -20241218201833_add_PPPO_BASE_ELIZABETH.up.sql 20241217163231_update_duty_locations_bad_zips.up.sql 20241217180136_add_AK_zips_to_zip3_distances.up.sql +20241218201833_add_PPPO_BASE_ELIZABETH.up.sql 20241220171035_add_additional_AK_zips_to_zip3_distances.up.sql 20241227153723_remove_empty_string_emplid_values.up.sql 20241230190638_remove_AK_zips_from_zip3.up.sql diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx index 9dae219dfbc..c7117373da0 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.jsx @@ -15,7 +15,7 @@ import styles from 'components/Office/CustomerContactInfoForm/CustomerContactInf import { Form } from 'components/form/Form'; import formStyles from 'styles/form.module.scss'; import WizardNavigation from 'components/Customer/WizardNavigation/WizardNavigation'; -import { isEmpty, isValidWeight } from 'shared/utils'; +import { checkAddressTogglesToClearAddresses, isEmpty, isValidWeight } from 'shared/utils'; import { formatAddressForPrimeAPI, formatSwaggerDate } from 'utils/formatters'; import { setFlashMessage as setFlashMessageAction } from 'store/flash/actions'; import { requiredAddressSchema, partialRequiredAddressSchema } from 'utils/validation'; @@ -115,29 +115,8 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { hasTertiaryDestinationAddress, }, } = values; - let { - ppmShipment: { - tertiaryPickupAddress, - tertiaryDestinationAddress, - secondaryPickupAddress, - secondaryDestinationAddress, - }, - } = values; - if (hasSecondaryPickupAddress !== 'true') { - secondaryPickupAddress = {}; - tertiaryPickupAddress = {}; - } - if (hasTertiaryPickupAddress !== 'true') { - tertiaryPickupAddress = {}; - } - if (hasSecondaryDestinationAddress !== 'true') { - secondaryDestinationAddress = {}; - tertiaryDestinationAddress = {}; - } - if (hasTertiaryDestinationAddress !== 'true') { - tertiaryDestinationAddress = {}; - } + const updatedValues = checkAddressTogglesToClearAddresses(values); body = { moveTaskOrderID: moveCodeOrID, @@ -146,19 +125,19 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { ppmShipment: { expectedDepartureDate: expectedDepartureDate ? formatSwaggerDate(expectedDepartureDate) : null, pickupAddress: isEmpty(pickupAddress) ? null : formatAddressForPrimeAPI(pickupAddress), - secondaryPickupAddress: isEmpty(secondaryPickupAddress) - ? null - : formatAddressForPrimeAPI(secondaryPickupAddress), destinationAddress: isEmpty(destinationAddress) ? null : formatAddressForPrimeAPI(destinationAddress), - secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress) + ? null + : formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress) ? null - : formatAddressForPrimeAPI(secondaryDestinationAddress), - tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) + : formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress) ? null - : formatAddressForPrimeAPI(tertiaryPickupAddress), - tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress) ? null - : formatAddressForPrimeAPI(tertiaryDestinationAddress), + : formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress), sitExpected, ...(sitExpected && { sitLocation: sitLocation || null, @@ -206,22 +185,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { }, } = values; - let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } = - values; - if (hasSecondaryPickupAddress !== 'true') { - secondaryPickupAddress = {}; - tertiaryPickupAddress = {}; - } - if (hasTertiaryPickupAddress !== 'true') { - tertiaryPickupAddress = {}; - } - if (hasSecondaryDestinationAddress !== 'true') { - secondaryDestinationAddress = {}; - tertiaryDestinationAddress = {}; - } - if (hasTertiaryDestinationAddress !== 'true') { - tertiaryDestinationAddress = {}; - } + const updatedValues = checkAddressTogglesToClearAddresses(values); // Sum the feet and inches fields into only inches for backend/db const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10); @@ -254,16 +218,18 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true', hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true', hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true', - secondaryPickupAddress: isEmpty(secondaryPickupAddress) + secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress) ? null - : formatAddressForPrimeAPI(secondaryPickupAddress), - secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress) ? null - : formatAddressForPrimeAPI(secondaryDestinationAddress), - tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress), - tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress) ? null - : formatAddressForPrimeAPI(tertiaryDestinationAddress), + : formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress) + ? null + : formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress), }; } else if (isMobileHome) { const { @@ -291,22 +257,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { }, } = values; - let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } = - values; - if (hasSecondaryPickupAddress !== 'true') { - secondaryPickupAddress = {}; - tertiaryPickupAddress = {}; - } - if (hasTertiaryPickupAddress !== 'true') { - tertiaryPickupAddress = {}; - } - if (hasSecondaryDestinationAddress !== 'true') { - secondaryDestinationAddress = {}; - tertiaryDestinationAddress = {}; - } - if (hasTertiaryDestinationAddress !== 'true') { - tertiaryDestinationAddress = {}; - } + const updatedValues = checkAddressTogglesToClearAddresses(values); // Sum the feet and inches fields into only inches for backend/db const totalLengthInInches = parseInt(lengthInFeet, 10) * 12 + parseInt(lengthInInches, 10); @@ -335,16 +286,18 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true', hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true', hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true', - secondaryPickupAddress: isEmpty(secondaryPickupAddress) + secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress) + ? null + : formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress) ? null - : formatAddressForPrimeAPI(secondaryPickupAddress), - secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress) ? null - : formatAddressForPrimeAPI(secondaryDestinationAddress), - tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress), - tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress) ? null - : formatAddressForPrimeAPI(tertiaryDestinationAddress), + : formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress), }; } else { const { @@ -360,23 +313,7 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { hasTertiaryDestinationAddress, } = values; - let { tertiaryPickupAddress, tertiaryDestinationAddress, secondaryPickupAddress, secondaryDestinationAddress } = - values; - - if (hasSecondaryPickupAddress !== 'true') { - secondaryPickupAddress = {}; - tertiaryPickupAddress = {}; - } - if (hasTertiaryPickupAddress !== 'true') { - tertiaryPickupAddress = {}; - } - if (hasSecondaryDestinationAddress !== 'true') { - secondaryDestinationAddress = {}; - tertiaryDestinationAddress = {}; - } - if (hasTertiaryDestinationAddress !== 'true') { - tertiaryDestinationAddress = {}; - } + const updatedValues = checkAddressTogglesToClearAddresses(values); body = { moveTaskOrderID: moveCodeOrID, @@ -391,16 +328,18 @@ const PrimeUIShipmentCreate = ({ setFlashMessage }) => { hasSecondaryDestinationAddress: hasSecondaryDestinationAddress === 'true', hasTertiaryPickupAddress: hasTertiaryPickupAddress === 'true', hasTertiaryDestinationAddress: hasTertiaryDestinationAddress === 'true', - secondaryPickupAddress: isEmpty(secondaryPickupAddress) + secondaryPickupAddress: isEmpty(updatedValues.secondaryPickupAddress) + ? null + : formatAddressForPrimeAPI(updatedValues.secondaryPickupAddress), + secondaryDestinationAddress: isEmpty(updatedValues.secondaryDestinationAddress) ? null - : formatAddressForPrimeAPI(secondaryPickupAddress), - secondaryDestinationAddress: isEmpty(secondaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.secondaryDestinationAddress), + tertiaryPickupAddress: isEmpty(updatedValues.tertiaryPickupAddress) ? null - : formatAddressForPrimeAPI(secondaryDestinationAddress), - tertiaryPickupAddress: isEmpty(tertiaryPickupAddress) ? null : formatAddressForPrimeAPI(tertiaryPickupAddress), - tertiaryDestinationAddress: isEmpty(tertiaryDestinationAddress) + : formatAddressForPrimeAPI(updatedValues.tertiaryPickupAddress), + tertiaryDestinationAddress: isEmpty(updatedValues.tertiaryDestinationAddress) ? null - : formatAddressForPrimeAPI(tertiaryDestinationAddress), + : formatAddressForPrimeAPI(updatedValues.tertiaryDestinationAddress), }; } diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx index 0c10c40d7bd..370372ffe9c 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreate.test.jsx @@ -32,7 +32,7 @@ jest.mock('services/primeApi', () => ({ jest.mock('utils/featureFlags', () => ({ ...jest.requireActual('utils/featureFlags'), - isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(true)), + isBooleanFlagEnabled: jest.fn().mockImplementation(() => Promise.resolve(false)), })); const moveDetailsURL = generatePath(primeSimulatorRoutes.VIEW_MOVE_PATH, { moveCodeOrID: moveId }); @@ -462,8 +462,6 @@ describe('Create Mobile Home and Boat', () => { const saveButton = screen.getByRole('button', { name: 'Save' }); expect(saveButton).not.toBeDisabled(); await userEvent.click(saveButton); - - // Verify that API call resets addresses when flags are not 'true' }); expect(createPrimeMTOShipmentV3).toHaveBeenCalledWith({ diff --git a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx index 22fd5f366df..ad0215141e2 100644 --- a/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx +++ b/src/pages/PrimeUI/Shipment/PrimeUIShipmentCreateForm.jsx @@ -408,7 +408,7 @@ const PrimeUIShipmentCreateForm = ({ enableBoat, enableMobileHome }) => { name="hasSecondaryPickupAddress" value="false" title="No, there is not a second pickup address" - checked={hasSecondaryPickupAddress !== 'true'} + checked={hasSecondaryPickupAddress !== 'true' && hasTertiaryPickupAddress !== 'true'} />
@@ -491,7 +491,7 @@ const PrimeUIShipmentCreateForm = ({ enableBoat, enableMobileHome }) => { name="hasSecondaryDestinationAddress" value="false" title="No, there is not a second delivery address" - checked={hasSecondaryDestinationAddress !== 'true'} + checked={hasSecondaryDestinationAddress !== 'true' && hasTertiaryDestinationAddress !== 'true'} /> diff --git a/src/shared/utils.js b/src/shared/utils.js index ac6baa1307b..12ccf91c7a8 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -171,3 +171,41 @@ export function isEmpty(obj) { export function isNullUndefinedOrWhitespace(value) { return value == null || value === undefined || value.trim() === ''; } + +export function checkAddressTogglesToClearAddresses(body) { + let values = body; + + if (values.shipmentType === 'PPM') { + if (values.ppmShipment.hasSecondaryPickupAddress !== 'true') { + values.ppmShipment.secondaryPickupAddress = {}; + values.ppmShipment.tertiaryPickupAddress = {}; + } + if (values.ppmShipment.hasTertiaryPickupAddress !== 'true') { + values.ppmShipment.tertiaryPickupAddress = {}; + } + if (values.ppmShipment.hasSecondaryDestinationAddress !== 'true') { + values.ppmShipment.secondaryDestinationAddress = {}; + values.ppmShipment.tertiaryDestinationAddress = {}; + } + if (values.ppmShipment.hasTertiaryDestinationAddress !== 'true') { + values.ppmShipment.tertiaryDestinationAddress = {}; + } + } else { + if (values.hasSecondaryPickupAddress !== 'true') { + values.secondaryPickupAddress = {}; + values.tertiaryPickupAddress = {}; + } + if (values.hasTertiaryPickupAddress !== 'true') { + values.tertiaryPickupAddress = {}; + } + if (values.hasSecondaryDestinationAddress !== 'true') { + values.secondaryDestinationAddress = {}; + values.tertiaryDestinationAddress = {}; + } + if (values.hasTertiaryDestinationAddress !== 'true') { + values.tertiaryDestinationAddress = {}; + } + } + + return values; +} diff --git a/src/shared/utils.test.js b/src/shared/utils.test.js index eb5ea3e0160..dfc7cfcd956 100644 --- a/src/shared/utils.test.js +++ b/src/shared/utils.test.js @@ -86,4 +86,59 @@ describe('utils', () => { }); }); }); + + it('check if 2nd and 3rd addresses should be cleared from prime shipment create payload', () => { + const ppmValues = { + shipmentType: 'PPM', + ppmShipment: { + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: '', + tertiaryPickupAddress: '', + secondaryDestinationAddress: '', + tertiaryDestinationAddress: '', + }, + }; + const hhgValues = { + shipmentType: 'HHG', + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: '', + tertiaryPickupAddress: '', + secondaryDestinationAddress: '', + tertiaryDestinationAddress: '', + }; + + const updatedPPMValues = utils.checkAddressTogglesToClearAddresses(ppmValues); + expect(updatedPPMValues).toEqual({ + shipmentType: 'PPM', + ppmShipment: { + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: {}, + tertiaryPickupAddress: {}, + secondaryDestinationAddress: {}, + tertiaryDestinationAddress: {}, + }, + }); + + const updatedHHGValues = utils.checkAddressTogglesToClearAddresses(hhgValues); + expect(updatedHHGValues).toEqual({ + shipmentType: 'HHG', + hasSecondaryPickupAddress: 'false', + hasTertiaryPickupAddress: 'false', + hasSecondaryDestinationAddress: 'false', + hasTertiaryDestinationAddress: 'false', + secondaryPickupAddress: {}, + tertiaryPickupAddress: {}, + secondaryDestinationAddress: {}, + tertiaryDestinationAddress: {}, + }); + }); });