Skip to content

Commit 16d7714

Browse files
committed
PPHA-525: Add Periods when you stopped smoking page
1 parent 1874502 commit 16d7714

27 files changed

Lines changed: 522 additions & 26 deletions

features/age_when_started_smoking.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: Age when started smoking
2626
When I go to "/age-when-started-smoking"
2727
Then I see a back link to "/relatives-age-when-diagnosed"
2828
When I fill in "How old were you when you started smoking?" as "18" and submit
29-
Then I am on "/check-your-answers"
29+
Then I am on "/periods-when-you-stopped-smoking"
3030

3131
Scenario: Checking responses and changing them
3232
Given I am logged in
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@PeriodsWhenYouStoppedSmoking
2+
Feature: Periods when you stopped smoking page
3+
Scenario: The page is accessible
4+
Given I am logged in
5+
And I have answered questions showing I am eligible
6+
When I go to "/periods-when-you-stopped-smoking"
7+
# TODO: problem with aria expanded from nhsuk frontend
8+
# Then there are no accessibility violations
9+
10+
Scenario: Form errors
11+
Given I am logged in
12+
And I have answered questions showing I am eligible
13+
When I go to "/periods-when-you-stopped-smoking"
14+
When I submit the form
15+
Then I am on "/periods-when-you-stopped-smoking"
16+
And I see a form error "Select if you ever stopped smoking for periods of 1 year or longer"
17+
# TODO: problem with aria expanded from nhsuk frontend
18+
# And there are no accessibility violations
19+
20+
Scenario: Navigating backwards and forwards
21+
Given I am logged in
22+
And I have answered questions showing I am eligible
23+
When I go to "/periods-when-you-stopped-smoking"
24+
Then I see a back link to "/family-history-lung-cancer"
25+
When I check "Yes"
26+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
27+
And I submit the form
28+
Then I am on "/check-your-answers"
29+
30+
Scenario: Checking responses and changing them
31+
Given I am logged in
32+
And I have answered questions showing I am eligible
33+
When I go to "/periods-when-you-stopped-smoking"
34+
And I check "Yes"
35+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
36+
And I submit the form
37+
When I go to "/check-your-answers"
38+
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"
39+
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"
40+
When I click the link to change "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"
41+
Then I am on "/periods-when-you-stopped-smoking?change=True"
42+
And I see "Yes" selected
43+
When I check "No"
44+
And I submit the form
45+
Then I am on "/check-your-answers"
46+
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ Feature: Questionnaire
5959
Then I am on "/age-when-started-smoking"
6060
When I fill in "How old were you when you started smoking?" as "18" and submit
6161

62+
63+
Then I am on "/periods-when-you-stopped-smoking"
64+
When I check "Yes"
65+
And I fill in "Enter the total number of years you stopped smoking for" with "10"
66+
And I submit the form
67+
6268
Then I am on "/check-your-answers"
63-
And I see a back link to "/age-when-started-smoking"
69+
And I see a back link to "/periods-when-you-stopped-smoking"
6470

6571
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
6672
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
@@ -78,5 +84,8 @@ Feature: Questionnaire
7884
And I see "Yes" as a response to "Have any of your parents, siblings or children ever been diagnosed with lung cancer?" under "Family history"
7985
And I see "Yes, they were younger than 60" as a response to "Were any of your relatives younger than 60 years old when they were diagnosed with lung cancer?" under "Family history"
8086

87+
And I see "18" as a response to "Age you started smoking" under "Smoking history"
88+
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"
89+
8190
When I click "Submit"
8291
Then I am on "/confirmation"

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
@@ -110,6 +110,11 @@ def when_i_fill_in_and_submit_my_cancer_diagnosis(context, relatives_age_when_di
110110
context.page.get_by_label(relatives_age_when_diagnosed, exact=True).check()
111111
when_i_submit_the_form(context)
112112

113+
@when(u'I fill in and submit my periods when you stopped smoking with "{periods_when_you_stopped_smoking}"')
114+
def when_i_fill_in_and_submit_my_periods_when_you_stopped_smoking(context, periods_when_you_stopped_smoking):
115+
context.page.get_by_label(periods_when_you_stopped_smoking, exact=True).check()
116+
when_i_submit_the_form(context)
117+
113118
@when('I submit the form')
114119
def when_i_submit_the_form(context):
115120
when_i_click(context, "Continue")
@@ -134,3 +139,8 @@ def then_i_see_value_filled_in_for_label(context, value, label):
134139
@when('I check "{label}"')
135140
def when_i_check_label(context, label):
136141
context.page.get_by_label(label, exact=True).check()
142+
143+
144+
@when('I fill in "{label}" with "{value}"')
145+
def when_i_fill_in_label_with_value(context, label, value):
146+
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 %}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.db import migrations, models
2+
import django.db.models.deletion
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("questions", "0043_agewhenstartedsmokingresponse"),
9+
]
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name='PeriodsWhenYouStoppedSmokingResponse',
14+
fields=[
15+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
16+
('created_at', models.DateTimeField(auto_now_add=True)),
17+
('updated_at', models.DateTimeField(auto_now=True)),
18+
('value', models.BooleanField()),
19+
('response_set', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='periods_when_you_stopped_smoking_response', to='questions.responseset')),
20+
],
21+
options={
22+
'abstract': False,
23+
},
24+
),
25+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.10 on 2026-01-21 11:01
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('questions', '0044_periodswhenyoustoppedsmokingresponse'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='periodswhenyoustoppedsmokingresponse',
15+
name='duration_years',
16+
field=models.IntegerField(blank=True, null=True),
17+
),
18+
]

0 commit comments

Comments
 (0)