diff --git a/app/__init__.py b/app/__init__.py
index be7f08146..9936aa1ee 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -682,4 +682,4 @@ def slugify(text):
"""
Converts text to lowercase, replaces spaces with hyphens, and removes invalid characters.
"""
- return re.sub(r'[^a-z0-9-]', '', re.sub(r'\s+', '-', text.lower()))
+ return re.sub(r"[^a-z0-9-]", "", re.sub(r"\s+", "-", text.lower()))
diff --git a/app/assets/javascripts/preventDuplicateFormSubmissions.js b/app/assets/javascripts/preventDuplicateFormSubmissions.js
index 61e2e6890..a58f2a8b5 100644
--- a/app/assets/javascripts/preventDuplicateFormSubmissions.js
+++ b/app/assets/javascripts/preventDuplicateFormSubmissions.js
@@ -13,7 +13,8 @@
} else {
$submitButton.data('clicked', 'true');
- setTimeout(renableSubmitButton($submitButton), 1500);
+ $submitButton.prop('disabled', true);
+ setTimeout(renableSubmitButton($submitButton), 10000);
}
@@ -22,7 +23,7 @@
let renableSubmitButton = $submitButton => () => {
$submitButton.data('clicked', '');
-
+ $submitButton.prop('disabled', false);
};
$('form').on('submit', disableSubmitButtons);
diff --git a/app/main/views/send.py b/app/main/views/send.py
index 194ee55ef..54f5eb098 100644
--- a/app/main/views/send.py
+++ b/app/main/views/send.py
@@ -924,6 +924,10 @@ def get_template_error_dict(exception):
def preview_notification(service_id, template_id):
recipient = get_recipient()
if not recipient:
+ current_app.logger.warning(
+ f"No recipient found for service {service_id}, template {template_id}. Redirecting..."
+ )
+
return redirect(
url_for(
".send_one_off",
diff --git a/app/templates/views/notifications/preview.html b/app/templates/views/notifications/preview.html
index d0be74aed..4f0d511d3 100644
--- a/app/templates/views/notifications/preview.html
+++ b/app/templates/views/notifications/preview.html
@@ -77,13 +77,16 @@
help='3' if help else 0
)}}" class='page-footer'>
-
Does everything look good?
{% if not error %}
{% set button_text %}
{{ "Schedule" if scheduled_for else 'Send'}}
{% endset %}
- {{ usaButton({ "text": button_text }) }}
+ {{ usaButton({
+ "text": button_text,
+ "type": submit,
+ "preventDoubleClick": True,
+ }) }}
{% endif %}
diff --git a/tests/app/main/views/service_settings/test_service_settings.py b/tests/app/main/views/service_settings/test_service_settings.py
index d7155f709..6c4e42fac 100644
--- a/tests/app/main/views/service_settings/test_service_settings.py
+++ b/tests/app/main/views/service_settings/test_service_settings.py
@@ -488,7 +488,9 @@ def test_show_switch_service_to_count_as_live_page(
# Extract label text and see if it matches the expected label
label_texts = [label.text.strip() for label in labels]
- assert labelled in label_texts, f"Expected label '{labelled}' not found. Found labels: {label_texts}"
+ assert (
+ labelled in label_texts
+ ), f"Expected label '{labelled}' not found. Found labels: {label_texts}"
@pytest.mark.parametrize(
diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py
index 02bed98fa..753931ce5 100644
--- a/tests/app/main/views/test_activity.py
+++ b/tests/app/main/views/test_activity.py
@@ -388,7 +388,10 @@ def test_search_recipient_form(
query_dict = parse_qs(url.query)
assert query_dict == {}
- assert page.select_one("label:contains('Search by')").text.strip() == expected_search_box_label
+ assert (
+ page.select_one("label:contains('Search by')").text.strip()
+ == expected_search_box_label
+ )
recipient_inputs = page.select("input[name=to]")
assert len(recipient_inputs) == 2
@@ -421,7 +424,10 @@ def test_api_users_are_told_they_can_search_by_reference_when_service_has_api_ke
service_id=SERVICE_ONE_ID,
message_type=message_type,
)
- assert page.select_one("label:contains('Search by')").text.strip() == expected_search_box_label
+ assert (
+ page.select_one("label:contains('Search by')").text.strip()
+ == expected_search_box_label
+ )
@pytest.mark.parametrize(
@@ -449,7 +455,10 @@ def test_api_users_are_not_told_they_can_search_by_reference_when_service_has_no
message_type=message_type,
)
- assert page.select_one("label:contains('Search by')").text.strip() == expected_search_box_label
+ assert (
+ page.select_one("label:contains('Search by')").text.strip()
+ == expected_search_box_label
+ )
def test_should_show_notifications_for_a_service_with_next_previous(
diff --git a/tests/javascripts/preventDuplicateFormSubmissions.test.js b/tests/javascripts/preventDuplicateFormSubmissions.test.js
index 09ec7e5d2..2a776ef0f 100644
--- a/tests/javascripts/preventDuplicateFormSubmissions.test.js
+++ b/tests/javascripts/preventDuplicateFormSubmissions.test.js
@@ -44,20 +44,19 @@ describe('Prevent duplicate form submissions', () => {
});
- test("It should prevent any clicks of the 'submit' button after the first one submitting the form", () => {
-
+ test("It should prevent the second click on the 'submit' button", () => {
helpers.triggerEvent(button, 'click');
+ expect(button.disabled).toBe(true);
helpers.triggerEvent(button, 'click');
- expect(formEventSpy.mock.calls.length).toEqual(1);
-
+ expect(button.disabled).toBe(true);
});
test("It should allow clicks again after 1.5 seconds", () => {
helpers.triggerEvent(button, 'click');
- jest.advanceTimersByTime(1500);
+ jest.advanceTimersByTime(10000);
helpers.triggerEvent(button, 'click');