Skip to content

[HOTE-871] fix: prevent revisiting check-your-answers via browser back#308

Open
ConnorF-NHS wants to merge 7 commits intomainfrom
feature/hote-871/control-back-navigation-after-order-creation
Open

[HOTE-871] fix: prevent revisiting check-your-answers via browser back#308
ConnorF-NHS wants to merge 7 commits intomainfrom
feature/hote-871/control-back-navigation-after-order-creation

Conversation

@ConnorF-NHS
Copy link
Copy Markdown
Contributor

@ConnorF-NHS ConnorF-NHS commented Apr 1, 2026

Description

When the user clicks the browser back button, they will now be taken to the GetSelfTestKitPage instead of the CheckYourAnswersPage, preventing them from submitting another order immediately. This is a temporary fix; a proper solution will be implemented in beta.

Context

https://nhsd-jira.digital.nhs.uk/browse/HOTE-871

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

Copilot AI review requested due to automatic review settings April 1, 2026 14:33
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Lambdas Coverage Report

Lines Statements Branches Functions
Coverage: 98%
98.34% (1305/1327) 91.84% (394/429) 96.26% (206/214)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

UI Coverage Report

Lines Statements Branches Functions
Coverage: 95%
95.65% (5632/5888) 87.54% (668/763) 87.5% (203/232)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the UI journey navigation to prevent users from revisiting the “Check your answers” step after submitting an order by using the browser back button.

Changes:

  • Update the / route redirect to use navigate(..., { replace: true }) so the home entry isn’t left in browser history.
  • Detect browser “POP” navigation back to CheckYourAnswersPage after submission and clear journey/order/postcode state before redirecting to the start.
  • Add/extend Jest + React Testing Library coverage for the new redirect/reset behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
ui/src/routes/HomePage.tsx Uses history replace on redirect to reduce back-navigation to /.
ui/src/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.tsx Clears persisted journey state on browser-back revisit post-submission and redirects to restart the journey.
ui/src/tests/routes/HomePage.test.tsx Adds test asserting redirect uses { replace: true }.
ui/src/tests/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.test.tsx Adds test asserting state is cleared and redirect occurs when revisiting via browser back after submission.

Copilot AI review requested due to automatic review settings April 2, 2026 09:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 2, 2026 11:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • ui/package-lock.json: Language not supported


reset();
clearAddresses();
sessionService.clearJourneyNavigation();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling sessionService.clearJourneyNavigation() here clears sessionStorage but does not reset the in-memory JourneyNavigationProvider state, so the next NavigationContext effect can immediately re-dehydrate the old stepHistory/returnToStep back into sessionStorage and carry stale history into the next journey run. Prefer resetting navigation via the JourneyNavigationContext API (e.g., add/use a dedicated reset method that sets stepHistory to [RoutePath.GetSelfTestKitPage] and returnToStep to null) rather than directly mutating session storage from the page.

Suggested change
sessionService.clearJourneyNavigation();

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +73
reset();
clearAddresses();
sessionService.clearJourneyNavigation();
navigate(RoutePath.GetSelfTestKitPage, { replace: true });
}, [clearAddresses, hasSubmittedOrder, navigate, navigationType, reset]);
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset() clears orderReferenceNumber, so after this redirect the browser Forward history entry to the OrderSubmitted page will no longer be able to display the reference number (it will fall back to the placeholder). Consider preserving the submitted order reference until the user explicitly starts a new journey, or add a guard on OrderSubmittedPage to redirect away when the reference is missing to avoid showing an empty confirmation.

Suggested change
reset();
clearAddresses();
sessionService.clearJourneyNavigation();
navigate(RoutePath.GetSelfTestKitPage, { replace: true });
}, [clearAddresses, hasSubmittedOrder, navigate, navigationType, reset]);
clearAddresses();
sessionService.clearJourneyNavigation();
navigate(RoutePath.GetSelfTestKitPage, { replace: true });
}, [clearAddresses, hasSubmittedOrder, navigate, navigationType]);

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 2, 2026 14:24
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment on lines +140 to +149
setNavigation({
stepHistory: [step],
returnToStep: null,
});

sessionService.clearJourneyNavigation();

if (step !== currentStep || options?.replace === true) {
navigate(getPathForStep(step), { replace: options?.replace });
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetNavigation sets navigation state before calling navigate; because stepHistory is derived by appending currentStep when the last history entry differs, resetting to a different step can temporarily re-add the previous currentStep (and may briefly re-persist it to sessionStorage) before the location updates.

Consider navigating first (or adding a small “pending reset” guard) so the computed stepHistory doesn’t momentarily include the old step when you’re intentionally clearing history.

Suggested change
setNavigation({
stepHistory: [step],
returnToStep: null,
});
sessionService.clearJourneyNavigation();
if (step !== currentStep || options?.replace === true) {
navigate(getPathForStep(step), { replace: options?.replace });
}
if (step !== currentStep || options?.replace === true) {
navigate(getPathForStep(step), { replace: options?.replace });
}
setNavigation({
stepHistory: [step],
returnToStep: null,
});
sessionService.clearJourneyNavigation();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants