diff --git a/lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py b/lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py index 6e5daa84..5289b416 100644 --- a/lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py +++ b/lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py @@ -52,3 +52,11 @@ def fill_in_and_submit_weight_imperial(page, stone, pounds): page.get_by_label("Pounds").fill(str(pounds)) page.click("text=Continue") + +def fill_in_and_submit_sex_at_birth(page, sex): + expect(page.locator("legend")).to_have_text( + "What was your sex at birth?") + + page.get_by_label(sex, exact=True).check() + + page.click("text=Continue") diff --git a/lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py b/lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py index f8ac92ac..2536419a 100644 --- a/lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py +++ b/lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py @@ -9,7 +9,8 @@ fill_in_and_submit_weight_metric, fill_in_and_submit_participant_id, fill_in_and_submit_smoking_eligibility, - fill_in_and_submit_date_of_birth + fill_in_and_submit_date_of_birth, + fill_in_and_submit_sex_at_birth ) class TestQuestionnaire(StaticLiveServerTestCase): @@ -40,6 +41,7 @@ def test_cannot_change_responses_once_checked_and_submitted(self): fill_in_and_submit_date_of_birth(page, age) fill_in_and_submit_height_metric(page, "170") fill_in_and_submit_weight_metric(page, "25.4") + fill_in_and_submit_sex_at_birth(page, "Male") page.click("text=Submit") diff --git a/lung_cancer_screening/core/tests/acceptance/test_questionnaire.py b/lung_cancer_screening/core/tests/acceptance/test_questionnaire.py index dba5c871..d92f7975 100644 --- a/lung_cancer_screening/core/tests/acceptance/test_questionnaire.py +++ b/lung_cancer_screening/core/tests/acceptance/test_questionnaire.py @@ -11,7 +11,8 @@ fill_in_and_submit_smoking_eligibility, fill_in_and_submit_date_of_birth, fill_in_and_submit_weight_metric, - fill_in_and_submit_weight_imperial + fill_in_and_submit_weight_imperial, + fill_in_and_submit_sex_at_birth ) from .helpers.assertion_helpers import expect_back_link_to_have_url @@ -49,43 +50,45 @@ def test_full_questionnaire_user_journey(self): expect(page).to_have_url( f"{self.live_server_url}/have-you-ever-smoked") - + expect_back_link_to_have_url(page, "/start") fill_in_and_submit_smoking_eligibility(page, smoking_status) expect(page).to_have_url(f"{self.live_server_url}/date-of-birth") expect_back_link_to_have_url(page, "/have-you-ever-smoked") - fill_in_and_submit_date_of_birth(page, age) expect(page).to_have_url(f"{self.live_server_url}/height") - + expect_back_link_to_have_url(page, "/date-of-birth") fill_in_and_submit_height_metric(page, height) - expect(page).to_have_url(f"{self.live_server_url}/weight") - page.click("text=Back") - expect(page).to_have_url(f"{self.live_server_url}/height") - page.click("text=Switch to imperial") - fill_in_and_submit_height_imperial(page, feet, inches) expect(page).to_have_url(f"{self.live_server_url}/weight") - + expect_back_link_to_have_url(page, "/height") fill_in_and_submit_weight_metric(page, weight_metric) - - expect(page).to_have_url(f"{self.live_server_url}/responses") page.click("text=Back") + + expect(page).to_have_url(f"{self.live_server_url}/weight") page.get_by_role("link", name="Switch to stone and pounds").click() fill_in_and_submit_weight_imperial(page, weight_stone, weight_pound) + + expect(page).to_have_url(f"{self.live_server_url}/sex-at-birth") + expect_back_link_to_have_url(page, "/weight") + fill_in_and_submit_sex_at_birth(page, "Male") + expect(page).to_have_url(f"{self.live_server_url}/responses") + expect_back_link_to_have_url(page, "/sex-at-birth") + responses = page.locator(".responses") expect(responses).to_contain_text("Have you ever smoked? Yes, I used to smoke regularly") expect(responses).to_contain_text( age.strftime("What is your date of birth? %Y-%m-%d")) expect(responses).to_contain_text(f"What is your height? {feet} feet {inches} inches") expect(responses).to_contain_text(f"What is your weight? {weight_stone} stone {weight_pound} pound") + expect(responses).to_contain_text("What was your sex at birth? Male") page.click("text=Submit") diff --git a/lung_cancer_screening/nhsuk_forms/choice_field.py b/lung_cancer_screening/nhsuk_forms/choice_field.py index 45db783a..cc9a2eab 100644 --- a/lung_cancer_screening/nhsuk_forms/choice_field.py +++ b/lung_cancer_screening/nhsuk_forms/choice_field.py @@ -1,8 +1,6 @@ from django import forms from django.forms import widgets -from .bound_choice_field import BoundChoiceField - class ChoiceField(forms.ChoiceField): """ A ChoiceField that renders using NHS.UK design system radios/select @@ -10,7 +8,6 @@ class ChoiceField(forms.ChoiceField): """ widget = widgets.RadioSelect - bound_field_class = BoundChoiceField def __init__( self, diff --git a/lung_cancer_screening/nhsuk_forms/jinja2/radios.jinja b/lung_cancer_screening/nhsuk_forms/jinja2/radios.jinja index 80e212d5..a97855fc 100644 --- a/lung_cancer_screening/nhsuk_forms/jinja2/radios.jinja +++ b/lung_cancer_screening/nhsuk_forms/jinja2/radios.jinja @@ -5,20 +5,12 @@ {% endif %} {% set ns = namespace(items=[]) %} {% for value, text in unbound_field.choices %} - {% set conditional_html = field.conditional_html(value) %} {% set ns.items = ns.items + [{ "id": field.auto_id if loop.first, "value": value, "text": text, - "checked": field.value() == value, - "conditional": { - "html": conditional_html - } if conditional_html else undefined + "checked": field.value() == value }] %} - {% set divider = field.get_divider_after(value) %} - {% if divider %} - {% set ns.items = ns.items + [{"divider": divider}] %} - {% endif %} {% endfor %} {{ radios({ "name": field.html_name, diff --git a/lung_cancer_screening/nhsuk_forms/tests/unit/test_choice_field.py b/lung_cancer_screening/nhsuk_forms/tests/unit/test_choice_field.py index d8ae7f62..50fd7ea5 100644 --- a/lung_cancer_screening/nhsuk_forms/tests/unit/test_choice_field.py +++ b/lung_cancer_screening/nhsuk_forms/tests/unit/test_choice_field.py @@ -38,41 +38,3 @@ def test_renders_nhs_radios(self): """, ) - - def test_renders_radios_with_conditional_html(self): - form = TestForm() - form["field"].add_conditional_html("b", "
Hello
") - - self.assertHTMLEqual( - form["field"].as_field_group(), - """ -Hello
") - - self.assertHTMLEqual( - form["field"].as_field_group(), - """ -