From 204a3570fec8ddeba6ab66625907f3abeb3ea71f Mon Sep 17 00:00:00 2001 From: petechd <53475968+petechd@users.noreply.github.com> Date: Thu, 30 May 2024 11:30:58 +0100 Subject: [PATCH] Add correct aria labels to change and remove actions on summaries (#1368) --- app/jinja_filters.py | 34 ++-- app/translations/messages.pot | 145 +++++++++--------- .../partials/summary/collapsible-summary.html | 2 +- templates/partials/summary/summary.html | 4 +- tests/app/test_jinja_filters.py | 30 ++-- 5 files changed, 111 insertions(+), 104 deletions(-) diff --git a/app/jinja_filters.py b/app/jinja_filters.py index 1c65af0dad..29d8af10df 100644 --- a/app/jinja_filters.py +++ b/app/jinja_filters.py @@ -434,10 +434,18 @@ def __init__( answer: SelectFieldBase._Option, item_title: str, edit_link_text: str, - edit_link_aria_label: str, + item_name: str | None = None, ) -> None: self.text = edit_link_text - self.visuallyHiddenText = edit_link_aria_label + " " + item_title + if item_name: + self.visuallyHiddenText = flask_babel.lazy_gettext( + "Change answer for {item_name}: {question_title_or_answer_label}" + ).format(item_name=item_name, question_title_or_answer_label=item_title) + else: + self.visuallyHiddenText = flask_babel.lazy_gettext( + "Change your answer for: {question_title_or_answer_label}" + ).format(question_title_or_answer_label=item_title) + self.url = answer["link"] self.attributes = { @@ -466,9 +474,9 @@ def __init__( # noqa: C901, R0912 pylint: disable=too-complex, too-many-branche answers_are_editable: bool, no_answer_provided: str, edit_link_text: str, - edit_link_aria_label: str, summary_type: str, use_answer_label: bool = False, + item_name: str | None = None, ) -> None: answer_type = answer.get("type", "calculated") if ( @@ -540,9 +548,7 @@ def __init__( # noqa: C901, R0912 pylint: disable=too-complex, too-many-branche if answers_are_editable: self.actions = [ - SummaryAction( - answer, self.rowTitle, edit_link_text, edit_link_aria_label - ) + SummaryAction(answer, self.rowTitle, edit_link_text, item_name) ] @@ -554,8 +560,8 @@ def __init__( answers_are_editable: bool, no_answer_provided: str, edit_link_text: str, - edit_link_aria_label: str, use_answer_label: bool = False, + item_name: str | None = None, ) -> None: self.rowTitle = strip_tags(question["title"]) self.id = question["id"] @@ -573,9 +579,9 @@ def __init__( answers_are_editable, no_answer_provided, edit_link_text, - edit_link_aria_label, summary_type, use_answer_label, + item_name, ) ) @@ -603,7 +609,6 @@ def map_summary_item_config( answers_are_editable, no_answer_provided, edit_link_text, - edit_link_aria_label, ) ) elif block.get("calculated_summary"): @@ -614,7 +619,6 @@ def map_summary_item_config( answers_are_editable, no_answer_provided, edit_link_text, - edit_link_aria_label, ) ) else: @@ -628,12 +632,13 @@ def map_summary_item_config( related_answers=block.get("related_answers"), item_label=block.get("item_label"), item_anchor=block.get("item_anchor"), + answers_are_editable=answers_are_editable, ) rows.extend(list_collector_rows) if is_summary_with_calculation(summary_type): - rows.append(SummaryRow(calculated_question, summary_type, False, "", "", "")) + rows.append(SummaryRow(calculated_question, summary_type, False, "", "")) return rows @@ -656,11 +661,12 @@ def map_list_collector_config( related_answers: dict | None = None, item_label: str | None = None, item_anchor: str | None = None, + answers_are_editable: bool = True, ) -> list[dict[str, list] | SummaryRow]: rows: list[dict[str, list] | SummaryRow] = [] for index, list_item in enumerate(list_items, start=1): - item_name = list_item.get("item_title") + item_name = str(list_item.get("item_title")) actions = [] edit_link_hidden_text = None @@ -731,11 +737,11 @@ def map_list_collector_config( summary_row = SummaryRow( block["question"], summary_type="SectionSummary", - answers_are_editable=True, + answers_are_editable=answers_are_editable, no_answer_provided=flask_babel.lazy_gettext("No answer provided"), edit_link_text=edit_link_text, - edit_link_aria_label=edit_link_aria_label, use_answer_label=True, + item_name=item_name, ) row_items.extend(summary_row.rowItems) diff --git a/app/translations/messages.pot b/app/translations/messages.pot index 0310115b70..469dc08389 100644 --- a/app/translations/messages.pot +++ b/app/translations/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-04-24 15:36+0100\n" +"POT-Creation-Date: 2024-05-21 12:29+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -41,7 +41,15 @@ msgstr "" msgid "%(from_date)s to %(to_date)s" msgstr "" -#: app/jinja_filters.py:732 +#: app/jinja_filters.py:441 +msgid "Change answer for {item_name}: {question_title_or_answer_label}" +msgstr "" + +#: app/jinja_filters.py:443 +msgid "Change your answer for: {question_title_or_answer_label}" +msgstr "" + +#: app/jinja_filters.py:734 #: templates/partials/summary/collapsible-summary.html:27 #: templates/partials/summary/summary.html:24 msgid "No answer provided" @@ -419,7 +427,7 @@ msgstr "" #: templates/individual_response/confirmation-text-message.html:39 #: templates/individual_response/question.html:5 templates/interstitial.html:7 #: templates/listcollectorcontent.html:6 templates/sectionsummary.html:11 -#: templates/sectionsummary.html:50 +#: templates/sectionsummary.html:51 msgid "Continue" msgstr "" @@ -509,7 +517,7 @@ msgstr "" #: app/views/handlers/confirm_email.py:128 #: app/views/handlers/confirmation_email.py:65 -#: app/views/handlers/feedback.py:78 app/views/handlers/question.py:173 +#: app/views/handlers/feedback.py:73 app/views/handlers/question.py:173 msgid "Error: {page_title}" msgstr "" @@ -517,39 +525,39 @@ msgstr "" msgid "Confirmation email" msgstr "" -#: app/views/handlers/feedback.py:44 +#: app/views/handlers/feedback.py:39 msgid "Feedback" msgstr "" -#: app/views/handlers/feedback.py:132 +#: app/views/handlers/feedback.py:122 msgid "Give feedback about this service" msgstr "" -#: app/views/handlers/feedback.py:138 app/views/handlers/feedback.py:162 +#: app/views/handlers/feedback.py:128 app/views/handlers/feedback.py:152 msgid "Select what your feedback is about" msgstr "" -#: app/views/handlers/feedback.py:141 app/views/handlers/feedback.py:142 +#: app/views/handlers/feedback.py:131 app/views/handlers/feedback.py:132 msgid "The survey questions" msgstr "" -#: app/views/handlers/feedback.py:143 +#: app/views/handlers/feedback.py:133 msgid "For example, questions not clear, answer options not relevant" msgstr "" -#: app/views/handlers/feedback.py:148 app/views/handlers/feedback.py:149 +#: app/views/handlers/feedback.py:138 app/views/handlers/feedback.py:139 msgid "Page design and structure" msgstr "" -#: app/views/handlers/feedback.py:152 app/views/handlers/feedback.py:155 +#: app/views/handlers/feedback.py:142 app/views/handlers/feedback.py:145 msgid "General feedback about this service" msgstr "" -#: app/views/handlers/feedback.py:170 app/views/handlers/feedback.py:180 +#: app/views/handlers/feedback.py:160 app/views/handlers/feedback.py:170 msgid "Enter your feedback" msgstr "" -#: app/views/handlers/feedback.py:171 +#: app/views/handlers/feedback.py:161 msgid "Do not include confidential information, such as your contact details" msgstr "" @@ -767,14 +775,14 @@ msgstr "" msgid "Back" msgstr "" -#: templates/feedback.html:30 +#: templates/feedback.html:31 #, python-format msgid "There is a problem with your feedback" msgid_plural "There are %(num)s problems with your feedback" msgstr[0] "" msgstr[1] "" -#: templates/feedback.html:40 +#: templates/feedback.html:41 msgid "Send feedback" msgstr "" @@ -782,7 +790,7 @@ msgstr "" msgid "If you can’t answer someone else’s questions" msgstr "" -#: templates/interstitial.html:22 templates/partials/question.html:46 +#: templates/interstitial.html:22 templates/partials/question.html:47 msgid "If you can’t answer questions for this person" msgstr "" @@ -818,37 +826,37 @@ msgstr "" msgid "Close this window to continue with your current survey" msgstr "" -#: templates/preview.html:33 +#: templates/preview.html:35 msgid "Preview of the questions in this survey" msgstr "" -#: templates/preview.html:41 +#: templates/preview.html:43 msgid "To answer these questions you need to start survey" msgstr "" -#: templates/preview.html:46 +#: templates/preview.html:48 msgid "" "You may not have to answer all of these questions. The questions you see " "will depend on the answers you provide." msgstr "" -#: templates/preview.html:52 +#: templates/preview.html:54 msgid "Print questions" msgstr "" -#: templates/preview.html:65 +#: templates/preview.html:68 msgid "Save questions as PDF" msgstr "" -#: templates/partials/introduction/preview.html:32 +#: templates/partials/introduction/preview.html:34 #: templates/partials/summary/collapsible-summary.html:51 -#: templates/preview.html:94 +#: templates/preview.html:98 msgid "Show all" msgstr "" -#: templates/partials/introduction/preview.html:33 +#: templates/partials/introduction/preview.html:35 #: templates/partials/summary/collapsible-summary.html:52 -#: templates/preview.html:95 +#: templates/preview.html:99 msgid "Hide all" msgstr "" @@ -878,73 +886,73 @@ msgstr "" msgid "Back to surveys" msgstr "" -#: templates/thank-you.html:40 +#: templates/thank-you.html:42 msgid "Thank you for completing the {survey_title}" msgstr "" -#: templates/thank-you.html:52 +#: templates/thank-you.html:54 msgid "" "Your response will help inform decision-makers how best to support the UK" " population and economy." msgstr "" -#: templates/thank-you.html:55 +#: templates/thank-you.html:57 msgid "Learn more about how we use this data" msgstr "" -#: templates/thank-you.html:58 templates/view-submitted-response.html:72 +#: templates/thank-you.html:60 templates/view-submitted-response.html:76 msgid "For security, you can no longer view or get a copy of your answers" msgstr "" -#: templates/thank-you.html:72 +#: templates/thank-you.html:74 msgid "For security, your answers will only be available to view for another " msgstr "" -#: templates/thank-you.html:73 +#: templates/thank-you.html:75 msgid "Get a copy of your answers" msgstr "" -#: templates/thank-you.html:75 +#: templates/thank-you.html:77 msgid "" "You can save or " "print your answers for your records." msgstr "" -#: templates/layouts/_base.html:146 templates/thank-you.html:81 +#: templates/layouts/_base.html:148 templates/thank-you.html:83 msgid "minute" msgstr "" -#: templates/layouts/_base.html:147 templates/thank-you.html:82 +#: templates/layouts/_base.html:149 templates/thank-you.html:84 msgid "minutes" msgstr "" -#: templates/layouts/_base.html:148 templates/thank-you.html:83 +#: templates/layouts/_base.html:150 templates/thank-you.html:85 msgid "second" msgstr "" -#: templates/layouts/_base.html:149 templates/thank-you.html:84 +#: templates/layouts/_base.html:151 templates/thank-you.html:86 msgid "seconds" msgstr "" -#: templates/thank-you.html:86 +#: templates/thank-you.html:88 msgid "For security, your answers will only be available to view for 45 minutes" msgstr "" -#: templates/thank-you.html:96 +#: templates/thank-you.html:98 msgid "Get confirmation email" msgstr "" -#: templates/thank-you.html:98 +#: templates/thank-you.html:100 msgid "" "If you would like to be sent confirmation that you have completed your " "survey, enter your email address" msgstr "" -#: templates/view-submitted-response.html:33 +#: templates/view-submitted-response.html:35 msgid "Print answers" msgstr "" -#: templates/view-submitted-response.html:46 +#: templates/view-submitted-response.html:49 msgid "Save answers as PDF" msgstr "" @@ -1197,67 +1205,67 @@ msgstr "" msgid "Previous" msgstr "" -#: templates/layouts/_base.html:58 +#: templates/layouts/_base.html:60 msgid "Tell us whether you accept cookies" msgstr "" -#: templates/layouts/_base.html:59 +#: templates/layouts/_base.html:61 msgid "" "We use cookies to collect information" " about how you use {cookie_domain}. We use this information to make the " "website work as well as possible and improve our services." msgstr "" -#: templates/layouts/_base.html:60 +#: templates/layouts/_base.html:62 msgid "" "You’ve accepted all cookies. You can change your cookie preferences at any " "time." msgstr "" -#: templates/layouts/_base.html:61 +#: templates/layouts/_base.html:63 msgid "Accept all cookies" msgstr "" -#: templates/layouts/_base.html:62 +#: templates/layouts/_base.html:64 msgid "Set cookie preferences" msgstr "" -#: templates/layouts/_base.html:63 +#: templates/layouts/_base.html:65 msgid "Hide" msgstr "" -#: templates/layouts/_base.html:113 +#: templates/layouts/_base.html:115 msgid "Skip to main content" msgstr "" -#: templates/layouts/_base.html:141 +#: templates/layouts/_base.html:143 msgid "You will be signed out soon" msgstr "" -#: templates/layouts/_base.html:142 +#: templates/layouts/_base.html:144 msgid "It appears you have been inactive for a while." msgstr "" -#: templates/layouts/_base.html:143 +#: templates/layouts/_base.html:145 msgid "" "To protect your information, your progress will be saved and you will be " "signed out in" msgstr "" -#: templates/layouts/_base.html:144 +#: templates/layouts/_base.html:146 msgid "You are being signed out" msgstr "" -#: templates/layouts/_base.html:145 +#: templates/layouts/_base.html:147 msgid "Continue survey" msgstr "" -#: templates/layouts/_calculatedsummary.html:18 +#: templates/layouts/_calculatedsummary.html:17 msgid "Yes, I confirm this is correct" msgstr "" -#: templates/layouts/_questionnaire.html:46 +#: templates/layouts/_questionnaire.html:47 msgid "Choose another section and return to this later" msgstr "" @@ -1269,15 +1277,15 @@ msgstr "" msgid "Interviewer note:" msgstr "" -#: templates/partials/confirmation-email-form.html:26 +#: templates/partials/confirmation-email-form.html:27 msgid "Email address" msgstr "" -#: templates/partials/confirmation-email-form.html:27 +#: templates/partials/confirmation-email-form.html:28 msgid "This will not be stored and only used once to send your confirmation" msgstr "" -#: templates/partials/confirmation-email-form.html:38 +#: templates/partials/confirmation-email-form.html:39 msgid "Send confirmation" msgstr "" @@ -1293,13 +1301,13 @@ msgstr "" msgid "Give feedback" msgstr "" -#: templates/partials/individual-response-guidance.html:18 +#: templates/partials/individual-response-guidance.html:19 msgid "" "You can share your household access code with the people" " you live with so they can complete their own sections." msgstr "" -#: templates/partials/individual-response-guidance.html:21 +#: templates/partials/individual-response-guidance.html:22 msgid "" "If this is not possible, there are other ways each person " "can complete their own census." @@ -1316,7 +1324,7 @@ msgid "" msgstr "" #: templates/partials/preview-question.html:31 -#: templates/partials/question.html:85 +#: templates/partials/question.html:86 msgid "Or" msgstr "" @@ -1324,19 +1332,19 @@ msgstr "" msgid "{max_characters} characters can be added." msgstr "" -#: templates/partials/question.html:77 +#: templates/partials/question.html:78 msgid "Selecting this will clear your answer" msgstr "" -#: templates/partials/question.html:78 +#: templates/partials/question.html:79 msgid "cleared" msgstr "" -#: templates/partials/question.html:80 +#: templates/partials/question.html:81 msgid "Selecting this will deselect any selected options" msgstr "" -#: templates/partials/question.html:81 templates/partials/question.html:89 +#: templates/partials/question.html:82 templates/partials/question.html:90 msgid "deselected" msgstr "" @@ -1509,11 +1517,8 @@ msgid "Change" msgstr "" #: templates/partials/summary/collapsible-summary.html:29 -#: templates/partials/summary/summary.html:28 -msgid "Change your answer for:" -msgstr "" - #: templates/partials/summary/list-summary.html:9 +#: templates/partials/summary/summary.html:28 msgid "Change details for {item_name}" msgstr "" @@ -1527,6 +1532,6 @@ msgid "Remove {item_name}" msgstr "" #: templates/partials/summary/summary.html:26 -msgid "Remove your answer for:" +msgid "Remove details for {item_name}" msgstr "" diff --git a/templates/partials/summary/collapsible-summary.html b/templates/partials/summary/collapsible-summary.html index f264784c91..e443df3e5d 100644 --- a/templates/partials/summary/collapsible-summary.html +++ b/templates/partials/summary/collapsible-summary.html @@ -26,7 +26,7 @@ answers_are_editable=content.summary.answers_are_editable, no_answer_provided=_("No answer provided"), edit_link_text=_("Change"), - edit_link_aria_label=_("Change your answer for:"), + edit_link_aria_label=_("Change details for {item_name}"), calculated_question=content.summary.calculated_question ) } diff --git a/templates/partials/summary/summary.html b/templates/partials/summary/summary.html index 5e370158e2..c0fa459536 100644 --- a/templates/partials/summary/summary.html +++ b/templates/partials/summary/summary.html @@ -23,9 +23,9 @@ answers_are_editable=content.summary.answers_are_editable, no_answer_provided=_("No answer provided"), remove_link_text=_("Remove") if not view_submitted_response else "", - remove_link_aria_label=_("Remove your answer for:") if not view_submitted_response else "", + remove_link_aria_label=_("Remove details for {item_name}") if not view_submitted_response else "", edit_link_text=_("Change") if not view_submitted_response else "", - edit_link_aria_label=_("Change your answer for:") if not view_submitted_response else "", + edit_link_aria_label=_("Change details for {item_name}") if not view_submitted_response else "", calculated_question=content.summary.calculated_question ), "classes": "ons-u-mt-m" if loop.index > 1 else "", diff --git a/tests/app/test_jinja_filters.py b/tests/app/test_jinja_filters.py index 8d76e96c56..d8d45a160f 100644 --- a/tests/app/test_jinja_filters.py +++ b/tests/app/test_jinja_filters.py @@ -744,7 +744,7 @@ def test_map_list_collector_config_with_related_answers_and_answer_title(): { "actions": [ { - "visuallyHiddenText": "edit_link_aria_label Registration number", + "visuallyHiddenText": "Change answer for Name of UK company or branch: Registration number", "attributes": { "data-ga": "click", "data-ga-action": "Edit", @@ -766,7 +766,7 @@ def test_map_list_collector_config_with_related_answers_and_answer_title(): { "actions": [ { - "visuallyHiddenText": "edit_link_aria_label Is this UK " + "visuallyHiddenText": "Change answer for Name of UK company or branch: Is this UK " "company or branch an authorised " "insurer?", "attributes": { @@ -903,7 +903,6 @@ def test_calculated_summary_config(): answers_are_editable=True, no_answer_provided="No answer Provided", edit_link_text="Change", - edit_link_aria_label="Change your answer for", ), SummaryRow( question={ @@ -926,7 +925,6 @@ def test_calculated_summary_config(): answers_are_editable=True, no_answer_provided="No answer Provided", edit_link_text="Change", - edit_link_aria_label="Change your answer for", ), SummaryRow( question={ @@ -938,7 +936,6 @@ def test_calculated_summary_config(): answers_are_editable=False, no_answer_provided=None, edit_link_text=None, - edit_link_aria_label=None, ), ] @@ -1015,13 +1012,13 @@ def test_summary_item_config_with_list_collector(): { "actions": [ { - "visuallyHiddenText": "Change your answer for:", + "visuallyHiddenText": "Change details for Company A", "attributes": {"data-qa": "list-item-change-1-link"}, "text": "Change", "url": "change_link_url", }, { - "visuallyHiddenText": "Remove Company A", + "visuallyHiddenText": "Remove details for Company A", "attributes": {"data-qa": "list-item-remove-1-link"}, "text": "Remove", "url": "remove_link_url", @@ -1039,8 +1036,7 @@ def test_summary_item_config_with_list_collector(): { "actions": [ { - "visuallyHiddenText": "Change your answer for: " - "Registration number", + "visuallyHiddenText": "Change answer for Company A: Registration number", "attributes": { "data-ga": "click", "data-ga-action": "Edit", @@ -1062,7 +1058,7 @@ def test_summary_item_config_with_list_collector(): { "actions": [ { - "visuallyHiddenText": "Change your answer for: Is this UK " + "visuallyHiddenText": "Change answer for Company A: Is this UK " "company or branch an authorised " "insurer?", "attributes": { @@ -1157,10 +1153,10 @@ def test_summary_item_config_with_list_collector(): summary_type="SectionSummary", answers_are_editable=True, no_answer_provided="No answer Provided", - remove_link_aria_label="Remove Company A", + remove_link_aria_label="Remove details for {item_name}", remove_link_text="Remove", edit_link_text="Change", - edit_link_aria_label="Change your answer for:", + edit_link_aria_label="Change details for {item_name}", calculated_question={}, ) @@ -1175,13 +1171,13 @@ def test_summary_item_config_with_list_collector_and_one_related_answer(): { "actions": [ { - "visuallyHiddenText": "Change your answer for:", + "visuallyHiddenText": "Change details for Company A", "attributes": {"data-qa": "list-item-change-1-link"}, "text": "Change", "url": "change_link_url", }, { - "visuallyHiddenText": "Remove Company A", + "visuallyHiddenText": "Remove details for Company A", "attributes": {"data-qa": "list-item-remove-1-link"}, "text": "Remove", "url": "remove_link_url", @@ -1199,7 +1195,7 @@ def test_summary_item_config_with_list_collector_and_one_related_answer(): { "actions": [ { - "visuallyHiddenText": "Change your answer for: " + "visuallyHiddenText": "Change answer for Company A: " "Registration number", "attributes": { "data-ga": "click", @@ -1279,10 +1275,10 @@ def test_summary_item_config_with_list_collector_and_one_related_answer(): summary_type="SectionSummary", answers_are_editable=True, no_answer_provided="No answer Provided", - remove_link_aria_label="Remove Company A", + remove_link_aria_label="Remove details for {item_name}", remove_link_text="Remove", edit_link_text="Change", - edit_link_aria_label="Change your answer for:", + edit_link_aria_label="Change details for {item_name}", calculated_question={}, )