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
1 change: 1 addition & 0 deletions features/age_when_started_smoking.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@AgeWhenStartedSmoking
Feature: Age when started smoking
Scenario: The page is accessible
Expand Down
1 change: 1 addition & 0 deletions features/periods_when_you_stopped_smoking.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@PeriodsWhenYouStoppedSmoking
Feature: Periods when you stopped smoking page
Scenario: The page is accessible
Expand Down
10 changes: 10 additions & 0 deletions features/questionnaire.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@Basic
@AgeWhenStartedSmoking
@SmokedTotalYears
@SmokedAmount
@SmokedChanged
@Questionnaire
Feature: Questionnaire
Scenario: Cannot change responses once submitted
Given I am logged in
Expand Down Expand Up @@ -79,6 +84,10 @@ Feature: Questionnaire
Then I am on "/cigarettes-smoking-frequency"
When I check "Daily" and submit

Then I am on "/cigarettes-smoked-amount"
When I fill in "Roughly how many cigarettes do you smoke in a normal day?" with "15"
And I submit the form

Then I am on "/check-your-answers"
And I see "Yes, I used to smoke" as a response to "Have you ever smoked tobacco?" under "Eligibility"
And I see a date 55 years ago as a response to "Date of birth" under "Eligibility"
Expand All @@ -100,6 +109,7 @@ Feature: Questionnaire
And I see "Yes (10 years)" as a response to "Have you ever stopped smoking for periods of 1 year or longer?" under "Smoking history"

And I see "10" as a response to "Total number of years you have smoked cigarettes" under "Smoking history"
And I see "15 cigarettes a day" as a response to "Current cigarette smoking" under "Smoking history"

When I click "Submit"
Then I am on "/confirmation"
48 changes: 48 additions & 0 deletions features/smoked_amount.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@SmokingHistory
@SmokedAmount
Feature: Smoked amount page
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 have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
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 have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
And I click "Continue"
Then I am on "/cigarettes-smoked-amount"
And I see a form error "Enter how many cigarettes you currently smoke in a normal day"
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 have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
Then I see a back link to "/cigarettes-smoked-total-years"
When I fill in "Roughly how many cigarettes do you smoke in a normal day?" with "20"
And I submit the form
Then I am on "/check-your-answers"

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 have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
When I fill in "Roughly how many cigarettes do you smoke in a normal day?" with "20"
And I submit the form
When I go to "/check-your-answers"
Then I see "20 cigarettes a day" as a response to "Current cigarette smoking" under "Smoking history"
And I see "/cigarettes-smoking-frequency?change=True" as a link to change "Current cigarette smoking" under "Smoking history"
When I click the link to change "Current cigarette smoking" under "Smoking history"
Then I am on "/cigarettes-smoking-frequency?change=True"
When I submit the form
Then I see "20" filled in for "Roughly how many cigarettes do you smoke in a normal day?"
When I fill in "Roughly how many cigarettes do you smoke in a normal day?" with "15"
And I click "Continue"
Then I am on "/check-your-answers"
And I see "15 cigarettes a day" as a response to "Current cigarette smoking" under "Smoking history"
8 changes: 5 additions & 3 deletions features/smoked_total_years.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@SmokedTotalYears
Feature: Smoked total years page
Scenario: The page is accessible
Expand Down Expand Up @@ -25,7 +26,7 @@ Feature: Smoked total years page
And I have answered questions showing I have smoked for "10" years
And I have answered questions showing I have smoked "Cigarettes"
When I go to "/cigarettes-smoked-total-years"
Then I see a back link to "/types-tobacco-smoking"
Then I see a back link to "/cigarettes-smoking-current"
When I fill in "Roughly how many years have you smoked cigarettes?" with "9"
And I submit the form
Then I am on "/cigarettes-smoking-frequency"
Expand All @@ -46,5 +47,6 @@ Feature: Smoked total years page
And I see "9" filled in for "Roughly how many years have you smoked cigarettes?"
When I fill in "Roughly how many years have you smoked cigarettes?" with "8"
And I click "Continue"
Then I am on "/check-your-answers"
And I see "8" as a response to "Total number of years you have smoked cigarettes" under "Smoking history"
Then I am on "/cigarettes-smoking-frequency?change=True"
When I go to "/check-your-answers"
Then I see "8" as a response to "Total number of years you have smoked cigarettes" under "Smoking history"
6 changes: 4 additions & 2 deletions features/smoking_current.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@SmokingCurrent
Feature: Smoking current page
Scenario: The page is accessible
Expand Down Expand Up @@ -39,5 +40,6 @@ Feature: Smoking current page
Then I am on "/cigarettes-smoking-current?change=True"
And I see "Yes" selected
When I check "No" and submit
Then I am on "/check-your-answers"
And I see "No" as a response to "Do you currently smoke cigarettes?" under "Smoking history"
Then I am on "/cigarettes-smoked-total-years?change=True"
When I go to "/check-your-answers"
Then I see "No" as a response to "Do you currently smoke cigarettes?" under "Smoking history"
18 changes: 11 additions & 7 deletions features/smoking_frequency.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@SmokingFrequency
Feature: Smoking frequency page
Scenario: The page is accessible
Expand Down Expand Up @@ -25,21 +26,24 @@ Feature: Smoking frequency page
When I go to "/cigarettes-smoking-frequency"
Then I see a back link to "/cigarettes-smoked-total-years"
When I check "Daily" and submit
Then I am on "/check-your-answers"
Then I am on "/cigarettes-smoked-amount"

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 have smoked for "10" years
And I have answered questions showing I have smoked "Cigarettes"
When I go to "/cigarettes-smoking-frequency"
When I check "Daily" and submit
And I check "Daily" and submit
And I fill in "Roughly how many cigarettes do you smoke in a normal day?" with "10"
And I submit the form
When I go to "/check-your-answers"
Then I see "Cigarettes a day" as a response to "Current cigarettes smoking" under "Smoking history"
And I see "/cigarettes-smoking-frequency?change=True" as a link to change "Current cigarettes smoking" under "Smoking history"
When I click the link to change "Current cigarettes smoking" under "Smoking history"
Then I see "10 cigarettes a day" as a response to "Current cigarette smoking" under "Smoking history"
And I see "/cigarettes-smoking-frequency?change=True" as a link to change "Current cigarette smoking" under "Smoking history"
When I click the link to change "Current cigarette smoking" under "Smoking history"
Then I am on "/cigarettes-smoking-frequency?change=True"
And I see "Daily" selected
When I check "Weekly" and submit
Then I am on "/check-your-answers"
And I see "Cigarettes a week" as a response to "Current cigarettes smoking" under "Smoking history"
Then I am on "/cigarettes-smoked-amount?change=True"
When I go to "/check-your-answers"
Then I see "10 cigarettes a week" as a response to "Current cigarette smoking" under "Smoking history"
9 changes: 9 additions & 0 deletions features/steps/preflight_steps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from behave import given
from inflection import humanize

from features.steps.form_steps import (
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago,
Expand Down Expand Up @@ -89,3 +90,11 @@ def given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(
when_i_check_label(context, tobacco_type.strip())

when_i_submit_the_form(context)


@given('I have answered questions showing I have smoked "{tobacco_type}" {frequency}')
def given_i_have_answered_questions_showing_i_have_smoked_tobacco_type_frequency(context, tobacco_type, frequency):
given_i_have_answered_questions_showing_i_have_smoked_tobacco_type(context, tobacco_type)
context.page.goto(f"{context.live_server_url}/{tobacco_type.lower()}-smoking-frequency")
when_i_check_label(context, humanize(frequency))
when_i_submit_the_form(context)
1 change: 1 addition & 0 deletions features/types_tobacco_smoking.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SmokingHistory
@TypesTobaccoSmoking
Feature: Types tobacco smoking page
Scenario: The page is accessible
Expand Down
6 changes: 6 additions & 0 deletions lung_cancer_screening/jinja2_env.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from django.conf import settings
from django.templatetags.static import static
from django.urls import reverse
from inflection import singularize
from jinja2 import ChoiceLoader, Environment, PackageLoader


def environment(**options):

env = Environment(**options, extensions=["jinja2.ext.do"])

if env.loader:
env.loader = ChoiceLoader(
[
Expand All @@ -27,4 +29,8 @@ def environment(**options):
{"static": static, "url": reverse, "STATIC_URL": settings.STATIC_URL}
)

env.filters.update(
{"singularize": singularize}
)

return env
44 changes: 44 additions & 0 deletions lung_cancer_screening/questions/forms/smoked_amount_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django import forms

from ...nhsuk_forms.integer_field import IntegerField
from ..models.smoked_amount_response import SmokedAmountResponse


class SmokedAmountForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
self.frequency_text = kwargs.pop("frequency_text", "day")

super().__init__(*args, **kwargs)

self.fields["value"] = IntegerField(
label=self._type_label(),
label_classes="nhsuk-label--m",
classes="nhsuk-input--width-4",
hint="Give an estimate if you are not sure",
suffix=self._type_suffix(),
required=True,
error_messages={
"required": self._type_required_error_message(),
"min_value": self._type_min_value_error_message()
},
)

def type_string(self):
return self.instance.tobacco_smoking_history.human_type().lower()

def _type_label(self):
return f"Roughly how many {self.type_string()} do you smoke in a normal {self.frequency_text}?"

def _type_required_error_message(self):
return f"Enter how many {self.type_string()} you currently smoke in a normal {self.frequency_text}"

def _type_min_value_error_message(self):
return f"The number of {self.type_string()} you smoke must be at least 1"

def _type_suffix(self):
return self.type_string()

class Meta:
model = SmokedAmountResponse
fields = ['value']
11 changes: 11 additions & 0 deletions lung_cancer_screening/questions/jinja2/smoked_amount.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'question_form.jinja' %}

{% block prelude %}

<h1 class="nhsuk-heading-l">{{ form.type_string() | title | singularize }} smoking</h1>

<p>This is a test of the online service. In the future, we will use this information to give you an accurate result.</p>

<p>The question on the next page will ask if the number of cigarettes you smoke has changed over time.</p>

{% endblock prelude %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 5.2.10

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


class Migration(migrations.Migration):

dependencies = [
(
"questions",
"0052_smokingfrequencyresponse",
),
]

operations = [
migrations.CreateModel(
name='SmokedAmountResponse',
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()),
('tobacco_smoking_history', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='smoked_amount_response', to='questions.tobaccosmokinghistory')),
],
options={
'abstract': False,
},
),
]
18 changes: 18 additions & 0 deletions lung_cancer_screening/questions/models/smoked_amount_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models
from django.core.validators import MinValueValidator

from .base import BaseModel
from .tobacco_smoking_history import TobaccoSmokingHistory


class SmokedAmountResponse(BaseModel):
tobacco_smoking_history = models.OneToOneField(
TobaccoSmokingHistory,
on_delete=models.CASCADE,
related_name='smoked_amount_response'
)
value = models.IntegerField(
validators=[
MinValueValidator(1)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ class SmokingFrequencyValues(models.TextChoices):
MONTHLY = "M", "Monthly"

class SmokingFrequencyResponse(BaseModel):
SINGULAR_TEXT_MAP = {
SmokingFrequencyValues.DAILY: "day",
SmokingFrequencyValues.WEEKLY: "week",
SmokingFrequencyValues.MONTHLY: "month",
}

tobacco_smoking_history = models.OneToOneField(
TobaccoSmokingHistory,
on_delete=models.CASCADE,
related_name='smoking_frequency_response'
)

value = models.CharField(
max_length=1,
choices=SmokingFrequencyValues.choices
)

def get_value_display_as_singleton_text(self):
return self.SINGULAR_TEXT_MAP.get(self.value)
Loading