Skip to content

Commit

Permalink
Use label instead of help text for query closing textarea accessibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Axon authored and stuaxo committed Feb 6, 2024
1 parent 0197c40 commit 945e7fe
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
14 changes: 1 addition & 13 deletions caseworker/cases/forms/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@

class CloseQueryForm(forms.Form):
reason_for_closing_query = forms.CharField(
label="",
label="Why are you closing the query? This will not be visible to the exporter.",
widget=forms.Textarea,
help_text="Why are you closing the query? This will not be visible to the exporter.",
required=False,
)

def use_hint_as_aria_labelledby(self, field_name):
"""
:param field_name: Name of the field to add an aria-labelledby attribute to.
Add an aria-labelledby attribute to a field's widget referencing the field's hint widget.
"""
field = self.fields[field_name]
label_id = (self.auto_id % self.prefix) + f"-{field_name}_hint"
field.widget.attrs["aria-labelledby"] = label_id

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout("reason_for_closing_query", Button("submit", "Submit"))
self.use_hint_as_aria_labelledby("reason_for_closing_query")
34 changes: 0 additions & 34 deletions unit_tests/caseworker/cases/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,37 +567,3 @@ def test_close_query_view_show_closed_queries_on_page(
assert data_query_closed_by_caseworker["question"] in str(closed_queries)
assert data_query_closed_by_caseworker["response"] in str(closed_queries)
assert data_query_closed_by_caseworker["responded_by_user_name"] in str(closed_queries)


def test_close_query_textarea_accessibility(
authorized_client,
requests_mock,
queue_pk,
standard_case_pk,
data_ecju_queries_gov_serializer,
data_query_closed_by_caseworker,
mock_get_queries,
):
expected_query_ids = [query_data["id"] for query_data in data_ecju_queries_gov_serializer["ecju_queries"]]

assert expected_query_ids # Test integrity: there should be some ids.

# see that the query is in the open queries section
url = reverse("cases:case", kwargs={"queue_pk": queue_pk, "pk": standard_case_pk, "tab": "ecju-queries"})
response = authorized_client.get(url)

soup = BeautifulSoup(response.content, "html.parser")
open_queries = soup.find(id="open-queries")

for query_id in expected_query_ids:
hint_widget = open_queries.find(
name=None, attrs={"class": "govuk-hint", "id": f"id_{query_id}-reason_for_closing_query_hint"}
)
textarea = open_queries.find("textarea", {"id": f"id_{query_id}-reason_for_closing_query"})
assert hint_widget is not None
assert textarea is not None

hint_widget_id = hint_widget["id"]

assert textarea["aria-labelledby"] == hint_widget_id
assert textarea["aria-describedby"] == hint_widget_id

0 comments on commit 945e7fe

Please sign in to comment.