Skip to content

PPHA-602: Updated backlinks to go to check-your-answers when updating responses#421

Open
stephhou wants to merge 19 commits intomainfrom
PPHA-602-Update-conditional-backlinks
Open

PPHA-602: Updated backlinks to go to check-your-answers when updating responses#421
stephhou wants to merge 19 commits intomainfrom
PPHA-602-Update-conditional-backlinks

Conversation

@stephhou
Copy link
Copy Markdown
Contributor

@stephhou stephhou commented Mar 30, 2026

What is the change?

  • Changed the order of responses on check-your-answers page to match page order.
  • Updated question base view to create a boolean based on the value of Change parameter for both GET and POST requests
  • Changed backlinks on all pages that should return to check-your-answers page, when editing responses.

Why are we making this change?

To ensure a good user experience by making the backlinks behave in an intuitive way when editing responses to questions.

@stephhou stephhou changed the title PPHA-602: Updated backlinks to go to check-you-answers when updating responses PPHA-602: Updated backlinks to go to check-your-answers when updating responses Mar 30, 2026
@stephhou stephhou marked this pull request as ready for review March 30, 2026 13:43
Copilot AI review requested due to automatic review settings March 30, 2026 13:43
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 improves the “change answers” journey by ensuring question pages can detect when a user is editing answers from the check-your-answers page, and adjusts back-link behavior accordingly.

Changes:

  • Add/standardize “change mode” detection (is_changing_responses) and update back-link destinations to return to questions:responses when editing.
  • Reorder “Sex at birth” and “Gender identity” items on the check-your-answers presenter to match question flow.
  • Add unit tests covering new back-link behavior across multiple question pages.

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
lung_cancer_screening/questions/views/question_base_view.py Renames/expands change-mode detection and uses it for success redirects.
lung_cancer_screening/questions/views/weight.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/height.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/gender.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/sex_at_birth.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/ethnicity.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/education.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/respiratory_conditions.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/asbestos_exposure.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/cancer_diagnosis.py Back-link now returns to responses when changing; otherwise previous question.
lung_cancer_screening/questions/views/family_history_lung_cancer.py Uses is_changing_responses and adds change-mode back-link.
lung_cancer_screening/questions/views/relatives_age_when_diagnosed.py Adds change-mode back-link while keeping prerequisite redirect logic.
lung_cancer_screening/questions/views/have_you_ever_smoked.py Adds change-mode back-link while preserving ineligible exit behavior.
lung_cancer_screening/questions/views/date_of_birth.py Adds change-mode back-link while preserving age-range exit behavior.
lung_cancer_screening/questions/views/age_when_started_smoking.py Uses is_changing_responses and adds change-mode back-link.
lung_cancer_screening/questions/views/periods_when_you_stopped_smoking.py Adds change-mode back-link.
lung_cancer_screening/questions/views/types_tobacco_smoking.py Computes back-link via helper; introduces local change-mode detection.
lung_cancer_screening/questions/views/smoking_current.py Back-link returns to responses when changing; preserves change query param when navigating back to types.
lung_cancer_screening/questions/views/smoking_change.py Renames change-mode helper and wires it into success/query-param logic.
lung_cancer_screening/questions/views/smoked_total_years.py Switches to is_changing_responses to control redirect flow.
lung_cancer_screening/questions/presenters/response_set_presenter.py Reorders “Sex at birth” item to match the actual question order.
lung_cancer_screening/questions/jinja2/weight.jinja Removes hardcoded back-link block so layout-driven back-link can be used.
lung_cancer_screening/questions/jinja2/height.jinja Removes hardcoded back-link block so layout-driven back-link can be used.
lung_cancer_screening/questions/tests/unit/views/test_weight.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_height.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_gender.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_sex_at_birth.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_ethnicity.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_education.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_respiratory_conditions.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_asbestos_exposure.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_cancer_diagnosis.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_family_history_lung_cancer.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_relatives_age_when_diagnosed.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_have_you_ever_smoked.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_date_of_birth.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_age_when_started_smoking.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_periods_when_you_stopped_smoking.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py Adds back-link tests for change vs non-change mode.
lung_cancer_screening/questions/tests/unit/views/test_smoking_current.py Adds back-link test for change mode in smoking_current.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +10
def is_changing_responses(self):
return bool(self.request.GET.get("change")) or bool(self.request.POST.get("change"))
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

is_changing_responses() treats any non-empty change value as true, but templates only persist the hidden POST field when change == "True". This can lead to GET behaving like “change mode” while the subsequent POST is not. Consider explicitly checking for the expected value (e.g., GET/POST change equals "True") to keep behavior consistent.

Copilot uses AI. Check for mistakes.
Comment on lines 37 to 41
return reverse(
"questions:smoking_current",
kwargs={
"tobacco_type": next_tobacco_smoking_history.url_type()
},
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

When arriving from the check-your-answers “Change” link, this view receives ?change=True, but the redirect URL built here drops that flag. That means subsequent smoking pages won't know they're in “change mode”, and their back links won’t return to the responses page. Preserve the change query param in this redirect (or redirect straight back to responses when changing).

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +46
def is_changing_responses(self):
return bool(self.request.GET.get("change")) or bool(self.request.POST.get("change"))

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

is_changing_responses() uses bool(request.GET/POST.get("change")), which will treat any non-empty value (including unexpected ones) as “changing”. Given templates only set the hidden POST field when change == "True", consider checking explicitly for the expected value to avoid inconsistent GET vs POST behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +62
def test_back_link_url_points_to_agree_terms_of_use_if_change_query_param_is_not_true(self):
ResponseSetFactory.create(user=self.user, eligible=True)
response = self.client.get(
reverse("questions:sex_at_birth")
)

self.assertEqual(response.context_data["back_link_url"], reverse("questions:gender"))
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The test name says the back link should point to agree_terms_of_use, but the assertion expects the gender URL. Rename the test (or adjust the expected URL) so the test description matches the behavior being verified.

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +84
ResponseSetFactory.create(user=self.user, eligible=True)

response = self.client.get(
reverse("questions:types_tobacco_smoking")
)

self.assertEqual(
response.context_data["back_link_url"],
reverse("questions:periods_when_you_stopped_smoking")
)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The new test method has its body over-indented, which will raise an IndentationError and prevent the test module from importing. Align the method body indentation with the other test methods in this class.

Suggested change
ResponseSetFactory.create(user=self.user, eligible=True)
response = self.client.get(
reverse("questions:types_tobacco_smoking")
)
self.assertEqual(
response.context_data["back_link_url"],
reverse("questions:periods_when_you_stopped_smoking")
)
ResponseSetFactory.create(user=self.user, eligible=True)
response = self.client.get(
reverse("questions:types_tobacco_smoking")
)
self.assertEqual(
response.context_data["back_link_url"],
reverse("questions:periods_when_you_stopped_smoking")
)

Copilot uses AI. Check for mistakes.
…when_you_stopped_smoking.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Steph Housden <167300771+stephhou@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
6.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

2 participants