Skip to content

Commit 3804ad5

Browse files
committed
Migrate full questionnaire journey to behave
1 parent d60f0b6 commit 3804ad5

File tree

5 files changed

+112
-163
lines changed

5 files changed

+112
-163
lines changed

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Feature: Questionnaire
2+
Scenario: The user can complete the full questionnaire
3+
When I go to "/start"
4+
And I submit my participant id
5+
Then I am on "/have-you-ever-smoked"
6+
And I see a back link to "/start"
7+
When I fill in and submit my smoking status with "Yes, I used to smoke regularly"
8+
Then I am on "/date-of-birth"
9+
And I see a back link to "/have-you-ever-smoked"
10+
When I fill in and submit my date of birth as 55 years ago
11+
Then I am on "/height"
12+
And I see a back link to "/date-of-birth"
13+
When I fill in and submit my height with "170"
14+
And I click "Back"
15+
And I click "Switch to imperial"
16+
When I fill in and submit my height with "5" feet and "7" inches
17+
Then I am on "/weight"
18+
And I see a back link to "/height"
19+
When I fill in and submit my weight with "70"
20+
And I click "Back"
21+
And I click "Switch to stone and pounds"
22+
When I fill in and submit my weight with "5" stone and "10" pounds
23+
Then I am on "/sex-at-birth"
24+
And I see a back link to "/weight"
25+
When I fill in and submit my sex at birth with "Male"
26+
Then I am on "/gender"
27+
And I see a back link to "/sex-at-birth"
28+
When I fill in and submit my gender with "Female"
29+
Then I am on "/ethnicity"
30+
And I see a back link to "/gender"
31+
When I fill in and submit my ethnicity with "White"
32+
Then I am on "/education"
33+
And I see a back link to "/ethnicity"
34+
When I click "Continue"
35+
Then I am on "/respiratory-conditions"
36+
And I see a back link to "/education"
37+
When I fill in and submit my respiratory conditions with "Pneumonia" and "Emphysema"
38+
Then I am on "/asbestos-exposure"
39+
And I see a back link to "/respiratory-conditions"
40+
When I fill in and submit my asbestos exposure with "No"
41+
Then I am on "/cancer-diagnosis"
42+
And I see a back link to "/asbestos-exposure"
43+
When I click "Continue"
44+
Then I am on "/family-history-lung-cancer"
45+
And I see a back link to "/cancer-diagnosis"
46+
When I click "Continue"
47+
Then I am on "/responses"
48+
And I see a back link to "/family-history-lung-cancer"
49+
And I see responses "Have you ever smoked? Yes, I used to smoke regularly"
50+
And I see responses "What is your date of birth?" with a date 55 years ago
51+
And I see responses "What is your height? 5 feet 7 inches"
52+
And I see responses "What is your weight? 5 stone 10 pounds"
53+
And I see responses "What was your sex at birth? Male"
54+
And I see responses "Which of these best describes you? Female"
55+
And I see responses "What is your ethnic background? White"
56+
And I see responses "Have you ever worked in a job where you might have been exposed to asbestos? No"
57+
And I see responses "Have you ever been diagnosed with any of the following respiratory conditions? Pneumonia, Emphysema"

tests/features/steps/form_steps.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from behave import when
2+
from datetime import datetime
3+
from dateutil.relativedelta import relativedelta
24

35

46
@when('I submit my participant id')
57
def when_I_submit_my_participant_id(context):
8+
if not hasattr(context, 'participant_id'):
9+
context.participant_id = 'abc123'
610
context.page.fill('input[name="participant_id"]', context.participant_id)
711
context.page.click('button[type="submit"]')
812

@@ -19,6 +23,14 @@ def when_I_fill_in_and_submit_my_date_of_birth(context, date_of_birth):
1923
context.page.get_by_label('Year').fill(year)
2024
context.page.click("text=Continue")
2125

26+
@when(u'I fill in and submit my date of birth as {years} years ago')
27+
def when_I_fill_in_and_submit_my_date_of_birth_as_x_years_ago(context, years):
28+
date_of_birth = datetime.now() - relativedelta(years=int(years))
29+
context.page.get_by_label('Day').fill(str(date_of_birth.day))
30+
context.page.get_by_label('Month').fill(str(date_of_birth.month))
31+
context.page.get_by_label('Year').fill(str(date_of_birth.year))
32+
context.page.click("text=Continue")
33+
2234
@when(u'I fill in and submit my height with "{height}"')
2335
def when_I_fill_in_and_submit_my_height(context, height):
2436
context.page.get_by_label('Centimetre').fill(height)
@@ -43,12 +55,32 @@ def stone_and_pounds(context, stone, pounds):
4355
context.page.get_by_label('Pounds').fill(pounds)
4456
context.page.click("text=Continue")
4557

58+
@when(u'I fill in and submit my sex at birth with "{sex_at_birth}"')
59+
def when_I_fill_in_and_submit_my_sex_at_birth(context, sex_at_birth):
60+
context.page.get_by_label(sex_at_birth, exact=True).check()
61+
context.page.click("text=Continue")
62+
63+
@when(u'I fill in and submit my gender with "{gender}"')
64+
def when_I_fill_in_and_submit_my_gender(context, gender):
65+
context.page.get_by_label(gender, exact=True).check()
66+
context.page.click("text=Continue")
67+
68+
@when(u'I fill in and submit my ethnicity with "{ethnicity}"')
69+
def when_I_fill_in_and_submit_my_ethnicity(context, ethnicity):
70+
context.page.get_by_label(ethnicity, exact=True).check()
71+
context.page.click("text=Continue")
72+
4673
@when(u'I fill in and submit my respiratory conditions with "{condition_a}" and "{condition_b}"')
4774
def when_I_fill_in_and_submit_my_respiratory_conditions(context, condition_a, condition_b):
4875
context.page.get_by_label(condition_a).check()
4976
context.page.get_by_label(condition_b).check()
5077
context.page.click("text=Continue")
5178

79+
@when(u'I fill in and submit my asbestos exposure with "{asbestos_exposure}"')
80+
def when_I_fill_in_and_submit_my_asbestos_exposure(context, asbestos_exposure):
81+
context.page.get_by_label(asbestos_exposure, exact=True).check()
82+
context.page.click("text=Continue")
83+
5284
@when('I submit the form')
5385
def when_I_submit_the_form(context):
5486
context.page.click("text=Continue")

tests/features/steps/navigation_steps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
def given_I_go_to(context, path):
77
context.page.goto(f"{context.live_server_url}{path}")
88

9+
@when('I click "{text}"')
10+
def when_I_click(context, text):
11+
context.page.click(f"text={text}")
12+
913
@then('I am on "{path}"')
1014
def then_I_am_on(context, path):
1115
expect(context.page).to_have_url(f"{context.live_server_url}{path}")
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
from behave import given, then
22
from playwright.sync_api import expect
3-
3+
from datetime import datetime
4+
from dateutil.relativedelta import relativedelta
45

56
@then(u'I see a title "{title}"')
67
def then_I_see_a_title(context, title):
78
expect(context.page.locator('.title')).to_have_text(title)
9+
10+
@then(u'I see a back link to "{url}"')
11+
def then_I_see_a_back_link_to(context, url):
12+
back_link = context.page.locator(".nhsuk-back-link")
13+
expect(back_link).to_have_count(1)
14+
expect(back_link).to_have_attribute("href", url)
15+
16+
@then(u'I see responses "{text}"')
17+
def then_I_see_responses(context, text):
18+
responses = context.page.locator(".responses")
19+
expect(responses).to_contain_text(text)
20+
21+
@then(u'I see responses "{text}" with a date {years} years ago')
22+
def then_I_see_responses_with_a_date(context, text, years):
23+
date_of_birth = datetime.now() - relativedelta(years=int(years))
24+
responses = context.page.locator(".responses")
25+
expect(responses).to_contain_text(f"{text} {date_of_birth.strftime('%Y-%m-%d')}")

0 commit comments

Comments
 (0)