Skip to content

Commit 5c14382

Browse files
committed
Refactor acceptance tests into helpers
1 parent b7cd870 commit 5c14382

File tree

7 files changed

+60
-70
lines changed

7 files changed

+60
-70
lines changed

lung_cancer_screening/core/tests/acceptance/helpers/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from playwright.sync_api import expect
2+
3+
def fill_in_and_submit_participant_id(page, participant_id):
4+
page.fill("input[name='participant_id']", participant_id)
5+
page.click('text=Start now')
6+
7+
8+
def fill_in_and_submit_smoking_elligibility(page, smoking_status):
9+
expect(page.locator("legend")).to_have_text(
10+
"Have you ever smoked?")
11+
12+
page.get_by_label(smoking_status).check()
13+
14+
page.click("text=Continue")
15+
16+
def fill_in_and_submit_date_of_birth(page, age):
17+
expect(page.locator("legend")).to_have_text(
18+
"What is your date of birth?")
19+
20+
page.get_by_label("Day").fill(str(age.day))
21+
page.get_by_label("Month").fill(str(age.month))
22+
page.get_by_label("Year").fill(str(age.year))
23+
24+
page.click("text=Continue")

lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py

Whitespace-only changes.

lung_cancer_screening/core/tests/acceptance/test_participant_not_smoker.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
from playwright.sync_api import sync_playwright, expect
44

55

6+
from .helpers.user_interaction_helpers import (
7+
fill_in_and_submit_participant_id,
8+
fill_in_and_submit_smoking_elligibility
9+
)
10+
11+
612
class TestParticipantNotSmoker(StaticLiveServerTestCase):
713

814
@classmethod
@@ -24,18 +30,8 @@ def test_participant_not_smoker(self):
2430
page = self.browser.new_page()
2531
page.goto(f"{self.live_server_url}/start")
2632

27-
page.fill("input[name='participant_id']", participant_id)
28-
29-
page.click('text=Start now')
30-
31-
expect(page).to_have_url(f"{self.live_server_url}/have-you-ever-smoked")
32-
33-
expect(page.locator("legend")).to_have_text(
34-
"Have you ever smoked?")
35-
36-
page.get_by_label('No, I have never smoked').check()
37-
38-
page.click("text=Continue")
33+
fill_in_and_submit_participant_id(page, participant_id)
34+
fill_in_and_submit_smoking_elligibility(page, 'No, I have never smoked')
3935

4036
expect(page).to_have_url(f"{self.live_server_url}/non-smoker-exit")
4137

lung_cancer_screening/core/tests/acceptance/test_participant_out_of_age_range.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from datetime import datetime
55
from dateutil.relativedelta import relativedelta
66

7+
from .helpers.user_interaction_helpers import (
8+
fill_in_and_submit_participant_id,
9+
fill_in_and_submit_smoking_elligibility,
10+
fill_in_and_submit_date_of_birth
11+
)
12+
713

814
class TestParticipantOutOfAgeRange(StaticLiveServerTestCase):
915

@@ -26,32 +32,11 @@ def test_participant_out_of_age_range(self):
2632
page = self.browser.new_page()
2733
page.goto(f"{self.live_server_url}/start")
2834

29-
page.fill("input[name='participant_id']", participant_id)
30-
31-
page.click('text=Start now')
32-
33-
expect(page).to_have_url(
34-
f"{self.live_server_url}/have-you-ever-smoked")
35-
36-
expect(page.locator("legend")).to_have_text(
37-
"Have you ever smoked?")
38-
39-
page.get_by_label('Yes, I used to smoke regularly').check()
40-
41-
page.click("text=Continue")
42-
43-
expect(page).to_have_url(f"{self.live_server_url}/date-of-birth")
44-
45-
expect(page.locator("legend")).to_have_text(
46-
"What is your date of birth?")
35+
fill_in_and_submit_participant_id(page, participant_id)
36+
fill_in_and_submit_smoking_elligibility(page, 'Yes, I used to smoke regularly')
4737

4838
age = datetime.now() - relativedelta(years=20)
49-
50-
page.get_by_label("Day").fill(str(age.day))
51-
page.get_by_label("Month").fill(str(age.month))
52-
page.get_by_label("Year").fill(str(age.year))
53-
54-
page.click("text=Continue")
39+
fill_in_and_submit_date_of_birth(page, age)
5540

5641
expect(page).to_have_url(f"{self.live_server_url}/age-range-exit")
5742

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from datetime import datetime
55
from dateutil.relativedelta import relativedelta
66

7+
from .helpers.user_interaction_helpers import (
8+
fill_in_and_submit_participant_id,
9+
fill_in_and_submit_smoking_elligibility,
10+
fill_in_and_submit_date_of_birth
11+
)
12+
713
class TestQuestionnaire(StaticLiveServerTestCase):
814

915
@classmethod
@@ -21,36 +27,22 @@ def tearDownClass(cls):
2127

2228
def test_full_questionaire_user_journey(self):
2329
participant_id = '123'
30+
smoking_status = 'Yes, I used to smoke regularly'
31+
age = datetime.now() - relativedelta(years=55)
2432

2533
page = self.browser.new_page()
2634
page.goto(f"{self.live_server_url}/start")
2735

28-
page.fill("input[name='participant_id']", participant_id)
29-
30-
page.click('text=Start now')
36+
fill_in_and_submit_participant_id(page, participant_id)
3137

3238
expect(page).to_have_url(
3339
f"{self.live_server_url}/have-you-ever-smoked")
3440

35-
expect(page.locator("legend")).to_have_text(
36-
"Have you ever smoked?")
37-
38-
page.get_by_label('Yes, I used to smoke regularly').check()
39-
40-
page.click("text=Continue")
41+
fill_in_and_submit_smoking_elligibility(page, smoking_status)
4142

4243
expect(page).to_have_url(f"{self.live_server_url}/date-of-birth")
4344

44-
expect(page.locator("legend")).to_have_text(
45-
"What is your date of birth?")
46-
47-
age = datetime.now() - relativedelta(years=55)
48-
49-
page.get_by_label("Day").fill(str(age.day))
50-
page.get_by_label("Month").fill(str(age.month))
51-
page.get_by_label("Year").fill(str(age.year))
52-
53-
page.click("text=Continue")
45+
fill_in_and_submit_date_of_birth(page, age)
5446

5547
expect(page).to_have_url(f"{self.live_server_url}/responses")
5648

lung_cancer_screening/core/tests/acceptance/test_questionnaire_validation_errors.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
33
from playwright.sync_api import sync_playwright, expect
44

5+
from .helpers.user_interaction_helpers import (
6+
fill_in_and_submit_participant_id,
7+
fill_in_and_submit_smoking_elligibility,
8+
fill_in_and_submit_date_of_birth
9+
)
10+
511
class TestQuestionnaireValidationErrors(StaticLiveServerTestCase):
612

713
@classmethod
@@ -23,21 +29,8 @@ def test_full_questionaire_user_journey_with_validation_errors(self):
2329
page = self.browser.new_page()
2430
page.goto(f"{self.live_server_url}/start")
2531

26-
page.fill("input[name='participant_id']", participant_id)
27-
28-
page.click('text=Start now')
29-
30-
expect(page).to_have_url(
31-
f"{self.live_server_url}/have-you-ever-smoked")
32-
33-
expect(page.locator("legend")).to_have_text(
34-
"Have you ever smoked?")
35-
36-
page.get_by_label('Yes, I currently smoke').check()
37-
38-
page.click("text=Continue")
39-
40-
expect(page).to_have_url(f"{self.live_server_url}/date-of-birth")
32+
fill_in_and_submit_participant_id(page, participant_id)
33+
fill_in_and_submit_smoking_elligibility(page, 'Yes, I currently smoke')
4134

4235
expect(page.locator("legend")).to_have_text(
4336
"What is your date of birth?")

0 commit comments

Comments
 (0)