Skip to content

Commit 3d14a2f

Browse files
LGA 3373 Why were you treated differently (#78)
* Update discrimination where form to allow multiple selections * Update discrimination why form to allow for multiple selections * Introduce functional tests for onward routing * Fix ruff formatting
1 parent ad74f38 commit 3d14a2f

File tree

3 files changed

+91
-32
lines changed

3 files changed

+91
-32
lines changed

app/categories/discrimination/forms.py

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from wtforms import RadioField, SelectMultipleField
2-
from app.categories.widgets import CategoryRadioInput, CategoryCheckboxInput
1+
from wtforms import SelectMultipleField
2+
from app.categories.widgets import CategoryCheckboxInput
33
from app.categories.forms import QuestionForm
44
from wtforms.validators import InputRequired
55

@@ -21,7 +21,11 @@ class DiscriminationWhereForm(DiscriminationQuestionForm):
2121
widget=CategoryCheckboxInput(
2222
show_divider=True, hint_text="You can select more than one."
2323
),
24-
validators=[InputRequired(message="Select where the discrimination happened")],
24+
validators=[
25+
InputRequired(
26+
message="Select where the discrimination happened, or select ‘I’m not sure’"
27+
)
28+
],
2529
choices=[
2630
("work", "Work - including colleagues, employer or employment agency"),
2731
("school", "School, college, university or other education setting"),
@@ -43,38 +47,39 @@ class DiscriminationWhereForm(DiscriminationQuestionForm):
4347

4448

4549
class DiscriminationWhyForm(DiscriminationQuestionForm):
46-
title = "Why were you treated differently?"
50+
title = "Why were you discriminated against?"
4751

4852
next_step_mapping = {
49-
"race": "categories.results.in_scope",
50-
"sex": "categories.results.in_scope",
51-
"disability": "categories.results.in_scope",
52-
"religion": "categories.results.in_scope",
53-
"age": "categories.results.in_scope",
54-
"sexualorientation": "categories.results.in_scope",
55-
"gender": "categories.results.in_scope",
56-
"pregnancy": "categories.results.in_scope",
57-
"none": "categories.results.alternative_help",
53+
"*": "categories.results.in_scope",
54+
"none": "categories.results.refer",
5855
}
5956

60-
question = RadioField(
57+
question = SelectMultipleField(
6158
title,
62-
widget=CategoryRadioInput(show_divider=True),
63-
validators=[InputRequired(message="Select why you were treated differently")],
59+
widget=CategoryCheckboxInput(
60+
show_divider=True, hint_text="You can select more than one."
61+
),
62+
validators=[InputRequired(message="Select why you were discriminated against")],
6463
choices=[
65-
("race", "Race, colour of skin, ethnicity"),
64+
("race", "Race, colour, ethnicity, nationality"),
6665
("sex", "Sex (male or female)"),
6766
("disability", "Disability, health condition, mental health condition"),
6867
("religion", "Religion, belief, lack of religion"),
6968
("age", "Age"),
70-
("sexualorientation", "Sexual orientation - gay, bi, other sexuality"),
71-
("gender", "Gender - trans, gender reassignment, other gender issue"),
7269
("pregnancy", "Pregnancy or being a mother"),
70+
(
71+
"sexualorientation",
72+
"Sexual orientation - gay, bisexual, other sexuality",
73+
),
74+
(
75+
"gender",
76+
"Gender reassignment, being transgender, non-binary or gender-fluid",
77+
),
7378
(
7479
"marriage",
75-
"Married status - being married, in a civil partnership, unmarried",
80+
"Married status - being married, in a civil partnership",
7681
),
7782
("", ""),
78-
("none", "None of the above"),
83+
("none", "None of these"),
7984
],
8085
)

app/categories/views.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ def get_next_page(self, answer: str) -> redirect:
104104
Raises:
105105
ValueError if the answer does not have a mapping to a next page
106106
"""
107+
optional_answers = [
108+
"notsure",
109+
"none",
110+
] # We should only route to these pages if they are the only answer
107111

108-
if "notsure" in answer and len(answer) == 1:
109-
return redirect(url_for(self.form_class.next_step_mapping["notsure"]))
112+
if len(answer) == 1 and answer[0] in optional_answers:
113+
return redirect(url_for(self.form_class.next_step_mapping[answer[0]]))
110114

111115
if isinstance(answer, list):
112116
for a in answer:
113-
if a in self.form_class.next_step_mapping and a != "notsure":
117+
if a in self.form_class.next_step_mapping and a not in optional_answers:
114118
return redirect(url_for(self.form_class.next_step_mapping[a]))
115119
answer = "*"
116120

tests/functional_tests/categories/discrimination/test_discrimination.py

+58-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
from playwright.sync_api import Page, expect
22
import pytest
33

4-
routing = [
4+
where_form_routing = [
55
pytest.param(
6-
["Work - including colleagues,"], "Why were you treated", id="single_answer"
6+
["Work - including colleagues,"],
7+
"Why were you discriminated against",
8+
id="single_answer",
79
),
810
pytest.param(
911
["Work - including colleagues,", "School, college, university"],
10-
"Why were you treated",
12+
"Why were you discriminated against",
1113
id="multiple_answers",
1214
),
1315
pytest.param(["not sure"], "Referral page", id="not_sure"),
1416
pytest.param(
15-
["Health or care", "not sure"], "Why were you treated", id="not_sure_and_answer"
17+
["Health or care", "not sure"],
18+
"Why were you discriminated against",
19+
id="not_sure_and_answer",
1620
),
1721
]
1822

1923

2024
@pytest.mark.usefixtures("live_server")
21-
@pytest.mark.parametrize("selections,expected_heading", routing)
22-
def test_discrimination_where_single_answer(
23-
page: Page, selections: list, expected_heading: str
24-
):
25+
@pytest.mark.parametrize("selections,expected_heading", where_form_routing)
26+
def test_discrimination_where(page: Page, selections: list, expected_heading: str):
2527
"""
2628
Test the discrimination form with different combinations of selections.
2729
@@ -40,3 +42,51 @@ def test_discrimination_where_single_answer(
4042
page.get_by_role("button", name="Continue").click()
4143

4244
expect(page.get_by_text(expected_heading)).to_be_visible()
45+
46+
47+
why_form_routing = [
48+
pytest.param(
49+
["Race, colour, ethnicity, nationality"],
50+
"Legal aid is available",
51+
id="single_answer",
52+
),
53+
pytest.param(
54+
[
55+
"Disability, health condition, mental health condition",
56+
"Religion, belief, lack of religion",
57+
],
58+
"Legal aid is available",
59+
id="multiple_answers",
60+
),
61+
pytest.param(["None of these"], "Referral page", id="not_sure"),
62+
pytest.param(
63+
["Religion, belief, lack of religion", "None of these"],
64+
"Legal aid is available",
65+
id="not_sure_and_answer",
66+
),
67+
]
68+
69+
70+
@pytest.mark.usefixtures("live_server")
71+
@pytest.mark.parametrize("selections,expected_heading", why_form_routing)
72+
def test_discrimination_why(page: Page, selections: list, expected_heading: str):
73+
"""
74+
Test the discrimination form with different combinations of selections.
75+
76+
Args:
77+
page: Playwright page fixture
78+
selections: List of labels to check
79+
expected_heading: Text expected to be visible after submission
80+
"""
81+
page.get_by_role("link", name="Discrimination").click()
82+
page.get_by_label("Work - including colleagues,").check()
83+
page.get_by_role("button", name="Continue").click()
84+
85+
# Check all selected options
86+
for selection in selections:
87+
page.get_by_label(selection).check()
88+
89+
# Submit form
90+
page.get_by_role("button", name="Continue").click()
91+
92+
expect(page.get_by_text(expected_heading)).to_be_visible()

0 commit comments

Comments
 (0)