Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions features/age_when_started_smoking.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,28 @@ Feature: Age when started smoking
Then I see a form error "The age you started smoking must be the same as, or less than your current age"
And there are no accessibility violations

Scenario: Navigating backwards and forwards
Scenario: Navigating backwards and forwards as a former smoker
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
When I go to "/age-when-started-smoking"
Then I see a back link to "/relatives-age-when-diagnosed"
When I fill in "How old were you when you started smoking?" as "18" and submit
Then I am on "/when-you-quit-smoking"

Scenario: Navigating backwards and forwards as a current smoker
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a current smoker
When I go to "/age-when-started-smoking"
Then I see a back link to "/relatives-age-when-diagnosed"
When I fill in "How old were you when you started smoking?" as "18" and submit
Then I am on "/periods-when-you-stopped-smoking"

Scenario: Checking responses and changing them
Scenario: Checking responses and changing them as a current smoker
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a current smoker
When I go to "/age-when-started-smoking"
And I fill in "How old were you when you started smoking?" as "18" and submit
When I go to "/check-your-answers"
Expand All @@ -42,3 +53,18 @@ Feature: Age when started smoking
And I see "18" filled in for "How old were you when you started smoking?"
When I fill in "How old were you when you started smoking?" as "22" and submit
Then I am on "/periods-when-you-stopped-smoking?change=True"

Scenario: Checking responses and changing them as a former smoker
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
When I go to "/age-when-started-smoking"
And I fill in "How old were you when you started smoking?" as "18" and submit
When I go to "/check-your-answers"
Then I see "18" as a response to "Age you started smoking" under "Smoking history"
And I see "/age-when-started-smoking?change=True" as a link to change "Age you started smoking" under "Smoking history"
When I click the link to change "Age you started smoking" under "Smoking History"
Then I am on "/age-when-started-smoking?change=True"
And I see "18" filled in for "How old were you when you started smoking?"
When I fill in "How old were you when you started smoking?" as "22" and submit
Then I am on "/when-you-quit-smoking?change=True"
97 changes: 2 additions & 95 deletions features/smoking_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Feature: Smoking history pages
And I see "2 cigarillos a month" as a response to "Current cigarillo smoking" under "Cigarillo smoking history"
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"

# Change cigarette smoking history with increased and decreased
# Change cigarette smoking history
When I click the link to change "Cigarette" smoking history

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

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

Then I am on "/cigarettes-smoking-decreased-frequency?change=True"
When I submit the form

Then I am on "/cigarettes-smoked-decreased-amount?change=True"
When I submit the form

Then I am on "/cigarettes-smoked-decreased-years?change=True"
When I submit the form

Then I am on "/check-your-answers"
When I go to "/check-your-answers"
Then I see "17 years" as a response to "Total number of years you smoked cigarettes" under "Cigarette smoking history"
And I see "25 cigarettes a month" as a response to "Current cigarette smoking" under "Cigarette smoking history"

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"

# Change medium cigars with decreased
Comment thread
jamiefalcus marked this conversation as resolved.
When I click the link to change "Medium cigar" smoking history

Then I am on "/medium-cigars-smoking-current?change=True"
When I submit the form

Then I am on "/medium-cigars-smoked-total-years?change=True"
When I submit the form

Then I am on "/medium-cigars-smoking-frequency?change=True"
When I submit the form

Then I am on "/medium-cigars-smoked-amount?change=True"
When I submit the form

Then I am on "/medium-cigars-smoking-change?change=True"
When I submit the form

Then I am on "/medium-cigars-smoking-decreased-frequency?change=True"
When I submit the form

Then I am on "/medium-cigars-smoked-decreased-amount?change=True"
When I submit the form

Then I am on "/medium-cigars-smoked-decreased-years?change=True"
When I submit the form

Then I am on "/check-your-answers"

# Change cigarillos with increased
When I click the link to change "Cigarillo" smoking history

Then I am on "/cigarillos-smoking-current?change=True"
When I submit the form

Then I am on "/cigarillos-smoked-total-years?change=True"
When I submit the form

Then I am on "/cigarillos-smoking-frequency?change=True"
When I submit the form

Then I am on "/cigarillos-smoked-amount?change=True"
When I submit the form

Then I am on "/cigarillos-smoking-change?change=True"
When I submit the form

Then I am on "/cigarillos-smoking-increased-frequency?change=True"
When I submit the form

Then I am on "/cigarillos-smoked-increased-amount?change=True"
When I submit the form

Then I am on "/cigarillos-smoked-increased-years?change=True"
When I submit the form

Then I am on "/check-your-answers"

# Change cigarettes change to no change
When I click the link to change "Cigarette" smoking history

Then I am on "/cigarettes-smoking-current?change=True"
When I submit the form

Then I am on "/cigarettes-smoked-total-years?change=True"
When I submit the form

Then I am on "/cigarettes-smoking-frequency?change=True"
When I submit the form

Then I am on "/cigarettes-smoked-amount?change=True"
When I submit the form

Then I am on "/cigarettes-smoking-change?change=True"
When I uncheck "Yes, I used to smoke more than 25 cigarettes a month"
And I uncheck "Yes, I used to smoke fewer than 25 cigarettes a month"
And I check "No, it has not changed"
When I submit the form

Then I am on "/check-your-answers"


3 changes: 1 addition & 2 deletions features/steps/accessibility_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def then_there_are_no_accessibility_violations(context):
axe_results = axe.run(context.page)
violations_msg = (
f"Found the following accessibility violations: \n"
# Use generate_report for more indepth information about the violations
f"{axe_results.generate_snapshot()}"
f"{axe_results.generate_report()}"
)
assert axe_results.violations_count == 0, violations_msg
14 changes: 10 additions & 4 deletions features/steps/preflight_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ def given_i_have_answered_questions_showing_i_am_eligible(context):
eligible=True,
)

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

when_i_check_label(context, "Yes, I currently smoke")
when_i_submit_the_form(context)
if current_or_former == "current":
when_i_check_label(context, "Yes, I currently smoke")
elif current_or_former == "former":
when_i_check_label(context, "Yes, I used to smoke")
else:
raise ValueError(f"Invalid current_or_former: {current_or_former}")

when_i_submit_the_form(context)

@given('I have answered questions showing I started smoking "{years}" years ago')
@given('I have answered questions showing I have smoked for "{years}" years')
def given_i_have_answered_questions_showing_i_have_smoked_for_years_years(context, years):
response_set = get_or_create_response_set(context)
Expand Down
51 changes: 51 additions & 0 deletions features/when_you_quit_smoking.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@SmokingHistory
@WhenYouQuitSmoking
Feature: Age quit smoking
Scenario: The page is accessible
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
And I am 60 years old
And I have answered questions showing I started smoking "30" years ago
When I go to "/age-when-started-smoking"
Then there are no accessibility violations

Scenario: Form errors
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
And I am 60 years old
And I have answered questions showing I started smoking "30" years ago
When I go to "/when-you-quit-smoking"
And I click "Continue"
Then I am on "/when-you-quit-smoking"
And I see a form error "Enter your age when you quit smoking"
And there are no accessibility violations

Scenario: Navigating backwards and forwards
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
And I am 60 years old
And I have answered questions showing I started smoking "30" years ago
When I go to "/when-you-quit-smoking"
Then I see a back link to "/age-when-started-smoking"
When I fill in "How old were you when you quit smoking?" as "30" and submit
Then I am on "/periods-when-you-stopped-smoking"

Scenario: Checking responses and changing them
Given I am logged in
And I have answered questions showing I am eligible
And I have answered questions showing I am a former smoker
And I am 60 years old
And I have answered questions showing I started smoking "30" years ago
When I go to "/when-you-quit-smoking"
And I fill in "How old were you when you quit smoking?" as "40" and submit
When I go to "/check-your-answers"
Then I see "40" as a response to "Age you quit smoking" under "Smoking history"
And I see "/when-you-quit-smoking?change=True" as a link to change "Age you quit smoking" under "Smoking history"
When I click the link to change "Age you quit smoking" under "Smoking History"
Then I am on "/when-you-quit-smoking?change=True"
And I see "40" filled in for "How old were you when you quit smoking?"
When I fill in "How old were you when you quit smoking?" as "45" and submit
Then I am on "/periods-when-you-stopped-smoking?change=True"
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
"invalid": "Enter your age when you started smoking",
"zero_entered":"The age you started smoking must be between 1 and your current age",
"age_started_smoking_greater_than_current_age":"The age you started smoking must be the same as, or less than your current age",
"no_date_of_birth" : format_html("<a href=\"{}\">Provide your date of birth</a> before answering this question", reverse_lazy("questions:date_of_birth"))
"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"))
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django import forms
from django.urls import reverse_lazy
from django.utils.html import format_html

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

coerce=lambda x: x == "True",
error_messages={
"required": self.required_error_message()
},
"required": self.required_error_message(),
"duration_years": self.duration_years_error_message()
Comment thread
jamiefalcus marked this conversation as resolved.
}
)

self.fields["duration_years"] = IntegerField(
Expand All @@ -36,6 +39,9 @@ def __init__(self, *args, **kwargs):
hint=self.duration_years_hint(),
required=False,
suffix="years",
error_messages={
"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"))
}
)

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


def label_is_page_heading(self):
Expand All @@ -82,24 +88,27 @@ def stopped_or_quit(self):
else:
return "stopped or quit "

def smoked_or_smoke(self):
if self.response_set().former_smoker():
return "smoked"
else:
return "have been smoking"

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


def duration_years_error_message(self):
return f"The number of years you stopped smoking must be fewer than the total number of years you {self.smoked_or_smoke()}"


def duration_years_required_error_message(self):
return f"Enter the total number of years you {self.stopped_or_quit()}smoking"


def duration_years_label(self):
if self.response_set().current_smoker():
return "Enter the total number of years you stopped smoking"
else:
return "Roughly how many years did you stop or quit smoking in total?"
return "Enter the total number of years you stopped smoking"


def duration_years_hint(self):
if self.response_set().current_smoker():
return "Give an estimate if you are not sure"
else:
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."
return "Give an estimate if you are not sure"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django import forms
from django.urls import reverse_lazy
from django.utils.html import format_html

from lung_cancer_screening.nhsuk_forms.integer_field import IntegerField
from ..models.when_you_quit_smoking_response import WhenYouQuitSmokingResponse

class WhenYouQuitSmokingForm(forms.ModelForm):
class Meta:
model = WhenYouQuitSmokingResponse
fields = ["value"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["value"] = IntegerField(
label="How old were you when you quit smoking?",
label_classes="nhsuk-label--m",
classes="nhsuk-input--width-2",
hint="Give an estimate if you are not sure",
prefix="Age",
error_messages={
"required": "Enter your age when you quit smoking",
"invalid": "Enter your age when you quit smoking",
"min_value":"The age you quit smoking must be between 1 and your current age",
"age_when_quit_smoking_greater_than_age_started":"The age you quit smoking cannot be lower than the age you started smoking",
Comment thread
jamiefalcus marked this conversation as resolved.
"age_when_quit_smoking_greater_than_current_age" : "The age you quit smoking must be the same as, or less than, your current age",
"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"))
}
)
11 changes: 11 additions & 0 deletions lung_cancer_screening/questions/jinja2/when_you_quit_smoking.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'question_form.jinja' %}

{% block pageTitle %}When did you quit smoking? – Check if you need a lung scan – NHS{% endblock %}

{% block prelude %}
<h1 class="nhsuk-heading-l">When you quit smoking?</h1>
Comment thread
jamiefalcus marked this conversation as resolved.

<p>If you stopped smoking more than once, tell us your age when you last quit smoking.</p>

<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>
{% endblock prelude %}
Loading
Loading