Skip to content

Commit 5e6a9a1

Browse files
authored
Merge pull request #1178 from NHSDigital/12368-focus-style-flash-messages
Enable auto-focus on flash messages
2 parents 523b48f + a030e62 commit 5e6a9a1

File tree

6 files changed

+31
-47
lines changed

6 files changed

+31
-47
lines changed

manage_breast_screening/core/jinja2/layout-app.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@
6161
{% block content %}
6262
{% block flash_messages %}
6363
{% set info_notification_params = get_notification_banner_params(
64-
request, message_type='info',
65-
disable_auto_focus=disable_auto_focus|default(true)
64+
request, message_type='info'
6665
) %}
6766

6867
{% set success_notification_params = get_notification_banner_params(
69-
request, message_type='success',
70-
disable_auto_focus=disable_auto_focus|default(true)
68+
request, message_type='success'
7169
) %}
7270

7371
{% set warning_notification_params = get_notification_banner_params(
74-
request, message_type='warning',
75-
disable_auto_focus=disable_auto_focus|default(true)
72+
request, message_type='warning'
7673
) %}
7774

7875
{% if success_notification_params %}

manage_breast_screening/core/jinja2/workflow_step.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
</div>
2222
<div class="nhsuk-grid-column-three-quarters app-workflow-container__main" id="workflow_content">
2323
{% set info_notification_params = get_notification_banner_params(
24-
request, message_type='info',
25-
disable_auto_focus=disable_auto_focus|default(true)
24+
request, message_type='info'
2625
) %}
2726

2827
{% set success_notification_params = get_notification_banner_params(
29-
request, message_type='success',
30-
disable_auto_focus=disable_auto_focus|default(true)
28+
request, message_type='success'
3129
) %}
3230

3331
{% set warning_notification_params = get_notification_banner_params(
34-
request, message_type='warning',
35-
disable_auto_focus=disable_auto_focus|default(true)
32+
request, message_type='warning'
3633
) %}
3734

3835
{% if success_notification_params %}

manage_breast_screening/core/template_helpers.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def message_with_heading(heading: str, html=None) -> SafeString:
8686

8787

8888
def get_notification_banner_params(
89-
request, message_type="info", disable_auto_focus=True
89+
request, message_type="info", disable_auto_focus=False
9090
):
9191
levels = {"info": INFO, "warning": WARNING, "success": SUCCESS}
9292
try:
@@ -102,18 +102,15 @@ def get_notification_banner_params(
102102

103103
message = messages[0].message
104104

105+
params = {"type": message_type}
106+
if disable_auto_focus:
107+
params["disableAutoFocus"] = True
105108
if _is_safe_message(message):
106-
return {
107-
"html": Markup(message),
108-
"type": message_type,
109-
"disableAutoFocus": disable_auto_focus,
110-
}
109+
params["html"] = Markup(message)
111110
else:
112-
return {
113-
"text": message,
114-
"type": message_type,
115-
"disableAutoFocus": disable_auto_focus,
116-
}
111+
params["text"] = message
112+
params["role"] = "alert"
113+
return params
117114

118115

119116
def _user_name_and_role_item(user):

manage_breast_screening/core/tests/jinja2/test_base_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_success_banner(jinja_env):
5050

5151
assertInHTML(
5252
"""
53-
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner" data-disable-auto-focus="true">
53+
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner">
5454
<div class="nhsuk-notification-banner__header">
5555
<h2 class="nhsuk-notification-banner__title" id="nhsuk-notification-banner-title">Success</h2>
5656
</div>
@@ -80,7 +80,7 @@ def test_success_banner_with_html_message(jinja_env):
8080

8181
assertInHTML(
8282
"""
83-
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner" data-disable-auto-focus="true">
83+
<div class="nhsuk-notification-banner nhsuk-notification-banner--success" role="alert" aria-labelledby="nhsuk-notification-banner-title" data-module="nhsuk-notification-banner">
8484
<div class="nhsuk-notification-banner__header">
8585
<h2 class="nhsuk-notification-banner__title" id="nhsuk-notification-banner-title">Success</h2>
8686
</div>

manage_breast_screening/core/tests/test_template_helpers.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,15 @@ def dummy_request(self):
8080

8181
def test_info_banner_with_text_message(self, dummy_request):
8282
result = get_notification_banner_params(dummy_request, "info")
83-
assert result == {"text": "abc", "type": "info", "disableAutoFocus": True}
83+
assert result == {"text": "abc", "type": "info", "role": "alert"}
8484

8585
def test_success_banner_with_text_message(self, dummy_request):
8686
result = get_notification_banner_params(dummy_request, "success")
87-
assert result == {"text": "def", "type": "success", "disableAutoFocus": True}
87+
assert result == {"text": "def", "type": "success", "role": "alert"}
8888

8989
def test_warning_banner_with_text_message(self, dummy_request):
9090
result = get_notification_banner_params(dummy_request, "warning")
91-
assert result == {
92-
"text": "warning!",
93-
"type": "warning",
94-
"disableAutoFocus": True,
95-
}
91+
assert result == {"text": "warning!", "type": "warning", "role": "alert"}
9692

9793
def test_invalid_message_type(self, dummy_request):
9894
with pytest.raises(
@@ -101,11 +97,16 @@ def test_invalid_message_type(self, dummy_request):
10197
):
10298
get_notification_banner_params(dummy_request, "error")
10399

104-
def test_autofocus_param(self, dummy_request):
100+
def test_autofocus_can_be_disabled(self, dummy_request):
105101
result = get_notification_banner_params(
106-
dummy_request, "info", disable_auto_focus=False
102+
dummy_request, "info", disable_auto_focus=True
107103
)
108-
assert result == {"text": "abc", "type": "info", "disableAutoFocus": False}
104+
assert result == {
105+
"text": "abc",
106+
"type": "info",
107+
"disableAutoFocus": True,
108+
"role": "alert",
109+
}
109110

110111

111112
class TestNotificationBannerParamsForHTMLMessages:
@@ -120,16 +121,8 @@ def dummy_request(self):
120121

121122
def test_info_banner_with_html_message(self, dummy_request):
122123
result = get_notification_banner_params(dummy_request, "info")
123-
assert result == {
124-
"html": mark_safe("abc"),
125-
"type": "info",
126-
"disableAutoFocus": True,
127-
}
124+
assert result == {"html": mark_safe("abc"), "type": "info", "role": "alert"}
128125

129126
def test_success_banner_with_html_message(self, dummy_request):
130127
result = get_notification_banner_params(dummy_request, "success")
131-
assert result == {
132-
"html": mark_safe("def"),
133-
"type": "success",
134-
"disableAutoFocus": True,
135-
}
128+
assert result == {"html": mark_safe("def"), "type": "success", "role": "alert"}

manage_breast_screening/tests/system/clinical/test_appointment_tabs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ def then_i_should_see_the_demographic_banner(self):
180180
expect(self.page.get_by_text("NHS Number")).to_be_visible()
181181

182182
def and_the_message_says_in_progress_with_someone_else(self):
183-
alert = self.page.get_by_role("region")
183+
alert = self.page.get_by_role("alert")
184184
expect(alert).to_contain_text("Important")
185185
expect(alert).to_contain_text(
186186
"This appointment is currently being run by F. Lastname."
187187
)
188188

189189
def and_no_message_says_in_progress_with_someone_else(self):
190-
expect(self.page.get_by_role("region")).not_to_be_attached()
190+
expect(self.page.get_by_role("alert")).not_to_be_attached()
191191

192192
def when_i_change_to_the_participant_details_tab(self):
193193
self.when_i_change_to_an_appointment_tab("Participant")

0 commit comments

Comments
 (0)