Skip to content

Commit bd7722e

Browse files
committed
Start of imperial height
1 parent b7e2302 commit bd7722e

File tree

9 files changed

+83
-15
lines changed

9 files changed

+83
-15
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ def fill_in_and_submit_date_of_birth(page, age):
2323

2424
page.click("text=Continue")
2525

26-
def fill_in_and_submit_height(page, height):
26+
def fill_in_and_submit_height_metric(page, height):
2727
expect(page.locator("h1")).to_have_text("What is your height?")
2828

2929
page.get_by_label("Centimetre").fill(str(height))
3030

3131
page.click("text=Continue")
32+
33+
def fill_in_and_submit_height_imperial(page, feet, inches):
34+
expect(page.locator("h1")).to_have_text("What is your height?")
35+
36+
page.get_by_label("Feet").fill(str(feet))
37+
page.get_by_label("Inches").fill(str(inches))
38+
39+
page.click("text=Continue")

lung_cancer_screening/core/tests/acceptance/test_cannot_change_answers_after_submission.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from dateutil.relativedelta import relativedelta
66

77
from .helpers.user_interaction_helpers import (
8-
fill_in_and_submit_height,
8+
fill_in_and_submit_height_metric,
9+
fill_in_and_submit_height_imperial,
910
fill_in_and_submit_participant_id,
1011
fill_in_and_submit_smoking_eligibility,
1112
fill_in_and_submit_date_of_birth
@@ -38,7 +39,7 @@ def test_cannot_change_responses_once_checked_and_submitted(self):
3839
fill_in_and_submit_participant_id(page, participant_id)
3940
fill_in_and_submit_smoking_eligibility(page, smoking_status)
4041
fill_in_and_submit_date_of_birth(page, age)
41-
fill_in_and_submit_height(page, "170")
42+
fill_in_and_submit_height_metric(page, "170")
4243

4344
page.click("text=Submit")
4445

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from dateutil.relativedelta import relativedelta
66

77
from .helpers.user_interaction_helpers import (
8-
fill_in_and_submit_height,
8+
fill_in_and_submit_height_imperial,
9+
fill_in_and_submit_height_metric,
910
fill_in_and_submit_participant_id,
1011
fill_in_and_submit_smoking_eligibility,
1112
fill_in_and_submit_date_of_birth
@@ -33,6 +34,8 @@ def test_full_questionnaire_user_journey(self):
3334
smoking_status = 'Yes, I used to smoke regularly'
3435
age = datetime.now() - relativedelta(years=55)
3536
height = "170"
37+
feet = 5
38+
inches = 7
3639

3740
page = self.browser.new_page()
3841
page.goto(f"{self.live_server_url}/start")
@@ -51,10 +54,18 @@ def test_full_questionnaire_user_journey(self):
5154

5255
expect(page).to_have_url(f"{self.live_server_url}/height")
5356

54-
fill_in_and_submit_height(page, height)
57+
fill_in_and_submit_height_metric(page, height)
5558

5659
expect(page).to_have_url(f"{self.live_server_url}/responses")
5760

61+
page.click("text=Back")
62+
63+
expect(page).to_have_url(f"{self.live_server_url}/height")
64+
65+
page.click("text=Switch to imperial")
66+
67+
fill_in_and_submit_height_imperial(page, feet, inches)
68+
5869
responses = page.locator(".responses")
5970
expect(responses).to_contain_text("Have you ever smoked? Yes, I used to smoke regularly")
6071
expect(responses).to_contain_text(
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import decimal
2+
from django import forms
3+
4+
from lung_cancer_screening.core.form_fields import DecimalField
5+
from ..models.response_set import ResponseSet
6+
7+
class MetricHeightForm(forms.ModelForm):
8+
9+
def __init__(self, *args, **kwargs):
10+
self.participant = kwargs.pop('participant')
11+
super().__init__(*args, **kwargs)
12+
self.instance.participant = self.participant
13+
14+
self.fields["height_feet"] = DecimalField(
15+
label="Feet",
16+
classes="nhsuk-input--width-4",
17+
)
18+
19+
self.fields["height_inches"] = DecimalField(
20+
label="Inches",
21+
classes="nhsuk-input--width-4",
22+
)
23+
24+
def clean_height(self):
25+
data = self.cleaned_data['height_feet']*12 + self.cleaned_data['height_inches']
26+
return data*2.54
27+
28+
class Meta:
29+
model = ResponseSet
30+
fields = ['height']

lung_cancer_screening/questions/forms/height_form.py renamed to lung_cancer_screening/questions/forms/metric_height_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from lung_cancer_screening.core.form_fields import DecimalField
55
from ..models.response_set import ResponseSet
66

7-
class HeightForm(forms.ModelForm):
7+
class MetricHeightForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
self.participant = kwargs.pop('participant')

lung_cancer_screening/questions/jinja2/height.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
"classes": "nhsuk-label--m"
2828
}
2929
}) %}
30+
3031
{{ form.height.as_field_group() }}
32+
33+
<a href="?unit={{ switch_to_unit }}">Switch to {{ switch_to_unit }}</a>
34+
3135
{% endcall %}
3236

3337
{{ button({

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
{% extends 'layout.jinja' %}
22
{% from 'nhsuk/components/button/macro.jinja' import button %}
3+
{% from 'nhsuk/components/back-link/macro.jinja' import backLink %}
34

4-
{% block content %}
5+
{% block beforeContent %}
6+
{{
7+
backLink({
8+
"href": url("questions:height"),
9+
"text": "Back"
10+
})
11+
}}
12+
{% endblock beforeContent %}
13+
14+
{% block page_content %}
515
<div class="nhsuk-grid-row">
616
<div class="nhsuk-grid-column-two-thirds">
717
<h1 class="nhsuk-heading-l">Responses</h1>

lung_cancer_screening/questions/tests/unit/forms/test_height_form.py renamed to lung_cancer_screening/questions/tests/unit/forms/test_metric_height_form.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from django.test import TestCase
22

33
from ....models.participant import Participant
4-
from ....forms.height_form import HeightForm
4+
from ....forms.metric_height_form import MetricHeightForm
55

66

7-
class TestHeightForm(TestCase):
7+
class TestMetricHeightForm(TestCase):
88
def setUp(self):
99
self.participant = Participant.objects.create(unique_id="1234567890")
1010

1111
def test_cm_to_mm(self):
1212
height = "170.4"
13-
form = HeightForm(
13+
form = MetricHeightForm(
1414
participant=self.participant,
1515
data={
1616
"height": height
@@ -22,7 +22,7 @@ def test_cm_to_mm(self):
2222
self.assertEqual(form.cleaned_data["height"], 1704)
2323

2424
def test_is_invalid(self):
25-
form = HeightForm(
25+
form = MetricHeightForm(
2626
participant=self.participant,
2727
data={
2828
"height": "invalid"

lung_cancer_screening/questions/views/height.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django.shortcuts import render, redirect
22
from django.core.exceptions import ValidationError
33

4-
from lung_cancer_screening.questions.forms.height_form import HeightForm
4+
from lung_cancer_screening.questions.forms.metric_height_form import MetricHeightForm
55
from lung_cancer_screening.questions.models import participant
66

77
from .decorators.participant_decorators import require_participant
88

99
@require_participant
1010
def height(request):
1111
if request.method == "POST":
12-
form = HeightForm(
12+
form = MetricHeightForm(
1313
instance = request.participant.responseset_set.last(),
1414
data=request.POST,
1515
participant=request.participant
@@ -26,9 +26,13 @@ def height(request):
2626
{ "form" : form },
2727
status=422
2828
)
29-
29+
unit = request.GET.get('unit')
3030
return render(
3131
request,
3232
"height.jinja",
33-
{ "form" : HeightForm(participant=request.participant) }
33+
{
34+
"form" : MetricHeightForm(participant=request.participant),
35+
"unit" : unit,
36+
"switch_to_unit" : "metric" if unit == "imperial" else "imperial"
37+
}
3438
)

0 commit comments

Comments
 (0)