Skip to content

Commit 87d3c3e

Browse files
committed
Adding cm height page with tests
1 parent 5ed909b commit 87d3c3e

File tree

7 files changed

+88
-4
lines changed

7 files changed

+88
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ def fill_in_and_submit_date_of_birth(page, age):
2222
page.get_by_label("Year").fill(str(age.year))
2323

2424
page.click("text=Continue")
25+
26+
def fill_in_and_submit_height(page, height):
27+
expect(page.locator("h1")).to_have_text("What is your height?")
28+
29+
page.get_by_label("Centimeter").fill(str(height))
30+
31+
page.click("text=Continue")

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dateutil.relativedelta import relativedelta
66

77
from .helpers.user_interaction_helpers import (
8+
fill_in_and_submit_height,
89
fill_in_and_submit_participant_id,
910
fill_in_and_submit_smoking_elligibility,
1011
fill_in_and_submit_date_of_birth

lung_cancer_screening/core/tests/unit/__init__.py

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{% extends 'layout.jinja' %}
2+
{% from 'nhsuk/components/button/macro.jinja' import button %}
3+
{% from 'nhsuk/components/back-link/macro.jinja' import backLink %}
4+
{% from 'nhsuk/components/input/macro.jinja' import input %}
5+
{% from 'nhsuk/components/fieldset/macro.jinja' import fieldset %}
6+
7+
{% block beforeContent %}
8+
{{
9+
backLink({
10+
"href": url("questions:date_of_birth"),
11+
"text": "Back"
12+
})
13+
}}
14+
{% endblock beforeContent %}
15+
16+
{% block page_content %}
17+
<div class="nhsuk-grid-row">
18+
<div class="nhsuk-grid-column-two-thirds">
19+
<form action="{{ request.path }}" method="POST">
20+
{{ csrf_input }}
21+
<h1 class="nhsuk-heading-l">What is your height?</h1>
22+
<p>An accurate measurement is important.
23+
24+
<p>You can measure your height at home with a measuring tape. Some pharmacies and gyms have machines to measure your height.
25+
{% call fieldset({
26+
"legend": {
27+
"text": "Enter your height",
28+
"classes": "nhsuk-label--m"
29+
}
30+
}) %}
31+
{{
32+
input({
33+
"id": "height",
34+
"name": "height",
35+
"label": {
36+
"text": "Centimetres",
37+
},
38+
"classes": "nhsuk-input--width-4"
39+
})
40+
}}
41+
{% endcall %}
42+
43+
{{ button({
44+
"text": "Continue"
45+
}) }}
46+
</form>
47+
</div>
48+
</div>
49+
{% endblock %}

lung_cancer_screening/questions/models/response_set.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class ResponseSet(BaseModel):
2424
date_of_birth = models.DateField(null=True, blank=True)
2525

2626
height = models.PositiveIntegerField(null=True, blank=True, validators=[
27-
MinValueValidator(1397, message="Height must be between 139.7cm and 243.8 cm"), # Minimum height in cm
28-
#models.Max(210) # Maximum height in cm
27+
MinValueValidator(1397, message="Height must be between 139.7cm and 243.8 cm"),
28+
MaxValueValidator(2438, message="Height must be between 139.7cm and 243.8 cm"),
2929
])
3030

31+
#height_type
32+
3133
submitted_at = models.DateTimeField(null=True, blank=True)
3234

3335
class Meta:

lung_cancer_screening/questions/views/height.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ def height(request):
99
if request.method == "POST":
1010
response_set = request.participant.responseset_set.last()
1111

12-
response_set.height = request.POST.get("height")
12+
height = request.POST.get("height")
13+
14+
if height.isdigit() and int(height) > 0 :
15+
height = int(height)*10
16+
response_set.height = height
17+
#response_set.height_type = request.POST.get("height_type")
1318
try:
1419
response_set.save()
1520
return redirect("questions:responses")
1621
except ValidationError:
1722
return render(
1823
request,
1924
"height.jinja",
20-
#{ "error": "Please enter a valid height in cm." },
2125
status=422
2226
)
2327

scripts/tests/ui.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
# This file is for you! Edit it to call your unit test suite. Note that the same
8+
# file will be called if you run it locally as if you run it on CI.
9+
10+
# Replace the following line with something like:
11+
#
12+
# rails test:unit
13+
# python manage.py test
14+
# npm run test
15+
#
16+
# or whatever is appropriate to your project. You should *only* run your fast
17+
# tests from here. If you want to run other test suites, see the predefined
18+
# tasks in scripts/test.mk.
19+
20+
docker compose run --rm --remove-orphans web poetry run python manage.py test lung_cancer_screening.core.tests.acceptance
21+

0 commit comments

Comments
 (0)