Skip to content
Draft
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
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
@@ -0,0 +1,27 @@
from django import forms

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_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"))
}
)
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>

<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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 6.0.3 on 2026-03-31 14:46

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0009_alter_sexatbirthresponse_value_alter_user_nhs_number'),
]

operations = [
migrations.CreateModel(
name='WhenYouQuitSmokingResponse',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('value', models.IntegerField()),
('response_set', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='questions.responseset')),
],
options={
'abstract': False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 6.0.3 on 2026-03-31 15:05

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('questions', '0010_whenyouquitsmokingresponse'),
]

operations = [
migrations.AlterField(
model_name='whenyouquitsmokingresponse',
name='response_set',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='when_you_quit_smoking_response', to='questions.responseset'),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ def is_eligible(self):

def is_current_smoker(self):
return self.value == HaveYouEverSmokedValues.YES_I_CURRENTLY_SMOKE.value


def is_former_smoker(self):
return self.value == HaveYouEverSmokedValues.YES_I_USED_TO_SMOKE_REGULARLY.value
10 changes: 10 additions & 0 deletions lung_cancer_screening/questions/models/response_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def _response_attrs(self):
if hasattr(self, 'family_history_lung_cancer') and self.family_history_lung_cancer.is_truthy():
response_attrs.append('relatives_age_when_diagnosed')

if self.former_smoker():
response_attrs.append('when_you_quit_smoking_response')

return response_attrs


Expand Down Expand Up @@ -170,3 +173,10 @@ def current_smoker(self):
return None

return self.have_you_ever_smoked_response.is_current_smoker()


def former_smoker(self):
if not hasattr(self, 'have_you_ever_smoked_response'):
return None

return self.have_you_ever_smoked_response.is_former_smoker()
Loading
Loading