Skip to content

Commit eae8ab9

Browse files
authored
Merge pull request #336 from NHSDigital/PPHA-589-fix-missing-dynamic-type-names-in-smoking-journey
PPHA-589: Handle past and present in multipe smoking types
2 parents cc6bb8e + 6b73f2e commit eae8ab9

23 files changed

Lines changed: 889 additions & 178 deletions

features/smoked_total_years.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Feature: Smoked total years page
66
And I have answered questions showing I am eligible
77
And I have answered questions showing I have smoked for "10" years
88
And I have answered questions showing I have smoked "Cigarettes"
9+
And I have answered questions showing I currently smoke "Cigarettes"
910
When I go to "/cigarettes-smoked-total-years"
1011
Then there are no accessibility violations
1112

@@ -14,6 +15,7 @@ Feature: Smoked total years page
1415
And I have answered questions showing I am eligible
1516
And I have answered questions showing I have smoked for "10" years
1617
And I have answered questions showing I have smoked "Cigarettes"
18+
And I have answered questions showing I currently smoke "Cigarettes"
1719
When I go to "/cigarettes-smoked-total-years"
1820
And I click "Continue"
1921
Then I am on "/cigarettes-smoked-total-years"
@@ -25,6 +27,7 @@ Feature: Smoked total years page
2527
And I have answered questions showing I am eligible
2628
And I have answered questions showing I have smoked for "10" years
2729
And I have answered questions showing I have smoked "Cigarettes"
30+
And I have answered questions showing I currently smoke "Cigarettes"
2831
When I go to "/cigarettes-smoked-total-years"
2932
Then I see a back link to "/cigarettes-smoking-current"
3033
When I fill in "Roughly how many years have you smoked cigarettes?" with "9"

features/smoking_frequency.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ Feature: Smoking frequency page
55
Given I am logged in
66
And I have answered questions showing I am eligible
77
And I have answered questions showing I have smoked "Cigarettes"
8+
And I have answered questions showing I currently smoke "Cigarettes"
89
When I go to "/cigarettes-smoking-frequency"
910
Then there are no accessibility violations
1011

1112
Scenario: Form errors
1213
Given I am logged in
1314
And I have answered questions showing I am eligible
1415
And I have answered questions showing I have smoked "Cigarettes"
16+
And I have answered questions showing I currently smoke "Cigarettes"
1517
When I go to "/cigarettes-smoking-frequency"
1618
And I click "Continue"
1719
Then I am on "/cigarettes-smoking-frequency"

features/steps/preflight_steps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,5 @@ def given_i_have_answered_questions_showing_i_have_changed_frequency_of_smoked_t
147147
def given_i_have_answered_questions_showing_i_have_changed_amount_of_smoked_tobacco_type(context, level, tobacco_type, amount):
148148
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(context, tobacco_type)
149149
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoked-{level}-amount")
150-
screenshot(context)
151150
when_i_fill_in_label_with_value(context, f"roughly how many {tobacco_type.lower()} did you normally smoke a", amount, exact=False)
152151
when_i_submit_the_form(context)

lung_cancer_screening/questions/forms/mixins/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from functools import cached_property
2+
3+
from lung_cancer_screening.questions.presenters.tobacco_smoking_history_presenter import TobaccoSmokingHistoryPresenter
4+
5+
class SmokingFormPresenter:
6+
@cached_property
7+
def presenter(self):
8+
return TobaccoSmokingHistoryPresenter(self.tobacco_smoking_history)
9+
10+
@cached_property
11+
def normal_presenter(self):
12+
return TobaccoSmokingHistoryPresenter(self.normal_tobacco_smoking_history)
13+

lung_cancer_screening/questions/forms/smoked_amount_form.py

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from ...nhsuk_forms.integer_field import IntegerField
44
from ..models.smoked_amount_response import SmokedAmountResponse
55

6+
from .mixins.smoking_form_presenter import SmokingFormPresenter
67

7-
class SmokedAmountForm(forms.ModelForm):
8+
9+
class SmokedAmountForm(SmokingFormPresenter, forms.ModelForm):
810

911
def __init__(self, tobacco_smoking_history, normal_tobacco_smoking_history = None, *args, **kwargs):
1012
self.tobacco_smoking_history = tobacco_smoking_history
@@ -13,83 +15,77 @@ def __init__(self, tobacco_smoking_history, normal_tobacco_smoking_history = Non
1315
super().__init__(*args, **kwargs)
1416

1517
self.fields["value"] = IntegerField(
16-
label=self._type_label(),
18+
label=self.label(),
1719
label_classes="nhsuk-label--m" if self.tobacco_smoking_history.is_normal() else "nhsuk-label--l",
1820
label_is_page_heading=not self.tobacco_smoking_history.is_normal(),
1921
classes="nhsuk-input--width-4",
2022
hint="Give an estimate if you are not sure",
2123
suffix=self.suffix(),
2224
required=True,
2325
error_messages={
24-
"required": self._type_required_error_message(),
25-
"min_value": self._type_min_value_error_message()
26+
"required": self.required_error_message(),
27+
"min_value": self.min_value_error_message()
2628
},
2729
)
2830

2931

30-
def type_string(self):
31-
return self.tobacco_smoking_history.human_type().lower()
32-
33-
def more_or_fewer_text(self):
34-
if self.tobacco_smoking_history.is_increased():
35-
return "more"
36-
elif self.tobacco_smoking_history.is_decreased():
37-
return "fewer"
38-
39-
def amount_prefix(self):
40-
return "grams of " if self.tobacco_smoking_history.is_rolling_tobacco() else ""
41-
4232
def suffix(self):
43-
return "grams" if self.tobacco_smoking_history.is_rolling_tobacco() else self.tobacco_smoking_history.unit()
33+
return "grams" if self.tobacco_smoking_history.is_rolling_tobacco() else self.presenter.unit()
4434

4535

46-
def _normal_type_label(self):
47-
return f"Roughly how many {self.tobacco_smoking_history.unit()} do you {self._currently_or_previously_text()} smoke in a normal {self.tobacco_smoking_history.frequency_singular()}?"
36+
def normal_label(self):
37+
return (
38+
f"Roughly how many {self.presenter.unit()} "
39+
f"{self.presenter.do_or_did()} you "
40+
f"{self.presenter.currently_or_previously()} smoke in a normal "
41+
f"{self.presenter.frequency()}?"
42+
)
4843

4944

50-
def _changed_type_label(self):
45+
def changed_label(self):
5146
return (
52-
f"When you smoked {self.more_or_fewer_text()} than "
53-
f"{self.normal_tobacco_smoking_history.amount()} {self.tobacco_smoking_history.unit()} "
54-
f"a {self.normal_tobacco_smoking_history.frequency_singular()}, "
55-
f"roughly how many {self.tobacco_smoking_history.unit()} "
56-
f"did you normally smoke a {self.tobacco_smoking_history.frequency_singular()}?"
47+
f"When you smoked {self.presenter.more_or_fewer()} than "
48+
f"{self.normal_presenter.to_sentence()}, "
49+
f"roughly how many {self.presenter.unit()} "
50+
f"did you normally smoke a {self.presenter.frequency()}?"
5751
)
5852

5953

60-
def _type_label(self):
61-
if self.normal_tobacco_smoking_history:
62-
return self._changed_type_label()
54+
def label(self):
55+
if self.tobacco_smoking_history.is_normal():
56+
return self.normal_label()
6357
else:
64-
return self._normal_type_label()
58+
return self.changed_label()
6559

6660

67-
def _currently_or_previously_text(self):
68-
return "currently" if self.tobacco_smoking_history.smoking_current_response.value else "previously"
69-
70-
71-
def _normal_type_required_error_message(self):
72-
return f"Enter how many {self.amount_prefix()}{self.type_string()} you {self._currently_or_previously_text()} smoke in a normal {self.tobacco_smoking_history.frequency_singular()}"
73-
61+
def normal_required_error_message(self):
62+
return (
63+
f"Enter how many {self.presenter.unit()} you "
64+
f"{self.presenter.currently_or_previously()} {self.presenter.smoke_or_smoked()} "
65+
f"in a normal {self.presenter.frequency()}"
66+
)
7467

75-
def _changed_type_required_error_message(self):
68+
def changed_required_error_message(self):
7669
return (
77-
f"Enter the number of {self.amount_prefix()}{self.type_string()} "
78-
f"you smoked when you smoked {self.more_or_fewer_text()} than "
79-
f"{self.normal_tobacco_smoking_history.amount()} {self.amount_prefix()}{self.type_string()} "
80-
f"a {self.normal_tobacco_smoking_history.frequency_singular()}"
70+
f"Enter the number of {self.presenter.unit()} "
71+
f"you smoked when you smoked {self.presenter.more_or_fewer()} than "
72+
f"{self.normal_presenter.to_sentence()}"
8173
)
8274

8375

84-
def _type_required_error_message(self):
76+
def required_error_message(self):
8577
if self.normal_tobacco_smoking_history:
86-
return self._changed_type_required_error_message()
78+
return self.changed_required_error_message()
8779
else:
88-
return self._normal_type_required_error_message()
80+
return self.normal_required_error_message()
8981

9082

91-
def _type_min_value_error_message(self):
92-
return f"The number of {self.type_string()} you smoke must be at least 1"
83+
def min_value_error_message(self):
84+
return (
85+
f"The number of {self.presenter.unit()} you "
86+
f"{self.presenter.smoke_or_smoked()} a {self.presenter.frequency()} "
87+
"must be at least 1"
88+
)
9389

9490
class Meta:
9591
model = SmokedAmountResponse

lung_cancer_screening/questions/forms/smoked_total_years_form.py

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from ...nhsuk_forms.integer_field import IntegerField
44
from ..models.smoked_total_years_response import SmokedTotalYearsResponse
5+
from .mixins.smoking_form_presenter import SmokingFormPresenter
56

67

7-
class SmokedTotalYearsForm(forms.ModelForm):
8-
9-
def __init__(self, tobacco_smoking_history,*args, **kwargs):
8+
class SmokedTotalYearsForm(SmokingFormPresenter, forms.ModelForm):
9+
def __init__(self, tobacco_smoking_history, *args, **kwargs):
1010
self.tobacco_smoking_history = tobacco_smoking_history
1111
super().__init__(*args, **kwargs)
1212

@@ -20,35 +20,97 @@ def __init__(self, tobacco_smoking_history,*args, **kwargs):
2020
suffix="years",
2121
error_messages={
2222
"required": self.required_error_message(),
23-
"invalid": "Years must be in whole numbers"
23+
"invalid": "Years must be in whole numbers",
24+
"min_value": self.min_value_error_message(),
25+
"max_value": self.greater_than_years_smoked_error_message()
2426
},
2527
)
2628

29+
2730
def normal_label(self):
2831
return (
29-
f"Roughly how many years have you smoked "
30-
f"{self.tobacco_smoking_history.human_type().lower()}?"
32+
f"Roughly how many years {self.presenter.have_you_smoked_or_did_you_smoke()} "
33+
f"{self.presenter.human_type().lower()}?"
3134
)
3235

36+
3337
def changed_label(self):
3438
return (
35-
f"Roughly how many years did you smoke {self.tobacco_smoking_history.amount()} "
36-
f"{self.tobacco_smoking_history.unit()} "
37-
f"a {self.tobacco_smoking_history.frequency_singular()}?"
39+
f"Roughly how many years did you smoke {self.presenter.to_sentence()}?"
3840
)
3941

42+
4043
def label(self):
4144
if self.tobacco_smoking_history.is_normal():
4245
return self.normal_label()
4346
else:
4447
return self.changed_label()
4548

49+
50+
def normal_required_error_message(self):
51+
have_text = "have " if self.presenter.is_present_tense() else ""
52+
return (
53+
f"Enter the number of years you {have_text}smoked "
54+
f"{self.presenter.human_type().lower()}"
55+
)
56+
57+
58+
def changed_required_error_message(self):
59+
return (
60+
"Enter the number of years you smoked "
61+
f"{self.presenter.to_sentence()}"
62+
)
63+
64+
4665
def required_error_message(self):
66+
if self.tobacco_smoking_history.is_normal():
67+
return self.normal_required_error_message()
68+
else:
69+
return self.changed_required_error_message()
70+
71+
72+
def normal_min_value_error_message(self):
73+
return (
74+
"The number of years you smoked "
75+
f"{self.presenter.human_type().lower()} must be at least 1"
76+
)
77+
78+
79+
def changed_min_value_error_message(self):
80+
return (
81+
"The number of years you smoked "
82+
f"{self.presenter.to_sentence()} must be at least 1"
83+
)
84+
85+
86+
def min_value_error_message(self):
87+
if self.tobacco_smoking_history.is_normal():
88+
return self.normal_min_value_error_message()
89+
else:
90+
return self.changed_min_value_error_message()
91+
92+
93+
def normal_greater_than_years_smoked_error_message(self):
4794
return (
48-
"Enter the number of years you have smoked "
49-
f"{self.tobacco_smoking_history.unit()}"
95+
f"The number of years you smoked {self.presenter.human_type().lower()} "
96+
"must equal to, or fewer than, the total number of years you smoked"
5097
)
5198

99+
100+
def changed_greater_than_years_smoked_error_message(self):
101+
return (
102+
f"The number of years you smoked {self.presenter.to_sentence()} "
103+
"must equal to, or fewer than, the total number of years you have been smoking"
104+
)
105+
106+
107+
def greater_than_years_smoked_error_message(self):
108+
if self.tobacco_smoking_history.is_normal():
109+
return self.normal_greater_than_years_smoked_error_message()
110+
else:
111+
return self.changed_greater_than_years_smoked_error_message()
112+
113+
52114
class Meta:
53115
model = SmokedTotalYearsResponse
54116
fields = ['value']

0 commit comments

Comments
 (0)