Skip to content

Commit 44806d0

Browse files
committed
Show question asked and responses in response template
1 parent ea5caad commit 44806d0

28 files changed

+536
-82
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
3+
from playwright.sync_api import sync_playwright, expect
4+
5+
6+
class TestParticipantNotSmoker(StaticLiveServerTestCase):
7+
8+
@classmethod
9+
def setUpClass(cls):
10+
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
11+
super().setUpClass()
12+
cls.playwright = sync_playwright().start()
13+
cls.browser = cls.playwright.chromium.launch()
14+
15+
@classmethod
16+
def tearDownClass(cls):
17+
super().tearDownClass()
18+
cls.browser.close()
19+
cls.playwright.stop()
20+
21+
def test_participant_not_smoker(self):
22+
participant_id = '123'
23+
24+
page = self.browser.new_page()
25+
page.goto(f"{self.live_server_url}/start")
26+
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').check()
37+
38+
page.click("text=Continue")
39+
40+
expect(page).to_have_url(f"{self.live_server_url}/non-smoker-exit")
41+
42+
expect(page.locator(".title")).to_have_text(
43+
"You do not need an NHS lung health check")

lung_cancer_screening/core/tests/acceptance/test_user_out_of_age_range.py renamed to lung_cancer_screening/core/tests/acceptance/test_participant_out_of_age_range.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dateutil.relativedelta import relativedelta
66

77

8-
class TestQuestionnaire(StaticLiveServerTestCase):
8+
class TestParticipantOutOfAgeRange(StaticLiveServerTestCase):
99

1010
@classmethod
1111
def setUpClass(cls):
@@ -30,6 +30,16 @@ def test_participant_out_of_age_range(self):
3030

3131
page.click('text=Start now')
3232

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').check()
40+
41+
page.click("text=Continue")
42+
3343
expect(page).to_have_url(f"{self.live_server_url}/date-of-birth")
3444

3545
expect(page.locator("legend")).to_have_text(

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ def test_full_questionaire_user_journey(self):
2929

3030
page.click('text=Start now')
3131

32+
expect(page).to_have_url(
33+
f"{self.live_server_url}/have-you-ever-smoked")
34+
35+
expect(page.locator("legend")).to_have_text(
36+
"Have you ever smoked?")
37+
38+
page.get_by_label('Yes').check()
39+
40+
page.click("text=Continue")
41+
3242
expect(page).to_have_url(f"{self.live_server_url}/date-of-birth")
3343

3444
expect(page.locator("legend")).to_have_text(
@@ -44,4 +54,6 @@ def test_full_questionaire_user_journey(self):
4454

4555
expect(page).to_have_url(f"{self.live_server_url}/responses")
4656

47-
expect(page.locator(".responses")).to_have_text(age.strftime("%Y-%m-%d"))
57+
expect(page.locator(".responses")).to_contain_text(
58+
age.strftime("Have you ever smoked? True"))
59+
expect(page.locator(".responses")).to_contain_text(age.strftime("What is your date of birth? %Y-%m-%d"))

lung_cancer_screening/questions/jinja2/date_of_birth.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<div class="nhsuk-grid-column-two-thirds">
99
<form action="{{ request.path }}" method="POST">
1010
{{ csrf_input }}
11+
1112
{{ dateInput({
1213
"fieldset": {
1314
"legend": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{% extends 'layout.jinja' %}
2+
{% from 'button/macro.jinja' import button %}
3+
{% from 'radios/macro.jinja' import radios %}
4+
5+
{% block content %}
6+
<div class="nhsuk-grid-row">
7+
<div class="nhsuk-grid-column-two-thirds">
8+
<form action="{{ request.path }}" method="POST">
9+
{{ csrf_input }}
10+
11+
{{ radios({
12+
"name": "value",
13+
"fieldset": {
14+
"legend": {
15+
"text": "Have you ever smoked?",
16+
"classes": "nhsuk-fieldset__legend--l",
17+
"isPageHeading": true
18+
}
19+
},
20+
"items": [
21+
{
22+
"value": "1",
23+
"text": "Yes"
24+
},
25+
{
26+
"value": "0",
27+
"text": "No"
28+
}
29+
]
30+
}) }}
31+
32+
<input type="hidden" name="participant_id" value="{{ participant_id }}">
33+
34+
{{ button({
35+
"text": "Continue"
36+
}) }}
37+
</form>
38+
</div>
39+
</div>
40+
{% endblock %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends 'layout.jinja' %}
2+
{% from 'button/macro.jinja' import button %}
3+
{% from 'input/macro.jinja' import input %}
4+
5+
{% block content %}
6+
<div class="nhsuk-grid-row">
7+
<div class="nhsuk-grid-column-two-thirds">
8+
<h2 class="title">You do not need an NHS lung health check</h2>
9+
10+
<p>The NHS lung health check is for people who have smoked or are current smokers.</p>
11+
</div>
12+
</div>
13+
{% endblock %}

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<div class="nhsuk-grid-column-two-thirds">
77
<h1 class="nhsuk-heading-l">Responses</h1>
88
<ul class="responses">
9-
{% for questionnaire_response in questionnaire_responses %}
10-
<li>{{ questionnaire_response.value }}</li>
9+
{% for response in responses %}
10+
<li>{{ response.question }} {{ response.value }}</li>
1111
{% endfor %}
1212
</ul>
1313
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.2.4 on 2025-09-03 16:03
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('questions', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='BooleanResponse',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('created_at', models.DateTimeField(auto_now_add=True)),
19+
('updated_at', models.DateTimeField(auto_now=True)),
20+
('value', models.BooleanField()),
21+
('participant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='questions.participant')),
22+
],
23+
options={
24+
'abstract': False,
25+
},
26+
),
27+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.2.4 on 2025-09-04 10:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('questions', '0002_booleanresponse'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='BooleanResponse',
15+
name='question',
16+
field=models.CharField(null='Have you ever smoked?', max_length=255),
17+
preserve_default=False,
18+
),
19+
migrations.AddField(
20+
model_name='QuestionnaireResponse',
21+
name='question',
22+
field=models.CharField(default='What is your date of birth?', max_length=255),
23+
preserve_default=False,
24+
),
25+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.4 on 2025-09-04 10:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('questions', '0003_booleanresponse_question_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RenameModel(
14+
old_name='QuestionnaireResponse',
15+
new_name='DateResponse',
16+
),
17+
18+
]

0 commit comments

Comments
 (0)