Skip to content

Commit 6435798

Browse files
authored
APPT-1668: Fixed multiple bugs around go back button (#1183)
# Description Aligned "No, go back" links to work same way as "Go back" buttons, navigating to previous url page, not previous screen on confirmation page. # Checklist: - [ ] My work is behind a feature toggle (if appropriate) - [ ] If my work is behind a feature toggle, I've added a full suite of tests for both the ON and OFF state - [ ] The ticket number is in the Pull Request title, with format "APPT-XXX: My Title Here" - [ ] I have ran npm tsc / lint (in the future these will be ran automatically) - [ ] My code generates no new .NET warnings (in the future these will be treated as errors) - [ ] If I've added a new Function, it is disabled in all but one of the terraform groups (e.g. http_functions) - [ ] If I've added a new Function, it has both unit and integration tests. Any request body validators have unit tests also - [ ] If I've made UI changes, I've added appropriate Playwright and Jest tests - [ ] If I've added/updated an end-point, I've added the appropriate annotations and tested the Swagger documentation reflects the change
1 parent c9cf12d commit 6435798

File tree

6 files changed

+106
-77
lines changed

6 files changed

+106
-77
lines changed

src/client/src/app/lib/components/session-modification-confirmation.test.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,31 @@ describe('EditSessionConfirmation', () => {
144144
).toBeInTheDocument();
145145
});
146146
});
147+
it('"No, go back" click resets decision and action to display previous step on a page ', async () => {
148+
const { user } = render(
149+
<SessionModificationConfirmation
150+
newlyUnsupportedBookingsCount={3}
151+
clinicalServices={mockMultipleServices}
152+
session={btoa(JSON.stringify(mockSessionSummary))}
153+
site="site-123"
154+
date="2024-06-10"
155+
mode="edit"
156+
/>,
157+
);
158+
159+
await user.click(screen.getByLabelText(/Yes, cancel the appointments/));
160+
await user.click(screen.getByRole('button', { name: 'Continue' }));
161+
await waitFor(() => {
162+
expect(
163+
screen.getByRole('button', { name: 'Cancel appointments' }),
164+
).toBeInTheDocument();
165+
});
166+
167+
const href = screen.getByText('No, go back').getAttribute('href');
168+
expect(href?.startsWith('/site/site-123/availability/edit?session=')).toBe(
169+
true,
170+
);
171+
});
147172
});
148173

149174
describe('CancelSessionConfirmation', () => {
@@ -288,19 +313,13 @@ describe('CancelSessionConfirmation', () => {
288313
screen.getByRole('button', { name: 'Cancel appointments' }),
289314
).toBeInTheDocument();
290315
});
291-
await user.click(screen.getByText('No, go back'));
292316

317+
const href = screen.getByText('No, go back').getAttribute('href');
293318
expect(
294-
screen.getByRole('button', { name: 'Continue' }),
295-
).toBeInTheDocument();
296-
expect(
297-
screen.queryByRole('button', { name: 'Cancel appointments' }),
298-
).not.toBeInTheDocument();
299-
300-
const radioYes = screen.getByLabelText(/Yes, cancel the appointments/);
301-
const radioNo = screen.getByLabelText(/No, do not cancel the appointments/);
302-
expect(radioYes).not.toBeChecked();
303-
expect(radioNo).not.toBeChecked();
319+
href?.startsWith(
320+
'/site/site-123/view-availability/week/edit-session?date=2024-06-10&session',
321+
),
322+
).toBe(true);
304323
});
305324
});
306325

src/client/src/app/lib/components/session-modification-confirmation.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,21 @@ export const SessionModificationConfirmation = ({
246246
</Button>
247247
)}
248248

249-
<Link
250-
href="#"
251-
onClick={e => {
252-
e.preventDefault();
253-
setDecision(undefined);
254-
setValue('action', undefined);
255-
}}
256-
>
257-
No, go back
258-
</Link>
249+
{mode == 'edit' && (
250+
<Link
251+
href={`/site/${site}/availability/edit?session=${session}&date=${date}`}
252+
>
253+
No, go back
254+
</Link>
255+
)}
256+
257+
{mode == 'cancel' && (
258+
<Link
259+
href={`/site/${site}/view-availability/week/edit-session?date=${date}&session=${session}`}
260+
>
261+
No, go back
262+
</Link>
263+
)}
259264
</ButtonGroup>
260265
</form>
261266
);

src/client/src/app/site/[site]/availability/cancel/confirmation/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const Page = async ({ searchParams, params }: PageProps) => {
5656
caption={site.name}
5757
originPage="edit-session"
5858
backLink={{
59-
href: `/site/${site.id}/availability/cancel?session=${session}&date=${date}`,
59+
href: `/site/${site.id}/view-availability/week/edit-session?date=${date}&session=${session}`,
6060
renderingStrategy: 'server',
6161
text: 'Go back',
6262
}}

src/client/src/app/site/[site]/availability/edit-services/confirmation/edit-services-confirmation.test.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,7 @@ jest.mock('@services/timeService', () => ({
3838
toTimeFormat: jest.fn(),
3939
}));
4040

41-
describe('EditSessionConfirmation', () => {
42-
it('No unsupported bookings, renders question to change session', () => {
43-
render(
44-
<EditServicesConfirmationPage
45-
newlyUnsupportedBookingsCount={0}
46-
clinicalServices={mockMultipleServices}
47-
session={btoa(JSON.stringify(mockSessionSummary))}
48-
removedServicesSession={btoa(JSON.stringify(mockRemovedService))}
49-
site="site-123"
50-
date="2024-06-10"
51-
/>,
52-
);
53-
54-
expect(
55-
screen.getByRole('button', { name: 'Remove service' }),
56-
).toBeInTheDocument();
57-
expect(
58-
screen.queryByRole('button', { name: 'Continue' }),
59-
).not.toBeInTheDocument();
60-
expect(
61-
screen.getByText('Are you sure you want to remove this service?'),
62-
).toBeInTheDocument();
63-
});
64-
});
65-
66-
describe('CancelSessionConfirmation', () => {
41+
describe('Edit Service Confirmation', () => {
6742
it('No unsupported bookings, renders question to remove the service', () => {
6843
render(
6944
<EditServicesConfirmationPage
@@ -160,6 +135,31 @@ describe('CancelSessionConfirmation', () => {
160135
).toBeInTheDocument();
161136
});
162137
});
138+
139+
it('"No, go back" click resets decision and action to display previous step on a page ', async () => {
140+
const { user } = render(
141+
<EditServicesConfirmationPage
142+
newlyUnsupportedBookingsCount={3}
143+
clinicalServices={mockMultipleServices}
144+
session={btoa(JSON.stringify(mockSessionSummary))}
145+
site="site-123"
146+
date="2024-06-10"
147+
/>,
148+
);
149+
150+
await user.click(screen.getByLabelText(/Yes, cancel the appointments/));
151+
await user.click(screen.getByRole('button', { name: 'Continue' }));
152+
await waitFor(() => {
153+
expect(
154+
screen.getByRole('button', { name: 'Cancel appointments' }),
155+
).toBeInTheDocument();
156+
});
157+
158+
const href = screen.getByText('No, go back').getAttribute('href');
159+
expect(
160+
href?.startsWith('/site/site-123/availability/edit-services?session='),
161+
).toBe(true);
162+
});
163163
});
164164

165165
describe('submitForm', () => {

src/client/src/app/site/[site]/availability/edit-services/confirmation/edit-services-confirmation.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React from 'react';
3+
import React, { useState } from 'react';
44
import { SessionSummaryTable } from '@components/session-summary-table';
55
import {
66
Button,
@@ -72,14 +72,17 @@ export const EditServicesConfirmationPage = ({
7272
const {
7373
handleSubmit,
7474
register,
75-
formState: { errors, isSubmitted },
76-
getValues,
75+
formState: { errors },
7776
setValue,
7877
} = useForm<FormData>({
7978
defaultValues: { action: undefined },
8079
});
80+
const [decision, setDecision] = useState<
81+
SessionModificationAction | undefined
82+
>();
8183

8284
const recordDecision: SubmitHandler<FormData> = form => {
85+
setDecision(form.action as SessionModificationAction);
8386
setValue('action', form.action);
8487
};
8588

@@ -210,9 +213,8 @@ export const EditServicesConfirmationPage = ({
210213
);
211214

212215
const renderUnsupportedDecision = () => {
213-
if (!isSubmitted) return renderRadioForm();
214-
const action = getValues('action');
215-
return renderConfirmationQuestion(action);
216+
if (!decision) return renderRadioForm();
217+
return renderConfirmationQuestion(decision);
216218
};
217219

218220
return (
@@ -226,9 +228,9 @@ export const EditServicesConfirmationPage = ({
226228

227229
{newlyUnsupportedBookingsCount > 0 ? (
228230
<>
229-
{isSubmitted && getValues('action') ? (
231+
{decision ? (
230232
<div className="margin-top-bottom">
231-
{getValues('action') === 'remove-services'
233+
{decision === 'remove-services'
232234
? newlyUnsupportedBookingsCount > 1
233235
? `You have chosen not to cancel ${newlyUnsupportedBookingsCount} bookings.`
234236
: 'You have chosen not to cancel 1 booking.'
@@ -246,22 +248,21 @@ export const EditServicesConfirmationPage = ({
246248
</div>
247249
)}
248250

249-
{newlyUnsupportedBookingsCount &&
250-
getValues('action') != 'remove-services' && (
251-
<Card
252-
title={String(newlyUnsupportedBookingsCount)}
253-
description={
254-
newlyUnsupportedBookingsCount > 1
255-
? 'Bookings may have to be cancelled'
256-
: 'Booking may have to be cancelled'
257-
}
258-
maxWidth={250}
259-
/>
260-
)}
251+
{newlyUnsupportedBookingsCount && decision != 'remove-services' && (
252+
<Card
253+
title={String(newlyUnsupportedBookingsCount)}
254+
description={
255+
newlyUnsupportedBookingsCount > 1
256+
? 'Bookings may have to be cancelled'
257+
: 'Booking may have to be cancelled'
258+
}
259+
maxWidth={250}
260+
/>
261+
)}
261262

262-
{isSubmitted && getValues('action') && (
263+
{decision && (
263264
<div className="margin-top-bottom">
264-
{getValues('action') === 'cancel-appointments'
265+
{decision === 'cancel-appointments'
265266
? 'People will be sent a text message or email confirming their appointment has been cancelled.'
266267
: ''}
267268
</div>

src/client/src/app/site/[site]/view-availability/week/edit-session/edit-session-decision.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ export const EditSessionDecision = ({
7676
sessionSummaries={[session]}
7777
clinicalServices={clinicalServices}
7878
/>
79-
<InsetText>
80-
<p>
81-
You can only reduce time, capacity or services from this screen. If
82-
you want to increase availability for this day, you must create a new
83-
session.
84-
</p>
85-
</InsetText>
79+
80+
{!cancelSessionUpliftedJourneyFlag && (
81+
<InsetText>
82+
<p>
83+
You can only reduce time, capacity or services from this screen. If
84+
you want to increase availability for this day, you must create a
85+
new session.
86+
</p>
87+
</InsetText>
88+
)}
89+
8690
<form onSubmit={handleSubmit(submitForm)}>
8791
<FormGroup
8892
legend="What do you want to do?"

0 commit comments

Comments
 (0)