Skip to content

Commit 275a4b0

Browse files
authored
Merge pull request #240 from NHSDigital/PPHA-526-types-smoking-tobacco
PPHA-526: Add types of tobacco smoked
2 parents 7abc57e + 67a4b1c commit 275a4b0

32 files changed

Lines changed: 682 additions & 45 deletions

features/date_of_birth_page.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Feature: Date of birth page
4343

4444
Scenario: Checking responses and changing them
4545
Given I am logged in
46-
And I have answered have you ever smoked with an eligible response
46+
And I have answered questions showing I am eligible
4747
When I go to "/date-of-birth"
4848
And I fill in and submit my date of birth as 55 years ago
4949
When I go to "/check-your-answers"

features/have_you_ever_smoked_page.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Feature: Have you ever smoked page
3030

3131
Scenario: Checking responses and changing them
3232
Given I am logged in
33+
And I have answered questions showing I am eligible
3334
When I go to "/have-you-ever-smoked"
3435
And I fill in and submit my smoking status with "Yes, I used to smoke"
3536
When I go to "/check-your-answers"

features/periods_when_you_stopped_smoking.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: Periods when you stopped smoking page
2626
When I check "Yes"
2727
And I fill in "Enter the total number of years you stopped smoking for" with "1"
2828
And I submit the form
29-
Then I am on "/check-your-answers"
29+
Then I am on "/types-tobacco-smoking"
3030

3131
Scenario: Checking responses and changing them
3232
Given I am logged in

features/questionnaire.feature

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ Feature: Questionnaire
6565
And I fill in "Enter the total number of years you stopped smoking for" with "10"
6666
And I submit the form
6767

68-
Then I am on "/check-your-answers"
69-
And I see a back link to "/periods-when-you-stopped-smoking"
68+
Then I am on "/types-tobacco-smoking"
69+
When I check "Cigarettes"
70+
And I check "Pipe"
71+
And I submit the form
7072

73+
Then I am on "/check-your-answers"
7174
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
7275
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
7376

features/steps/debug_steps.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from behave import when
2+
from datetime import datetime
3+
4+
@given("I take a screenshot")
5+
@given("I take a screenshot {value}")
6+
@when("I take a screenshot")
7+
@when("I take a screenshot {value}")
8+
@then("I take a screenshot")
9+
@then("I take a screenshot {value}")
10+
def screenshot(context, value=""):
11+
context.page.screenshot(
12+
full_page=True, path=f"screenshots/{datetime.now()}-{value}-screenshot.png"
13+
)
14+
15+
@given("I print eligibiity")
16+
@when("I print eligibiity")
17+
@then("I print eligibiity")
18+
def print_eligibiity(context):
19+
print("Is user eligible?: ", context.current_user.responseset_set.last().is_eligible())
20+

features/steps/form_steps.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ def when_i_enter_value_and_submit(context, field, value):
1414
context.page.get_by_label(field).fill(value)
1515
when_i_submit_the_form(context)
1616

17-
@when("I take a screenshot")
18-
@when("I take a screenshot {value}")
19-
def screenshot(context, value=""):
20-
context.page.screenshot(full_page=True, path=f"screenshots/{datetime.now()}-{value}-screenshot.png")
21-
2217
@when('I fill in and submit my smoking status with "{smoking_status}"')
2318
def when_i_fill_in_and_submit_my_smoking_status(context, smoking_status):
2419
context.page.get_by_label(smoking_status).check()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@TypesTobaccoSmoking
2+
Feature: Types tobacco 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 "/types-tobacco-smoking"
7+
Then there are no accessibility violations
8+
9+
Scenario: Form errors
10+
Given I am logged in
11+
And I have answered questions showing I am eligible
12+
When I go to "/types-tobacco-smoking"
13+
And I click "Continue"
14+
Then I am on "/types-tobacco-smoking"
15+
And I see a form error "Select the type of tobacco you smoke or have smoked"
16+
And there are no accessibility violations
17+
18+
Scenario: Navigating backwards and forwards
19+
Given I am logged in
20+
And I have answered questions showing I am eligible
21+
When I go to "/types-tobacco-smoking"
22+
Then I see a back link to "/periods-when-you-stopped-smoking"
23+
When I check "Cigarettes"
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+
And I have answered questions showing I am eligible
30+
When I go to "/types-tobacco-smoking"
31+
And I check "Cigarettes"
32+
And I check "Cigars"
33+
And I submit the form
34+
When I go to "/check-your-answers"
35+
Then I take a screenshot
36+
Then I see "Cigarettes and Cigars" as a response to "Types of tobacco smoked" under "Smoking history"
37+
And I see "/types-tobacco-smoking?change=True" as a link to change "Types of tobacco smoked" under "Smoking history"
38+
When I click the link to change "Types of tobacco smoked" under "Smoking history"
39+
Then I am on "/types-tobacco-smoking?change=True"
40+
And I see "Cigarettes" selected
41+
And I see "Cigars" selected
42+
When I check "Pipe"
43+
And I click "Continue"
44+
Then I am on "/check-your-answers"
45+
And I see "Cigarettes, Pipe, and Cigars" as a response to "Types of tobacco smoked" under "Smoking history"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from django import forms
2+
3+
from ...nhsuk_forms.choice_field import MultipleChoiceField
4+
from ..models.tobacco_smoking_history import TobaccoSmokingHistoryTypes, TobaccoSmokingHistory
5+
6+
7+
8+
class TypesTobaccoSmokingForm(forms.Form):
9+
10+
value = MultipleChoiceField(
11+
choices=TobaccoSmokingHistoryTypes.choices,
12+
widget=forms.CheckboxSelectMultiple,
13+
label="What do you or have you smoked?",
14+
label_classes="nhsuk-fieldset__legend--m",
15+
hint="Select all that apply",
16+
error_messages={
17+
"required": "Select the type of tobacco you smoke or have smoked"
18+
},
19+
)
20+
21+
def __init__(self, *args, response_set, **kwargs):
22+
super().__init__(*args, **kwargs)
23+
self.response_set = response_set
24+
self.existing_types = list(
25+
response_set.tobacco_smoking_history.values_list('type', flat=True)
26+
)
27+
self.fields["value"].initial = self.existing_types
28+
29+
value_field=self['value']
30+
value_field.add_hint_for_choice(
31+
TobaccoSmokingHistoryTypes.CIGARILLOS,
32+
"Cafe Creme or Signature cigars, roughly the size of a cigarette"
33+
)
34+
35+
36+
def save(self, commit=True):
37+
if not self.is_valid():
38+
return None
39+
40+
self._delete_types_not_selected()
41+
return self._create_types_selected()
42+
43+
44+
def _delete_types_not_selected(self):
45+
for kind in self.existing_types:
46+
if kind not in self.cleaned_data["value"]:
47+
TobaccoSmokingHistory.objects.filter(response_set=self.response_set, type=kind).delete()
48+
49+
50+
def _create_types_selected(self):
51+
instances = [
52+
TobaccoSmokingHistory(response_set=self.response_set, type=kind)
53+
for kind in self.cleaned_data["value"]
54+
if kind not in self.existing_types
55+
]
56+
57+
TobaccoSmokingHistory.objects.bulk_create(instances)
58+
59+
return instances

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</section>
4141

4242
<section>
43-
<h2 class="nhsuk-heading-m">Smoking history</h2>
43+
<h2 class="nhsuk-heading-m">Smoking history</h2>
4444

4545
{{ summaryList({
4646
"rows": response_set.smoking_history_responses_items()
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 prelude %}
4+
<h1 class="nhsuk-heading-l">The type of tobacco you smoke or used to smoke</h1>
5+
6+
<p>Smoking affects your health in different ways depending on what you smoke.</p>
7+
8+
<p>We need to know what you smoke, or used to smoke, on a regular basis. For example, if you have smoked a pipe on a weekly basis for a year or longer.</p>
9+
10+
<p>You do not need to tell us about less frequent forms of smoking. For example, a cigar on special occasions.</p>
11+
{% endblock prelude %}

0 commit comments

Comments
 (0)