Skip to content

Commit 5151649

Browse files
committed
PPHA-525: Add Periods when you stopped smoking page
1 parent 0d280a7 commit 5151649

29 files changed

Lines changed: 538 additions & 11 deletions

features/family_history_lung_cancer.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Family history of lung cancer page
1818
When I go to "/family-history-lung-cancer"
1919
Then I see a back link to "/cancer-diagnosis"
2020
When I fill in and submit my asbestos exposure with "No"
21-
Then I am on "/check-your-answers"
21+
Then I am on "/periods-when-you-stopped-smoking"
2222
When I click "Back"
2323
When I fill in and submit my family history lung cancer with "Yes"
2424
Then I am on "/relatives-age-when-diagnosed"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@PeriodsWhenYouStoppedSmoking
2+
Feature: Periods when you stopped smoking page
3+
Scenario: The page is accessible
4+
Given I am logged in
5+
When I go to "/periods-when-you-stopped-smoking"
6+
# TODO: problem with aria expanded from nhsuk frontend
7+
# Then there are no accessibility violations
8+
9+
Scenario: Form errors
10+
Given I am logged in
11+
When I go to "/periods-when-you-stopped-smoking"
12+
When I submit the form
13+
Then I am on "/periods-when-you-stopped-smoking"
14+
And I see a form error "Select if you ever stopped smoking for periods of 1 year or longer"
15+
# TODO: problem with aria expanded from nhsuk frontend
16+
# And there are no accessibility violations
17+
18+
Scenario: Navigating backwards and forwards
19+
Given I am logged in
20+
When I go to "/periods-when-you-stopped-smoking"
21+
Then I see a back link to "/family-history-lung-cancer"
22+
When I check "Yes"
23+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
24+
And I submit the form
25+
Then I am on "/check-your-answers"
26+
27+
Scenario: Checking responses and changing them
28+
Given I am logged in
29+
When I go to "/periods-when-you-stopped-smoking"
30+
And I check "Yes"
31+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
32+
And I submit the form
33+
When I go to "/check-your-answers"
34+
Then I see "Yes (10 years)" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
35+
And I see "/periods-when-you-stopped-smoking?change=True" as a link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
36+
When I click the link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
37+
Then I am on "/periods-when-you-stopped-smoking?change=True"
38+
And I see "Yes" selected
39+
When I check "No"
40+
And I submit the form
41+
Then I am on "/check-your-answers"
42+
And I see "No" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"

features/questionnaire.feature

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,20 @@ Feature: Questionnaire
5656
Then I am on "/relatives-age-when-diagnosed"
5757
When I fill in and submit my relatives age when diagnosed with "Yes, they were younger than 60"
5858

59+
Then I am on "/periods-when-you-stopped-smoking"
60+
When I check "Yes"
61+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
62+
And I submit the form
63+
5964
Then I am on "/check-your-answers"
60-
And I see a back link to "/relatives-age-when-diagnosed"
65+
And I see a back link to "/periods-when-you-stopped-smoking"
6166

6267
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
6368
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
6469

70+
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Smoking history"
71+
And I see "Yes (10 years)" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
72+
6573
And I see "5 feet 7 inches" as a response to "Height" under "About you"
6674
And I see "5 stone 10 pounds" as a response to "Weight" under "About you"
6775
And I see "Male" as a response to "Sex at birth" under "About you"

features/relatives_age_when_diagnosed.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: Relatives age when diagnosed page
2424
Then I am on "/relatives-age-when-diagnosed"
2525
And I see a back link to "/family-history-lung-cancer"
2626
When I fill in and submit my relatives age when diagnosed with "Yes, they were younger than 60"
27-
Then I am on "/check-your-answers"
27+
Then I am on "/periods-when-you-stopped-smoking"
2828

2929
Scenario: Redirecting if they have no family history of lung cancer
3030
Given I am logged in

features/steps/accessibility_steps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ def then_there_are_no_accessibility_violations(context):
99
f"Found the following accessibility violations: \n"
1010
f"{axe_results.generate_snapshot()}"
1111
)
12+
print(axe_results)
1213
assert axe_results.violations_count == 0, violations_msg

features/steps/form_steps.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ def when_i_fill_in_and_submit_my_cancer_diagnosis(context, relatives_age_when_di
105105
context.page.get_by_label(relatives_age_when_diagnosed, exact=True).check()
106106
when_i_submit_the_form(context)
107107

108+
@when(u'I fill in and submit my periods when you stopped smoking with "{periods_when_you_stopped_smoking}"')
109+
def when_i_fill_in_and_submit_my_periods_when_you_stopped_smoking(context, periods_when_you_stopped_smoking):
110+
context.page.get_by_label(periods_when_you_stopped_smoking, exact=True).check()
111+
when_i_submit_the_form(context)
112+
108113
@when('I submit the form')
109114
def when_i_submit_the_form(context):
110115
when_i_click(context, "Continue")
@@ -129,3 +134,8 @@ def then_i_see_value_filled_in_for_label(context, value, label):
129134
@when('I check "{label}"')
130135
def when_i_check_label(context, label):
131136
context.page.get_by_label(label, exact=True).check()
137+
138+
139+
@when('I fill in "{label}" with "{value}"')
140+
def when_i_fill_in_label_with_value(context, label, value):
141+
context.page.get_by_label(label, exact=True).fill(value)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
import "nhsuk-frontend/packages/nhsuk.js";
1+
import { initAll } from "nhsuk-frontend";
2+
3+
document.addEventListener("DOMContentLoaded", () => {
4+
// Initialise NHS.UK frontend components
5+
initAll();
6+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from django import forms
2+
3+
from ...nhsuk_forms.integer_field import IntegerField
4+
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
5+
from ..models.periods_when_you_stopped_smoking_response import PeriodsWhenYouStoppedSmokingResponse
6+
7+
8+
class PeriodsWhenYouStoppedSmokingForm(forms.ModelForm):
9+
def __init__(self, *args, **kwargs):
10+
super().__init__(*args, **kwargs)
11+
12+
self.fields["value"] = TypedChoiceField(
13+
choices=[(True, "Yes"), (False, "No")],
14+
widget=forms.RadioSelect,
15+
label="Have you ever stopped smoking for periods of 1 year or longer?",
16+
label_classes="nhsuk-fieldset__legend--m",
17+
coerce=lambda x: x == "True",
18+
error_messages={
19+
"required": "Select if you ever stopped smoking for periods of 1 year or longer"
20+
},
21+
)
22+
23+
self.fields["duration_years"] = IntegerField(
24+
label="Enter the total number of years you stopped smoking for",
25+
label_classes="nhsuk-fieldset__legend--s",
26+
classes="nhsuk-input--width-4",
27+
hint="Give an estimate if you are not sure",
28+
required=False,
29+
suffix="years",
30+
error_messages={
31+
"required": "Enter the total number of years you stopped smoking for"
32+
},
33+
)
34+
35+
class Meta:
36+
model = PeriodsWhenYouStoppedSmokingResponse
37+
fields = ["value", "duration_years"]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends 'layout.jinja' %}
2+
3+
{% from 'nhsuk/components/button/macro.jinja' import button %}
4+
5+
{% if error %}
6+
{% set error_message = { "text": error } %}
7+
{% endif %}
8+
9+
{% block page_content %}
10+
<div class="nhsuk-grid-row">
11+
<div class="nhsuk-grid-column-two-thirds">
12+
<form action="{{ request.path }}" method="POST">
13+
{{ csrf_input }}
14+
15+
{% if request.GET.get("change") == "True" %}
16+
<input type="hidden" name="change" value="True">
17+
{% endif %}
18+
19+
<h1 class="nhsuk-heading-l">Periods when you stopped smoking</h1>
20+
21+
<p>There may have been periods when you stopped or quit smoking.</p>
22+
<p>If you stopped smoking for periods of 1 year or longer, tell us the total number of years you stopped smoking.</p>
23+
24+
{% do form.value.add_conditional_html(
25+
True,
26+
form.duration_years.as_field_group()
27+
) %}
28+
29+
{{ form.value.as_field_group() }}
30+
31+
{{ button({
32+
"text": "Continue"
33+
}) }}
34+
</form>
35+
</div>
36+
</div>
37+
{% endblock %}

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
}) }}
1818
</section>
1919

20+
<section>
21+
<h2 class="nhsuk-heading-m">Smoking history</h2>
22+
{{ summaryList({
23+
"rows": response_set.smoking_history_responses_items()
24+
}) }}
25+
</section>
26+
2027
<section>
2128
<h2 class="nhsuk-heading-m">About you</h2>
2229
{{ summaryList({

0 commit comments

Comments
 (0)