mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Update govuk_text_input_field_widget to only show one error
If there were multiple errors, this widget was joining the messages together and displaying all error messages. If a text input field does have more than one validation error, we only want to show one.
This commit is contained in:
@@ -2361,6 +2361,27 @@ def test_incorrect_sms_sender_input(
|
||||
assert count_of_api_calls == 0
|
||||
|
||||
|
||||
def test_incorrect_sms_sender_input_with_multiple_errors_only_shows_the_first(
|
||||
client_request,
|
||||
no_sms_senders,
|
||||
mock_add_sms_sender,
|
||||
):
|
||||
# There are two errors with the SMS sender - the length and characters used. Only one
|
||||
# should be displayed on the page.
|
||||
page = client_request.post(
|
||||
'main.service_add_sms_sender',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'sms_sender': '{}'},
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
error_message = page.select_one('.govuk-error-message')
|
||||
count_of_api_calls = len(mock_add_sms_sender.call_args_list)
|
||||
|
||||
assert normalize_spaces(error_message.text) == 'Error: Enter 3 characters or more'
|
||||
assert count_of_api_calls == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('reply_to_addresses, data, api_default_args', [
|
||||
([], {}, True),
|
||||
(create_multiple_email_reply_to_addresses(), {}, False),
|
||||
|
||||
@@ -110,6 +110,26 @@ def test_should_redirect_after_email_change(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address,error_message', [
|
||||
('me@example.com', 'Enter a public sector email address or find out who can use Notify'),
|
||||
('not_valid', 'Enter a valid email address') # 2 errors with email address, only first error shown
|
||||
])
|
||||
def test_should_show_errors_if_new_email_address_does_not_validate(
|
||||
client_request,
|
||||
mock_email_is_not_already_in_use,
|
||||
mock_get_organisations,
|
||||
email_address,
|
||||
error_message,
|
||||
):
|
||||
page = client_request.post(
|
||||
'main.user_profile_email',
|
||||
_data={'email_address': email_address},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.find('span', class_='govuk-error-message').text) == f'Error: {error_message}'
|
||||
|
||||
|
||||
def test_should_show_authenticate_after_email_change(
|
||||
client_request,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user