Skip to content

Commit a030e62

Browse files
committed
Apply role=alert to all notification banners
Without this, info/warning banners (ie - any type other than 'success') will not have autofocus on page load. We apply this change on the basis that we want to autofocus all banners in the service. If a need arises to disable this behaviour, we can use the disable_autofocus param.
1 parent 49b0e5b commit a030e62

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

manage_breast_screening/core/template_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def get_notification_banner_params(
109109
params["html"] = Markup(message)
110110
else:
111111
params["text"] = message
112+
params["role"] = "alert"
112113
return params
113114

114115

manage_breast_screening/core/tests/test_template_helpers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +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"}
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"}
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 == {"text": "warning!", "type": "warning"}
91+
assert result == {"text": "warning!", "type": "warning", "role": "alert"}
9292

9393
def test_invalid_message_type(self, dummy_request):
9494
with pytest.raises(
@@ -101,7 +101,12 @@ def test_autofocus_can_be_disabled(self, dummy_request):
101101
result = get_notification_banner_params(
102102
dummy_request, "info", disable_auto_focus=True
103103
)
104-
assert result == {"text": "abc", "type": "info", "disableAutoFocus": True}
104+
assert result == {
105+
"text": "abc",
106+
"type": "info",
107+
"disableAutoFocus": True,
108+
"role": "alert",
109+
}
105110

106111

107112
class TestNotificationBannerParamsForHTMLMessages:
@@ -116,8 +121,8 @@ def dummy_request(self):
116121

117122
def test_info_banner_with_html_message(self, dummy_request):
118123
result = get_notification_banner_params(dummy_request, "info")
119-
assert result == {"html": mark_safe("abc"), "type": "info"}
124+
assert result == {"html": mark_safe("abc"), "type": "info", "role": "alert"}
120125

121126
def test_success_banner_with_html_message(self, dummy_request):
122127
result = get_notification_banner_params(dummy_request, "success")
123-
assert result == {"html": mark_safe("def"), "type": "success"}
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)