PPHA-602: Updated backlinks to go to check-your-answers when updating responses#421
PPHA-602: Updated backlinks to go to check-your-answers when updating responses#421
Conversation
Signed-off-by: Steph Housden <167300771+stephhou@users.noreply.github.com>
There was a problem hiding this comment.
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 toquestions:responseswhen 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.
lung_cancer_screening/questions/tests/unit/views/test_periods_when_you_stopped_smoking.py
Outdated
Show resolved
Hide resolved
lung_cancer_screening/questions/tests/unit/views/test_periods_when_you_stopped_smoking.py
Outdated
Show resolved
Hide resolved
| def is_changing_responses(self): | ||
| return bool(self.request.GET.get("change")) or bool(self.request.POST.get("change")) |
There was a problem hiding this comment.
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.
| return reverse( | ||
| "questions:smoking_current", | ||
| kwargs={ | ||
| "tobacco_type": next_tobacco_smoking_history.url_type() | ||
| }, |
There was a problem hiding this comment.
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).
| def is_changing_responses(self): | ||
| return bool(self.request.GET.get("change")) or bool(self.request.POST.get("change")) | ||
|
|
There was a problem hiding this comment.
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.
| 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")) |
There was a problem hiding this comment.
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.
| 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") | ||
| ) |
There was a problem hiding this comment.
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.
| 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") | |
| ) |
lung_cancer_screening/questions/tests/unit/views/test_family_history_lung_cancer.py
Show resolved
Hide resolved
…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>
|


What is the change?
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.