Skip to content

Commit 2d03d98

Browse files
PPHA-593: separate quit smoking page from periods you stopped smoking (#427)
# What is the change? Create a separate page in the former smoker journey so users can enter when they quit # Why are we making this change? So that users can differentiate between when they quite and periods they stopped smoking. This allows clarity and stops the user having to calculate the total years stopped themselves --------- Co-authored-by: Jamie Falcus <50366804+jamiefalcus@users.noreply.github.com>
1 parent 52a3d04 commit 2d03d98

47 files changed

Lines changed: 1330 additions & 242 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

features/age_when_started_smoking.feature

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,28 @@ Feature: Age when started smoking
2121
Then I see a form error "The age you started smoking must be the same as, or less than your current age"
2222
And there are no accessibility violations
2323

24-
Scenario: Navigating backwards and forwards
24+
Scenario: Navigating backwards and forwards as a former smoker
2525
Given I am logged in
2626
And I have answered questions showing I am eligible
27+
And I have answered questions showing I am a former smoker
28+
When I go to "/age-when-started-smoking"
29+
Then I see a back link to "/relatives-age-when-diagnosed"
30+
When I fill in "How old were you when you started smoking?" as "18" and submit
31+
Then I am on "/when-you-quit-smoking"
32+
33+
Scenario: Navigating backwards and forwards as a current smoker
34+
Given I am logged in
35+
And I have answered questions showing I am eligible
36+
And I have answered questions showing I am a current smoker
2737
When I go to "/age-when-started-smoking"
2838
Then I see a back link to "/relatives-age-when-diagnosed"
2939
When I fill in "How old were you when you started smoking?" as "18" and submit
3040
Then I am on "/periods-when-you-stopped-smoking"
3141

32-
Scenario: Checking responses and changing them
42+
Scenario: Checking responses and changing them as a current smoker
3343
Given I am logged in
3444
And I have answered questions showing I am eligible
45+
And I have answered questions showing I am a current smoker
3546
When I go to "/age-when-started-smoking"
3647
And I fill in "How old were you when you started smoking?" as "18" and submit
3748
When I go to "/check-your-answers"
@@ -42,3 +53,18 @@ Feature: Age when started smoking
4253
And I see "18" filled in for "How old were you when you started smoking?"
4354
When I fill in "How old were you when you started smoking?" as "22" and submit
4455
Then I am on "/periods-when-you-stopped-smoking?change=True"
56+
57+
Scenario: Checking responses and changing them as a former smoker
58+
Given I am logged in
59+
And I have answered questions showing I am eligible
60+
And I have answered questions showing I am a former smoker
61+
When I go to "/age-when-started-smoking"
62+
And I fill in "How old were you when you started smoking?" as "18" and submit
63+
When I go to "/check-your-answers"
64+
Then I see "18" as a response to "Age you started smoking" under "Smoking history"
65+
And I see "/age-when-started-smoking?change=True" as a link to change "Age you started smoking" under "Smoking history"
66+
When I click the link to change "Age you started smoking" under "Smoking History"
67+
Then I am on "/age-when-started-smoking?change=True"
68+
And I see "18" filled in for "How old were you when you started smoking?"
69+
When I fill in "How old were you when you started smoking?" as "22" and submit
70+
Then I am on "/when-you-quit-smoking?change=True"

features/smoking_history.feature

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ Feature: Smoking history pages
386386
And I see "2 cigarillos a month" as a response to "Current cigarillo smoking" under "Cigarillo smoking history"
387387
And I see "4 cigarillos a week for 3 years" as a response to "When you smoked more than 2 cigarillos a month" under "Cigarillo smoking history"
388388

389-
# Change cigarette smoking history with increased and decreased
389+
# Change cigarette smoking history
390390
When I click the link to change "Cigarette" smoking history
391391

392392
Then I am on "/cigarettes-smoking-current?change=True"
@@ -419,102 +419,9 @@ Feature: Smoking history pages
419419
And I submit the form
420420

421421
Then I am on "/cigarettes-smoked-increased-years?change=True"
422-
When I submit the form
423422

424-
Then I am on "/cigarettes-smoking-decreased-frequency?change=True"
425-
When I submit the form
426-
427-
Then I am on "/cigarettes-smoked-decreased-amount?change=True"
428-
When I submit the form
429-
430-
Then I am on "/cigarettes-smoked-decreased-years?change=True"
431-
When I submit the form
432-
433-
Then I am on "/check-your-answers"
423+
When I go to "/check-your-answers"
434424
Then I see "17 years" as a response to "Total number of years you smoked cigarettes" under "Cigarette smoking history"
435425
And I see "25 cigarettes a month" as a response to "Current cigarette smoking" under "Cigarette smoking history"
436426

437427
And I see "40 cigarettes a day for 5 years" as a response to "When you smoked more than 25 cigarettes a month" under "Cigarette smoking history"
438-
439-
# Change medium cigars with decreased
440-
When I click the link to change "Medium cigar" smoking history
441-
442-
Then I am on "/medium-cigars-smoking-current?change=True"
443-
When I submit the form
444-
445-
Then I am on "/medium-cigars-smoked-total-years?change=True"
446-
When I submit the form
447-
448-
Then I am on "/medium-cigars-smoking-frequency?change=True"
449-
When I submit the form
450-
451-
Then I am on "/medium-cigars-smoked-amount?change=True"
452-
When I submit the form
453-
454-
Then I am on "/medium-cigars-smoking-change?change=True"
455-
When I submit the form
456-
457-
Then I am on "/medium-cigars-smoking-decreased-frequency?change=True"
458-
When I submit the form
459-
460-
Then I am on "/medium-cigars-smoked-decreased-amount?change=True"
461-
When I submit the form
462-
463-
Then I am on "/medium-cigars-smoked-decreased-years?change=True"
464-
When I submit the form
465-
466-
Then I am on "/check-your-answers"
467-
468-
# Change cigarillos with increased
469-
When I click the link to change "Cigarillo" smoking history
470-
471-
Then I am on "/cigarillos-smoking-current?change=True"
472-
When I submit the form
473-
474-
Then I am on "/cigarillos-smoked-total-years?change=True"
475-
When I submit the form
476-
477-
Then I am on "/cigarillos-smoking-frequency?change=True"
478-
When I submit the form
479-
480-
Then I am on "/cigarillos-smoked-amount?change=True"
481-
When I submit the form
482-
483-
Then I am on "/cigarillos-smoking-change?change=True"
484-
When I submit the form
485-
486-
Then I am on "/cigarillos-smoking-increased-frequency?change=True"
487-
When I submit the form
488-
489-
Then I am on "/cigarillos-smoked-increased-amount?change=True"
490-
When I submit the form
491-
492-
Then I am on "/cigarillos-smoked-increased-years?change=True"
493-
When I submit the form
494-
495-
Then I am on "/check-your-answers"
496-
497-
# Change cigarettes change to no change
498-
When I click the link to change "Cigarette" smoking history
499-
500-
Then I am on "/cigarettes-smoking-current?change=True"
501-
When I submit the form
502-
503-
Then I am on "/cigarettes-smoked-total-years?change=True"
504-
When I submit the form
505-
506-
Then I am on "/cigarettes-smoking-frequency?change=True"
507-
When I submit the form
508-
509-
Then I am on "/cigarettes-smoked-amount?change=True"
510-
When I submit the form
511-
512-
Then I am on "/cigarettes-smoking-change?change=True"
513-
When I uncheck "Yes, I used to smoke more than 25 cigarettes a month"
514-
And I uncheck "Yes, I used to smoke fewer than 25 cigarettes a month"
515-
And I check "No, it has not changed"
516-
When I submit the form
517-
518-
Then I am on "/check-your-answers"
519-
520-

features/steps/accessibility_steps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def then_there_are_no_accessibility_violations(context):
77
axe_results = axe.run(context.page)
88
violations_msg = (
99
f"Found the following accessibility violations: \n"
10-
# Use generate_report for more indepth information about the violations
11-
f"{axe_results.generate_snapshot()}"
10+
f"{axe_results.generate_report()}"
1211
)
1312
assert axe_results.violations_count == 0, violations_msg

features/steps/preflight_steps.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ def given_i_have_answered_questions_showing_i_am_eligible(context):
6868
eligible=True,
6969
)
7070

71-
@given("I have answered questions showing I am a current smoker")
72-
def given_i_have_answered_questions_showing_i_am_a_current_smoker(context):
71+
@given("I have answered questions showing I am a {current_or_former} smoker")
72+
def given_i_have_answered_questions_showing_i_am_a_current_smoker(context, current_or_former):
7373
context.page.goto(f"{context.live_server_url}/have-you-ever-smoked")
7474

75-
when_i_check_label(context, "Yes, I currently smoke")
76-
when_i_submit_the_form(context)
75+
if current_or_former == "current":
76+
when_i_check_label(context, "Yes, I currently smoke")
77+
elif current_or_former == "former":
78+
when_i_check_label(context, "Yes, I used to smoke")
79+
else:
80+
raise ValueError(f"Invalid current_or_former: {current_or_former}")
7781

82+
when_i_submit_the_form(context)
7883

84+
@given('I have answered questions showing I started smoking "{years}" years ago')
7985
@given('I have answered questions showing I have smoked for "{years}" years')
8086
def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(context, years):
8187
response_set = get_or_create_response_set(context)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@SmokingHistory
2+
@WhenYouQuitSmoking
3+
Feature: Age quit smoking
4+
Scenario: The page is accessible
5+
Given I am logged in
6+
And I have answered questions showing I am eligible
7+
And I have answered questions showing I am a former smoker
8+
And I am 60 years old
9+
And I have answered questions showing I started smoking "30" years ago
10+
When I go to "/age-when-started-smoking"
11+
Then there are no accessibility violations
12+
13+
Scenario: Form errors
14+
Given I am logged in
15+
And I have answered questions showing I am eligible
16+
And I have answered questions showing I am a former smoker
17+
And I am 60 years old
18+
And I have answered questions showing I started smoking "30" years ago
19+
When I go to "/when-you-quit-smoking"
20+
And I click "Continue"
21+
Then I am on "/when-you-quit-smoking"
22+
And I see a form error "Enter your age when you quit smoking"
23+
And there are no accessibility violations
24+
25+
Scenario: Navigating backwards and forwards
26+
Given I am logged in
27+
And I have answered questions showing I am eligible
28+
And I have answered questions showing I am a former smoker
29+
And I am 60 years old
30+
And I have answered questions showing I started smoking "30" years ago
31+
When I go to "/when-you-quit-smoking"
32+
Then I see a back link to "/age-when-started-smoking"
33+
When I fill in "How old were you when you quit smoking?" as "30" and submit
34+
Then I am on "/periods-when-you-stopped-smoking"
35+
36+
Scenario: Checking responses and changing them
37+
Given I am logged in
38+
And I have answered questions showing I am eligible
39+
And I have answered questions showing I am a former smoker
40+
And I am 60 years old
41+
And I have answered questions showing I started smoking "30" years ago
42+
When I go to "/when-you-quit-smoking"
43+
And I fill in "How old were you when you quit smoking?" as "40" and submit
44+
When I go to "/check-your-answers"
45+
Then I see "40" as a response to "Age you quit smoking" under "Smoking history"
46+
And I see "/when-you-quit-smoking?change=True" as a link to change "Age you quit smoking" under "Smoking history"
47+
When I click the link to change "Age you quit smoking" under "Smoking History"
48+
Then I am on "/when-you-quit-smoking?change=True"
49+
And I see "40" filled in for "How old were you when you quit smoking?"
50+
When I fill in "How old were you when you quit smoking?" as "45" and submit
51+
Then I am on "/periods-when-you-stopped-smoking?change=True"

lung_cancer_screening/questions/forms/age_when_started_smoking_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
2121
"invalid": "Enter your age when you started smoking",
2222
"zero_entered":"The age you started smoking must be between 1 and your current age",
2323
"age_started_smoking_greater_than_current_age":"The age you started smoking must be the same as, or less than your current age",
24-
"no_date_of_birth" : format_html("<a href=\"{}\">Provide your date of birth</a> before answering this question", reverse_lazy("questions:date_of_birth"))
24+
"no_date_of_birth" : format_html("<a href=\"{}\">Provide your date of birth</a> before answering age when you started smoking", reverse_lazy("questions:date_of_birth"))
2525
}
2626
)
2727

lung_cancer_screening/questions/forms/periods_when_you_stopped_smoking_form.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from django import forms
2+
from django.urls import reverse_lazy
3+
from django.utils.html import format_html
24

35
from ...nhsuk_forms.integer_field import IntegerField
46
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
@@ -25,8 +27,9 @@ def __init__(self, *args, **kwargs):
2527

2628
coerce=lambda x: x == "True",
2729
error_messages={
28-
"required": self.required_error_message()
29-
},
30+
"required": self.required_error_message(),
31+
"duration_years": self.duration_years_error_message()
32+
}
3033
)
3134

3235
self.fields["duration_years"] = IntegerField(
@@ -36,6 +39,9 @@ def __init__(self, *args, **kwargs):
3639
hint=self.duration_years_hint(),
3740
required=False,
3841
suffix="years",
42+
error_messages={
43+
"no_when_you_quit_smoking": format_html("<a href=\"{}\">Provide when you quit smoking</a> before answering the total number of years you stopped smoking", reverse_lazy("questions:when_you_quit_smoking"))
44+
}
3945
)
4046

4147
def clean_duration_years(self):
@@ -59,7 +65,7 @@ def label(self):
5965
if self.response_set().current_smoker():
6066
return "Have you ever stopped smoking for periods of 1 year or longer?"
6167
else:
62-
return "Did you ever stop or quit smoking for periods of 1 year or longer?"
68+
return "Before you quit smoking, did you ever stop for periods of 1 year or longer?"
6369

6470

6571
def label_is_page_heading(self):
@@ -82,24 +88,27 @@ def stopped_or_quit(self):
8288
else:
8389
return "stopped or quit "
8490

91+
def smoked_or_smoke(self):
92+
if self.response_set().former_smoker():
93+
return "smoked"
94+
else:
95+
return "have been smoking"
8596

8697
def required_error_message(self):
8798
return f"Select if you ever {self.stopped_or_quit()}smoking for periods of 1 year or longer"
8899

89100

101+
def duration_years_error_message(self):
102+
return f"The number of years you stopped smoking must be fewer than the total number of years you {self.smoked_or_smoke()}"
103+
104+
90105
def duration_years_required_error_message(self):
91106
return f"Enter the total number of years you {self.stopped_or_quit()}smoking"
92107

93108

94109
def duration_years_label(self):
95-
if self.response_set().current_smoker():
96-
return "Enter the total number of years you stopped smoking"
97-
else:
98-
return "Roughly how many years did you stop or quit smoking in total?"
110+
return "Enter the total number of years you stopped smoking"
99111

100112

101113
def duration_years_hint(self):
102-
if self.response_set().current_smoker():
103-
return "Give an estimate if you are not sure"
104-
else:
105-
return "Add together the periods when you stopped smoking and the number of years since you quit. Give an estimate if you are not sure."
114+
return "Give an estimate if you are not sure"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from django import forms
2+
from django.urls import reverse_lazy
3+
from django.utils.html import format_html
4+
5+
from lung_cancer_screening.nhsuk_forms.integer_field import IntegerField
6+
from ..models.when_you_quit_smoking_response import WhenYouQuitSmokingResponse
7+
8+
class WhenYouQuitSmokingForm(forms.ModelForm):
9+
class Meta:
10+
model = WhenYouQuitSmokingResponse
11+
fields = ["value"]
12+
13+
def __init__(self, *args, **kwargs):
14+
super().__init__(*args, **kwargs)
15+
16+
self.fields["value"] = IntegerField(
17+
label="How old were you when you quit smoking?",
18+
label_classes="nhsuk-label--m",
19+
classes="nhsuk-input--width-2",
20+
hint="Give an estimate if you are not sure",
21+
prefix="Age",
22+
error_messages={
23+
"required": "Enter your age when you quit smoking",
24+
"invalid": "Enter your age when you quit smoking",
25+
"min_value":"The age you quit smoking must be between 1 and your current age",
26+
"age_when_quit_smoking_greater_than_age_started":"The age you quit smoking cannot be lower than the age you started smoking",
27+
"age_when_quit_smoking_greater_than_current_age" : "The age you quit smoking must be the same as, or less than, your current age",
28+
"no_date_of_birth" : format_html("<a href=\"{}\">Provide your date of birth</a> before answering when you quit smoking", reverse_lazy("questions:date_of_birth"))
29+
}
30+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends 'question_form.jinja' %}
2+
3+
{% block pageTitle %}When did you quit smoking? – Check if you need a lung scan – NHS{% endblock %}
4+
5+
{% block prelude %}
6+
<h1 class="nhsuk-heading-l">When you quit smoking?</h1>
7+
8+
<p>If you stopped smoking more than once, tell us your age when you last quit smoking.</p>
9+
10+
<p>The question on the next page will ask if you ever stopped smoking for periods of 1 year or longer before you quit.</p>
11+
{% endblock prelude %}

0 commit comments

Comments
 (0)