From 9020f534f66bf083844763342868a5455dd4d02a Mon Sep 17 00:00:00 2001 From: John Woolschlager Date: Fri, 20 Dec 2024 20:45:12 -0500 Subject: [PATCH] WIP error state for api failure --- .../ChooseDateAndTime.jsx | 19 +++---- .../ChooseDateAndTime.unit.spec.js | 3 +- .../referral-appointments/ConfirmReferral.jsx | 6 ++- .../ReferralsAndRequests.jsx | 5 +- .../ScheduleReferral.jsx | 6 ++- .../components/DateAndTimeContent.jsx | 3 -- .../DateAndTimeContent.unit.spec.js | 2 - .../components/ErrorAlert.jsx | 14 +++++ .../components/ReferralLayout.jsx | 32 +++++++++-- .../components/ReferralLayout.unit.spec.js | 54 +++++++++++++++++++ .../vaos/referral-appointments/index.jsx | 12 ++--- src/applications/vaos/services/mocks/index.js | 3 ++ .../vaos/services/referral/index.js | 18 +++---- 13 files changed, 124 insertions(+), 53 deletions(-) create mode 100644 src/applications/vaos/referral-appointments/components/ErrorAlert.jsx create mode 100644 src/applications/vaos/referral-appointments/components/ReferralLayout.unit.spec.js diff --git a/src/applications/vaos/referral-appointments/ChooseDateAndTime.jsx b/src/applications/vaos/referral-appointments/ChooseDateAndTime.jsx index d2b23dd9b43e..24b172a4758b 100644 --- a/src/applications/vaos/referral-appointments/ChooseDateAndTime.jsx +++ b/src/applications/vaos/referral-appointments/ChooseDateAndTime.jsx @@ -51,7 +51,7 @@ export const ChooseDateAndTime = props => { ) { setLoading(false); setFailed(true); - scrollAndFocus('h2'); + scrollAndFocus('h1'); } }, [currentReferral.providerId, dispatch, providerFetchStatus, futureStatus], @@ -71,19 +71,12 @@ export const ChooseDateAndTime = props => { ); } - if (failed) { - return ( - -

We’re sorry. We’ve run into a problem

-

- We’re having trouble getting your upcoming appointments. Please try - again later. -

-
- ); - } return ( - + { sandbox.restore(); }); it('should fetch provider or appointments from store if it exists and not call API', async () => { - const screen = renderWithStoreAndRouter( + renderWithStoreAndRouter( , @@ -149,7 +149,6 @@ describe('VAOS ChoseDateAndTime component', () => { store: createTestStore(initialFullState), }, ); - expect(await screen.getByTestId('pick-heading')).to.exist; sandbox.assert.notCalled(getProviderByIdModule.getProviderById); sandbox.assert.notCalled(fetchAppointmentsModule.fetchAppointments); }); diff --git a/src/applications/vaos/referral-appointments/ConfirmReferral.jsx b/src/applications/vaos/referral-appointments/ConfirmReferral.jsx index b2fdcb841267..1f862894d675 100644 --- a/src/applications/vaos/referral-appointments/ConfirmReferral.jsx +++ b/src/applications/vaos/referral-appointments/ConfirmReferral.jsx @@ -6,8 +6,10 @@ import ReferralLayout from './components/ReferralLayout'; export default function ConfirmReferral(props) { const { currentReferral } = props; return ( - -

Confirm Referral for {currentReferral.CategoryOfCare}

+

{currentReferral.UUID}

- -

Referrals and requests

+

Find your requested appointments and community care referrals.

Community care referrals

diff --git a/src/applications/vaos/referral-appointments/ScheduleReferral.jsx b/src/applications/vaos/referral-appointments/ScheduleReferral.jsx index 45568b3230c7..0ea785402858 100644 --- a/src/applications/vaos/referral-appointments/ScheduleReferral.jsx +++ b/src/applications/vaos/referral-appointments/ScheduleReferral.jsx @@ -26,9 +26,11 @@ export default function ScheduleReferral(props) { ? '1 appointment' : `${currentReferral.numberOfAppointments} appointments`; return ( - +

-

Referral for {currentReferral.CategoryOfCare}

{`Your referring VA facility approved you for ${appointmentCountString} with a community care provider. You can now schedule your appointment with a community care provider.`}

diff --git a/src/applications/vaos/referral-appointments/components/DateAndTimeContent.jsx b/src/applications/vaos/referral-appointments/components/DateAndTimeContent.jsx index bb274634c02f..b2cbbf480946 100644 --- a/src/applications/vaos/referral-appointments/components/DateAndTimeContent.jsx +++ b/src/applications/vaos/referral-appointments/components/DateAndTimeContent.jsx @@ -98,9 +98,6 @@ export const DateAndTimeContent = props => { return ( <>
-

- Schedule an appointment with your provider -

You or your referring VA facility selected to schedule an appointment online with this provider: diff --git a/src/applications/vaos/referral-appointments/components/DateAndTimeContent.unit.spec.js b/src/applications/vaos/referral-appointments/components/DateAndTimeContent.unit.spec.js index 7aaa1ae1658a..2d67215a2535 100644 --- a/src/applications/vaos/referral-appointments/components/DateAndTimeContent.unit.spec.js +++ b/src/applications/vaos/referral-appointments/components/DateAndTimeContent.unit.spec.js @@ -65,8 +65,6 @@ describe('VAOS Component: DateAndTimeContent', () => { initialState, }, ); - - expect(screen.getByTestId('pick-heading')).to.exist; expect(screen.getByTestId('cal-widget')).to.exist; }); it('should show error if no date selected', async () => { diff --git a/src/applications/vaos/referral-appointments/components/ErrorAlert.jsx b/src/applications/vaos/referral-appointments/components/ErrorAlert.jsx new file mode 100644 index 000000000000..df3bfdcaf9fe --- /dev/null +++ b/src/applications/vaos/referral-appointments/components/ErrorAlert.jsx @@ -0,0 +1,14 @@ +import React from 'react'; + +const ErrorAlert = () => { + return ( + +

We’re sorry. We’ve run into a problem.

+

+ Something went wrong on our end. Please refresh the page and try again. +

+ + ); +}; + +export default ErrorAlert; diff --git a/src/applications/vaos/referral-appointments/components/ReferralLayout.jsx b/src/applications/vaos/referral-appointments/components/ReferralLayout.jsx index a26d35651d26..145a3a314300 100644 --- a/src/applications/vaos/referral-appointments/components/ReferralLayout.jsx +++ b/src/applications/vaos/referral-appointments/components/ReferralLayout.jsx @@ -11,6 +11,7 @@ import ErrorBoundary from '../../components/ErrorBoundary'; import WarningNotification from '../../components/WarningNotification'; import { selectCurrentPage } from '../redux/selectors'; import { routeToPreviousReferralPage } from '../flow'; +import ErrorAlert from './ErrorAlert'; function BreadCrumbNav() { const history = useHistory(); @@ -41,8 +42,20 @@ function BreadCrumbNav() { ); } -export default function ReferralLayout({ children, hasEyebrow }) { +export default function ReferralLayout({ + children, + hasEyebrow, + apiFailure, + heading, +}) { const location = useLocation(); + let headingTestId = null; + if (heading) { + headingTestId = `${heading + .replace(/\s+/g, '-') + .toLowerCase() + .replace(/[^a-z0-9-]/g, '')}-heading`; + } return ( <> @@ -62,11 +75,18 @@ export default function ReferralLayout({ children, hasEyebrow }) {
{hasEyebrow && ( - - New Appointment - + <> + + New Appointment + + {heading &&

{heading}

} + + )} + {apiFailure ? ( + + ) : ( + {children} )} - {children}
@@ -76,6 +96,8 @@ export default function ReferralLayout({ children, hasEyebrow }) { } ReferralLayout.propTypes = { + apiFailure: PropTypes.bool, children: PropTypes.node, hasEyebrow: PropTypes.bool, + heading: PropTypes.string, }; diff --git a/src/applications/vaos/referral-appointments/components/ReferralLayout.unit.spec.js b/src/applications/vaos/referral-appointments/components/ReferralLayout.unit.spec.js new file mode 100644 index 000000000000..1d3581aa1298 --- /dev/null +++ b/src/applications/vaos/referral-appointments/components/ReferralLayout.unit.spec.js @@ -0,0 +1,54 @@ +import React from 'react'; +import { expect } from 'chai'; +import ReferralLayout from './ReferralLayout'; +import { + renderWithStoreAndRouter, + createTestStore, +} from '../../tests/mocks/setup'; + +describe('VAOS Component: ReferralLayout', () => { + const initialFullState = { + featureToggles: { + vaOnlineSchedulingCCDirectScheduling: true, + }, + }; + it('should render the layout with the correct header and children', () => { + const screen = renderWithStoreAndRouter( + +
I'm a child
+
, + { + store: createTestStore(initialFullState), + }, + ); + + expect(screen.getByTestId('child')).to.exist; + expect(screen.getByText('A tribute to the best heading in the world')).to + .exist; + expect(screen.getByText('New Appointment')).to.exist; + }); + it('should render the error with the correct header and children', () => { + const screen = renderWithStoreAndRouter( + +
I'm a child
+
, + { + store: createTestStore(initialFullState), + }, + ); + + expect(screen.getByTestId('error')).to.exist; + expect(screen.queryByTestId('child')).to.not.exist; + expect(screen.getByText('A tribute to the best heading in the world')).to + .exist; + expect(screen.getByText('New Appointment')).to.exist; + }); +}); diff --git a/src/applications/vaos/referral-appointments/index.jsx b/src/applications/vaos/referral-appointments/index.jsx index 67acfcc077f6..eed2930dac98 100644 --- a/src/applications/vaos/referral-appointments/index.jsx +++ b/src/applications/vaos/referral-appointments/index.jsx @@ -7,7 +7,6 @@ import { useLocation, } from 'react-router-dom'; import { useSelector } from 'react-redux'; -import { VaAlert } from '@department-of-veterans-affairs/component-library/dist/react-bindings'; import ScheduleReferral from './ScheduleReferral'; import ReviewAndConfirm from './ReviewAndConfirm'; import ConfirmReferral from './ConfirmReferral'; @@ -18,6 +17,7 @@ import { useGetReferralById } from './hooks/useGetReferralById'; import { FETCH_STATUS } from '../utils/constants'; import FormLayout from '../new-appointment/components/FormLayout'; import { scrollAndFocus } from '../utils/scrollAndFocus'; +import ErrorAlert from './components/ErrorAlert'; export default function ReferralAppointments() { useManualScrollRestoration(); @@ -66,15 +66,9 @@ export default function ReferralAppointments() { } if (referralFetchStatus === FETCH_STATUS.failed) { - return ( - -

- There was an error trying to get your referral data -

-

Please try again later, or contact your VA facility for help.

-
- ); + return ; } + return ( <> diff --git a/src/applications/vaos/services/mocks/index.js b/src/applications/vaos/services/mocks/index.js index 0659251ed1b8..b151d87f586c 100644 --- a/src/applications/vaos/services/mocks/index.js +++ b/src/applications/vaos/services/mocks/index.js @@ -496,6 +496,9 @@ const responses = { }); }, 'GET /vaos/v2/epsApi/referralDetails/:referralId': (req, res) => { + if (req.params.referralId === 'error') { + return res.status(500).json({ error: true }); + } const referrals = referralUtils.createReferrals(3, '2024-12-02'); const singleReferral = referrals.find( referral => referral?.UUID === req.params.referralId, diff --git a/src/applications/vaos/services/referral/index.js b/src/applications/vaos/services/referral/index.js index 66a04a44faa2..a772219d2ca7 100644 --- a/src/applications/vaos/services/referral/index.js +++ b/src/applications/vaos/services/referral/index.js @@ -9,17 +9,13 @@ export async function getPatientReferrals() { } export async function getPatientReferralById(referralId) { - try { - const response = await apiRequestWithUrl( - `/vaos/v2/epsApi/referralDetails/${referralId}`, - { - method: 'GET', - }, - ); - return response.data; - } catch (error) { - return null; - } + const response = await apiRequestWithUrl( + `/vaos/v2/epsApi/referralDetails/${referralId}`, + { + method: 'GET', + }, + ); + return response.data; } export async function getProviderById(providerId) {