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
4 changes: 2 additions & 2 deletions features/age_when_started_smoking.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Feature: Age when started smoking
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 "/periods-when-you-stopped-smoking?change=True"
Then I am on "/check-your-answers"

Scenario: Checking responses and changing them as a former smoker
Given I am logged in
Expand All @@ -67,4 +67,4 @@ Feature: Age when started smoking
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"
Then I am on "/check-your-answers"
9 changes: 1 addition & 8 deletions features/questionnaire.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ Feature: Questionnaire
When I check "Cigarettes"
And I submit the form

Then I am on "/cigarettes-smoking-current"
When I check "Yes" and submit

Then I am on "/cigarettes-smoked-total-years"
When I fill in "Roughly how many years have you smoked cigarettes?" with "10"
And I submit the form

Then I am on "/cigarettes-smoking-frequency"
When I check "Daily" and submit

Expand Down Expand Up @@ -113,7 +106,7 @@ Feature: Questionnaire
And I see "18" as a response to "Age you started smoking" under "Smoking history"
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 smoked cigarettes" under "Smoking history"
And I see "37" as a response to "Total number of years you 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"
Expand Down
3 changes: 3 additions & 0 deletions features/smoked_amount.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
Expand All @@ -12,6 +13,7 @@ Feature: Smoked amount page
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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
Expand All @@ -23,6 +25,7 @@ Feature: Smoked amount page
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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked "Cigarettes" daily
When I go to "/cigarettes-smoked-amount"
Expand Down
2 changes: 1 addition & 1 deletion features/smoked_total_years.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Smoked total years page
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"
And I have answered questions showing I have smoked "Cigarettes, Pipe"
And I have answered questions showing I currently smoke "Cigarettes"
When I go to "/cigarettes-smoked-total-years"
And I click "Continue"
Expand Down
3 changes: 3 additions & 0 deletions features/smoking_change.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Feature: Smoking change 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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
When I go to "/cigarettes-smoking-change"
Expand All @@ -11,6 +12,7 @@ Feature: Smoking change page
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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
When I go to "/cigarettes-smoking-change"
Expand All @@ -25,6 +27,7 @@ Feature: Smoking change page
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 for "10" years
And I have answered questions showing I currently smoke "Cigarettes"
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
When I go to "/cigarettes-smoking-change"
Expand Down
4 changes: 3 additions & 1 deletion features/smoking_current.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Feature: Smoking current 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 for "10" years
And I have answered questions showing I have smoked "Cigarettes"
When I go to "/cigarettes-smoking-current"
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"
And I have answered questions showing I have smoked for "10" years
And I have answered questions showing I have smoked "Cigarettes, Pipe"
When I go to "/cigarettes-smoking-current"
And I click "Continue"
Then I am on "/cigarettes-smoking-current"
Expand Down
6 changes: 4 additions & 2 deletions features/smoking_frequency.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: Smoking frequency 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 for "10" years
And I have answered questions showing I have smoked "Cigarettes"
And I have answered questions showing I currently smoke "Cigarettes"
When I go to "/cigarettes-smoking-frequency"
Expand All @@ -12,6 +13,7 @@ Feature: Smoking frequency page
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 for "10" years
And I have answered questions showing I have smoked "Cigarettes"
And I have answered questions showing I currently smoke "Cigarettes"
When I go to "/cigarettes-smoking-frequency"
Expand All @@ -25,15 +27,15 @@ Feature: Smoking frequency page
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 currently smoke "Cigarettes"
And I have answered questions showing I have smoked "Cigarettes"
When I go to "/cigarettes-smoking-frequency"
Then I see a back link to "/cigarettes-smoked-total-years"
Then I see a back link to "/types-tobacco-smoking"
When I check "Daily" and submit
Then I am on "/cigarettes-smoked-amount"

Scenario: When I say that I have increased the amount I smoke I am shown the correct page
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 currently smoke "Cigarettes"
And I have answered questions showing I have smoked 10 "Cigarettes" "daily"
And I have answered questions showing I have "increased" my level of "Cigarettes" smoking from "10 cigarettes a day"
Expand Down
11 changes: 1 addition & 10 deletions features/smoking_history.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ Feature: Smoking history pages
And I have answered questions showing I have smoked for "30" years
When I go to "/types-tobacco-smoking"
And I check "Cigarettes"
And I check "Cigarettes"
And I submit the form

Then I am on "/cigarettes-smoking-current"
When I check "Yes"
And I submit the form

Then I am on "/cigarettes-smoked-total-years"
When I fill in "Roughly how many years have you smoked cigarettes?" with "15"
And I submit the form

Then I am on "/cigarettes-smoking-frequency"
Expand Down Expand Up @@ -55,7 +46,7 @@ Feature: Smoking history pages
And I submit the form

Then I am on "/check-your-answers"
Then I see "15 years" as a response to "Total number of years you smoked cigarettes" under "Cigarette smoking history"
Then I see "30 years" as a response to "Total number of years you smoked cigarettes" under "Cigarette smoking history"
And I see "10 cigarettes a day" as a response to "Current cigarette smoking" under "Cigarette smoking history"
And I see "200 cigarettes a week for 5 years" as a response to "When you smoked more than 10 cigarettes a day" under "Cigarette smoking history"
And I see "1 cigarettes a month for 2 years" as a response to "When you smoked fewer than 10 cigarettes a day" under "Cigarette smoking history"
Expand Down
4 changes: 2 additions & 2 deletions features/steps/navigation_steps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from behave import when, then
from behave import when, then, step
from playwright.sync_api import expect


@when('I go to "{path}"')
@step('I go to "{path}"')
def given_i_go_to(context, path):
context.page.goto(f"{context.live_server_url}{path}")

Expand Down
5 changes: 5 additions & 0 deletions features/steps/preflight_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def given_i_have_answered_questions_showing_i_am_aged_60_years_old(context, year
context.page.goto(f"{context.live_server_url}/date-of-birth")
when_i_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years)

@given("I have answered questions showing I quit smoking at \"{years}\" years old")
def given_i_have_answered_questions_showing_i_quit_smoking_at_years_old(context, years):
context.page.goto(f"{context.live_server_url}/when-you-quit-smoking")
when_i_fill_in_label_with_value(context, "How old were you when you quit smoking?", years)
when_i_submit_the_form(context)

@given('I have answered questions showing I stopped smoking for "{years}" years')
def given_i_have_answered_questions_showing_i_stopped_smoking_for_years_years(context, years):
Expand Down
32 changes: 31 additions & 1 deletion features/types_tobacco_smoking.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,45 @@ Feature: Types tobacco smoking page
And I see a form error "Select the type of tobacco you smoke or have smoked"
And there are no accessibility violations

Scenario: Navigating backwards and forwards
Scenario: Current smokers 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 for "10" years
When I go to "/types-tobacco-smoking"
Then I see a back link to "/periods-when-you-stopped-smoking"
When I check "Cigarettes"
And I submit the form
Then I am on "/cigarettes-smoking-frequency"
When I click "Back"
Then I am on "/types-tobacco-smoking"
And I see "Cigarettes" selected
When I check "Pipe"
And I click "Continue"
Then I am on "/cigarettes-smoking-current"
And I see a back link to "/types-tobacco-smoking"

Scenario: Former smokers 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 aged "70" years old
And I have answered questions showing I am a former smoker
And I have answered questions showing I have smoked for "50" years
And I have answered questions showing I quit smoking at "50" years old
And I go to "/check-your-answers"
And I take a screenshot
When I go to "/types-tobacco-smoking"
Then I see a back link to "/periods-when-you-stopped-smoking"
When I check "Cigarettes"
And I take a screenshot
And I submit the form
Then I am on "/cigarettes-smoking-frequency"
When I click "Back"
Then I am on "/types-tobacco-smoking"
And I see "Cigarettes" selected
When I check "Pipe"
And I click "Continue"
Then I am on "/cigarettes-smoked-total-years"
And I see a back link to "/types-tobacco-smoking"

Scenario: Checking responses and changing them
Given I am logged in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django import forms

from lung_cancer_screening.questions.models.smoked_total_years_response import SmokedTotalYearsResponse
from lung_cancer_screening.questions.models.smoking_current_response import SmokingCurrentResponse

from ...nhsuk_forms.choice_field import MultipleChoiceField
from ..models.tobacco_smoking_history import (
TobaccoSmokingHistory,
Expand Down Expand Up @@ -81,4 +84,26 @@ def _create_types_selected(self):

TobaccoSmokingHistory.objects.bulk_create(instances)

self._create_default_responses_for_single_selection()

return instances

def _create_default_responses_for_single_selection(self):
response_set = self.response_set
instances = response_set.tobacco_smoking_history.normal()
if instances.count() == 1:
instance = instances.first()

SmokingCurrentResponse.objects.update_or_create(
tobacco_smoking_history=instance,
defaults={
"value": response_set.current_smoker()
},
)

SmokedTotalYearsResponse.objects.update_or_create(
tobacco_smoking_history=instance,
defaults={
"value": response_set.age_when_started_smoking_response.years_smoked_including_stopped()
}
)
Comment thread
jamiefalcus marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.test import TestCase, tag

from ...factories.age_when_started_smoking_response_factory import AgeWhenStartedSmokingResponseFactory

from ...factories.response_set_factory import ResponseSetFactory
from ...factories.tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory
from ...factories.have_you_ever_smoked_response_factory import HaveYouEverSmokedResponseFactory
from ....models.tobacco_smoking_history import (
TobaccoSmokingHistoryTypes,
)
Expand Down Expand Up @@ -102,6 +105,9 @@ def test_saves_an_tobacco_smoking_type_for_each_value_selected(self):
def test_does_not_create_a_new_tobacco_smoking_type_if_it_already_exists(self):
TobaccoSmokingHistoryFactory(response_set=self.response_set, cigarettes=True)

HaveYouEverSmokedResponseFactory(response_set=self.response_set, current_smoker=True)
AgeWhenStartedSmokingResponseFactory(response_set=self.response_set, value=20)

form = TypesTobaccoSmokingForm(
response_set=self.response_set,
data={
Expand All @@ -116,6 +122,10 @@ def test_does_not_create_a_new_tobacco_smoking_type_if_it_already_exists(self):
def test_deletes_a_tobacco_smoking_type_if_it_is_no_longer_selected(self):
TobaccoSmokingHistoryFactory(response_set=self.response_set, cigarettes=True)

HaveYouEverSmokedResponseFactory(response_set=self.response_set, current_smoker=True)

AgeWhenStartedSmokingResponseFactory(response_set=self.response_set, value=20)

form = TypesTobaccoSmokingForm(
response_set=self.response_set,
data={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_redirects_to_periods_when_you_stopped_smoking_as_a_current_smoker_if_ch

self.assertRedirects(
response,
reverse("questions:periods_when_you_stopped_smoking", query={"change": "True"})
reverse("questions:responses")
)


Expand Down Expand Up @@ -195,7 +195,7 @@ def test_redirects_to_when_you_quit_smoking_as_a_former_smoker_if_change_query_p

self.assertRedirects(
response,
reverse("questions:when_you_quit_smoking", query={"change": "True"})
reverse("questions:responses")
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ def test_responds_successfully(self):

self.assertEqual(response.status_code, 200)

def test_back_link_normal_level(self):
def test_back_link_normal_level_multiple_types(self):
self.tobacco_smoking_history = TobaccoSmokingHistoryFactory.create(
response_set=self.response_set,
cigarettes=True,
pipe=True,
complete=True
)

response = self.client.get(reverse("questions:smoking_frequency", kwargs = {
"tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower()
}))
Expand All @@ -96,6 +103,16 @@ def test_back_link_normal_level(self):
"/cigarettes-smoked-total-years",
)

def test_back_link_normal_level_single_type(self):
response = self.client.get(reverse("questions:smoking_frequency", kwargs = {
"tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower()
}))

self.assertEqual(
response.context_data["back_link_url"],
"/types-tobacco-smoking",
)

def test_back_link_increased_level(self):
TobaccoSmokingHistoryFactory.create(
response_set=self.response_set,
Expand Down
Loading
Loading