Skip to content

Commit

Permalink
Merge branch 'main' into B-21473-MAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstonebraker authored Feb 24, 2025
2 parents c8cc63c + d862d48 commit ac12604
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 139 deletions.
109 changes: 69 additions & 40 deletions src/components/Customer/MtoShipmentForm/MtoShipmentForm.jsx

Large diffs are not rendered by default.

69 changes: 48 additions & 21 deletions src/components/Customer/MtoShipmentForm/MtoShipmentForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,46 @@ describe('MtoShipmentForm component', () => {
await userEvent.click(screen.getByTitle('Yes, I have a second pickup address'));

const streetAddress1 = await screen.findAllByLabelText(/Address 1/);
expect(streetAddress1[1]).toHaveAttribute('name', 'secondaryPickup.address.streetAddress1');
expect(streetAddress1.length).toBe(1);
expect(streetAddress1[0]).toHaveAttribute('name', 'pickup.address.streetAddress1');

const streetAddress2 = await screen.findAllByLabelText(/Address 2/);
expect(streetAddress2[1]).toHaveAttribute('name', 'secondaryPickup.address.streetAddress2');
expect(streetAddress2[0]).toHaveAttribute('name', 'pickup.address.streetAddress2');

const city = screen.getAllByTestId('City');
expect(city[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.city');
expect(city[0]).toHaveAttribute('aria-label', 'pickup.address.city');

const state = screen.getAllByTestId(/State/);
expect(state[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.state');
expect(state[0]).toHaveAttribute('aria-label', 'pickup.address.state');

const zip = screen.getAllByTestId(/ZIP/);
expect(zip[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.postalCode');
expect(zip[0]).toHaveAttribute('aria-label', 'pickup.address.postalCode');
});

it('renders a second address fieldset when the user has a pickup address', async () => {
renderMtoShipmentForm();

await userEvent.click(screen.getByTitle('Yes, I know my delivery address'));

const streetAddress1 = await screen.findAllByLabelText(/Address 1/);
expect(streetAddress1[0]).toHaveAttribute('name', 'pickup.address.streetAddress1');
expect(streetAddress1[1]).toHaveAttribute('name', 'delivery.address.streetAddress1');

const streetAddress2 = await screen.findAllByLabelText(/Address 2/);
expect(streetAddress2[0]).toHaveAttribute('name', 'pickup.address.streetAddress2');
expect(streetAddress2[1]).toHaveAttribute('name', 'delivery.address.streetAddress2');

const city = screen.getAllByTestId('City');
expect(city[0]).toHaveAttribute('aria-label', 'pickup.address.city');
expect(city[1]).toHaveAttribute('aria-label', 'delivery.address.city');

const state = screen.getAllByTestId('State');
expect(state[0]).toHaveAttribute('aria-label', 'pickup.address.state');
expect(state[1]).toHaveAttribute('aria-label', 'delivery.address.state');

const zip = screen.getAllByTestId('ZIP');
expect(zip[0]).toHaveAttribute('aria-label', 'pickup.address.postalCode');
expect(zip[1]).toHaveAttribute('aria-label', 'delivery.address.postalCode');
});

it('renders a second address fieldset when the user has a delivery address', async () => {
Expand Down Expand Up @@ -388,24 +415,24 @@ describe('MtoShipmentForm component', () => {
await userEvent.click(screen.getByTitle('Yes, I have a second delivery address'));

const streetAddress1 = await screen.findAllByLabelText(/Address 1/);
expect(streetAddress1.length).toBe(3);
expect(streetAddress1[2]).toHaveAttribute('name', 'secondaryDelivery.address.streetAddress1');
expect(streetAddress1[0]).toHaveAttribute('name', 'pickup.address.streetAddress1');
expect(streetAddress1[1]).toHaveAttribute('name', 'delivery.address.streetAddress1');

const streetAddress2 = await screen.findAllByLabelText(/Address 2/);
expect(streetAddress2.length).toBe(3);
expect(streetAddress2[2]).toHaveAttribute('name', 'secondaryDelivery.address.streetAddress2');
expect(streetAddress2[0]).toHaveAttribute('name', 'pickup.address.streetAddress2');
expect(streetAddress2[1]).toHaveAttribute('name', 'delivery.address.streetAddress2');

const city = screen.getAllByTestId('City');
expect(city.length).toBe(3);
expect(city[2]).toHaveAttribute('aria-label', 'secondaryDelivery.address.city');
expect(city[0]).toHaveAttribute('aria-label', 'pickup.address.city');
expect(city[1]).toHaveAttribute('aria-label', 'delivery.address.city');

const state = await screen.getAllByTestId(/State/);
expect(state.length).toBe(3);
expect(state[2]).toHaveAttribute('aria-label', 'secondaryDelivery.address.state');
expect(state[0]).toHaveAttribute('aria-label', 'pickup.address.state');
expect(state[1]).toHaveAttribute('aria-label', 'delivery.address.state');

const zip = await screen.getAllByTestId(/ZIP/);
expect(zip.length).toBe(3);
expect(zip[2]).toHaveAttribute('aria-label', 'secondaryDelivery.address.postalCode');
expect(zip[0]).toHaveAttribute('aria-label', 'pickup.address.postalCode');
expect(zip[1]).toHaveAttribute('aria-label', 'delivery.address.postalCode');
});

it('goes back when the back button is clicked', async () => {
Expand Down Expand Up @@ -1134,25 +1161,25 @@ describe('MtoShipmentForm component', () => {
});
});

it('renders a second address fieldset when the user has a second pickup address', async () => {
it('renders a second address fieldset when the user has a pickup address', async () => {
renderUBShipmentForm();

await userEvent.click(screen.getByTitle('Yes, I have a second pickup address'));

const streetAddress1 = await screen.findAllByLabelText(/Address 1/);
expect(streetAddress1[1]).toHaveAttribute('name', 'secondaryPickup.address.streetAddress1');
expect(streetAddress1[0]).toHaveAttribute('name', 'pickup.address.streetAddress1');

const streetAddress2 = await screen.findAllByLabelText(/Address 2/);
expect(streetAddress2[1]).toHaveAttribute('name', 'secondaryPickup.address.streetAddress2');
expect(streetAddress2[0]).toHaveAttribute('name', 'pickup.address.streetAddress2');

const city = screen.getAllByTestId('City');
expect(city[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.city');
expect(city[0]).toHaveAttribute('aria-label', 'pickup.address.city');

const state = screen.getAllByTestId('State');
expect(state[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.state');
expect(state[0]).toHaveAttribute('aria-label', 'pickup.address.state');

const zip = screen.getAllByTestId('ZIP');
expect(zip[1]).toHaveAttribute('aria-label', 'secondaryPickup.address.postalCode');
expect(zip[0]).toHaveAttribute('aria-label', 'pickup.address.postalCode');
});

it('renders a second address fieldset when the user has a delivery address', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { OptionalAddressSchema } from 'components/Customer/MtoShipmentForm/valid
import { requiredAddressSchema, partialRequiredAddressSchema } from 'utils/validation';
import { isBooleanFlagEnabled } from 'utils/featureFlags';
import RequiredTag from 'components/form/RequiredTag';
import { isPreceedingAddressComplete } from 'shared/utils';

let meta = '';

Expand All @@ -45,13 +46,20 @@ let validationShape = {
secondaryDestinationAddress: Yup.object().shape({
address: OptionalAddressSchema,
}),
tertiaryPickupAddress: Yup.object().shape({
address: OptionalAddressSchema,
}),
tertiaryDestinationAddress: Yup.object().shape({
address: OptionalAddressSchema,
}),
};

const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMember, move, onBack, onSubmit }) => {
const initialValues = {
useCurrentResidence: false,
pickupAddress: {},
secondaryPickupAddress: {},
tertiaryPickupAddress: {},
hasSecondaryPickupAddress: mtoShipment?.ppmShipment?.secondaryPickupAddress ? 'true' : 'false',
hasTertiaryPickupAddress: mtoShipment?.ppmShipment?.tertiaryPickupAddress ? 'true' : 'false',
useCurrentDestinationAddress: false,
Expand All @@ -62,7 +70,6 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
sitExpected: mtoShipment?.ppmShipment?.sitExpected ? 'true' : 'false',
expectedDepartureDate: mtoShipment?.ppmShipment?.expectedDepartureDate || '',
closeoutOffice: move?.closeoutOffice || {},
tertiaryPickupAddress: {},
tertiaryDestinationAddress: {},
};

Expand Down Expand Up @@ -228,6 +235,7 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
name="hasSecondaryPickupAddress"
value="true"
checked={values.hasSecondaryPickupAddress === 'true'}
disabled={!isPreceedingAddressComplete('true', values.pickupAddress.address)}
/>
<Field
as={Radio}
Expand All @@ -237,6 +245,7 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
name="hasSecondaryPickupAddress"
value="false"
checked={values.hasSecondaryPickupAddress === 'false'}
disabled={!isPreceedingAddressComplete('true', values.pickupAddress.address)}
/>
</Fieldset>
</FormGroup>
Expand Down Expand Up @@ -276,6 +285,12 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
value="true"
title="Yes, I have a third delivery address"
checked={values.hasTertiaryPickupAddress === 'true'}
disabled={
!isPreceedingAddressComplete(
values.hasSecondaryPickupAddress,
values.secondaryPickupAddress.address,
)
}
/>
<Field
as={Radio}
Expand All @@ -286,6 +301,12 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
value="false"
title="No, I do not have a third delivery address"
checked={values.hasTertiaryPickupAddress === 'false'}
disabled={
!isPreceedingAddressComplete(
values.hasSecondaryPickupAddress,
values.secondaryPickupAddress.address,
)
}
/>
</Fieldset>
</FormGroup>
Expand Down Expand Up @@ -341,6 +362,7 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
name="hasSecondaryDestinationAddress"
value="true"
checked={values.hasSecondaryDestinationAddress === 'true'}
disabled={!isPreceedingAddressComplete('true', values.destinationAddress.address)}
/>
<Field
as={Radio}
Expand All @@ -350,6 +372,7 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
name="hasSecondaryDestinationAddress"
value="false"
checked={values.hasSecondaryDestinationAddress === 'false'}
disabled={!isPreceedingAddressComplete('true', values.destinationAddress.address)}
/>
</Fieldset>
</FormGroup>
Expand Down Expand Up @@ -390,6 +413,12 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
value="true"
title="Yes, I have a third delivery address"
checked={values.hasTertiaryDestinationAddress === 'true'}
disabled={
!isPreceedingAddressComplete(
values.hasSecondaryDestinationAddress,
values.secondaryDestinationAddress.address,
)
}
/>
<Field
as={Radio}
Expand All @@ -400,6 +429,12 @@ const DateAndLocationForm = ({ mtoShipment, destinationDutyLocation, serviceMemb
value="false"
title="No, I do not have a third delivery address"
checked={values.hasTertiaryDestinationAddress === 'false'}
disabled={
!isPreceedingAddressComplete(
values.hasSecondaryDestinationAddress,
values.secondaryDestinationAddress.address,
)
}
/>
</Fieldset>
</FormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,37 @@ describe('DateAndLocationForm component', () => {
<DateAndLocationForm {...defaultProps} />
</Provider>,
);
const hasSecondaryDestinationAddress = await screen.getAllByLabelText('Yes')[1];

await userEvent.click(hasSecondaryDestinationAddress);
await userEvent.click(screen.getByLabelText('Use my current delivery address'));

const postalCodes = screen.getAllByTestId(/ZIP/);
const address1 = screen.getAllByLabelText(/Address 1/, { exact: false });
const address2 = screen.getAllByLabelText('Address 2', { exact: false });
const address3 = screen.getAllByLabelText('Address 3', { exact: false });
const state = screen.getAllByTestId(/State/);
const city = screen.getAllByTestId(/City/);
expect(address1[1]).toHaveValue(defaultProps.destinationDutyLocation.address.streetAddress1);
expect(address2[1]).toHaveValue('');
expect(city[1]).toHaveTextContent(defaultProps.destinationDutyLocation.address.city);
expect(state[1]).toHaveTextContent(defaultProps.destinationDutyLocation.address.state);
expect(postalCodes[1]).toHaveTextContent(defaultProps.destinationDutyLocation.address.postalCode);

const hasSecondaryDestinationAddress = await screen.getAllByLabelText('Yes')[1];

await userEvent.click(hasSecondaryDestinationAddress);
const secondaryPostalCodes = screen.getAllByTestId(/ZIP/);
const secondaryAddress1 = screen.getAllByLabelText(/Address 1/, { exact: false });
const secondaryAddress2 = screen.getAllByLabelText('Address 2', { exact: false });
const secondaryAddress3 = screen.getAllByLabelText('Address 3', { exact: false });
const secondaryState = screen.getAllByTestId(/State/);
const secondaryCity = screen.getAllByTestId(/City/);

await waitFor(() => {
expect(address1[2]).toBeInstanceOf(HTMLInputElement);
expect(address2[2]).toBeInstanceOf(HTMLInputElement);
expect(address3[2]).toBeInstanceOf(HTMLInputElement);
expect(state[2]).toBeInstanceOf(HTMLLabelElement);
expect(city[2]).toBeInstanceOf(HTMLLabelElement);
expect(postalCodes[2]).toBeInstanceOf(HTMLLabelElement);
expect(secondaryAddress1[2]).toBeInstanceOf(HTMLInputElement);
expect(secondaryAddress2[2]).toBeInstanceOf(HTMLInputElement);
expect(secondaryAddress3[2]).toBeInstanceOf(HTMLInputElement);
expect(secondaryState[2]).toBeInstanceOf(HTMLLabelElement);
expect(secondaryCity[2]).toBeInstanceOf(HTMLLabelElement);
expect(secondaryPostalCodes[2]).toBeInstanceOf(HTMLLabelElement);
});
});
});
Expand Down
Loading

0 comments on commit ac12604

Please sign in to comment.