diff --git a/assets/js/__tests__/upload.spec.ts b/assets/js/__tests__/upload.spec.ts
index ec0b986a..233bcd83 100644
--- a/assets/js/__tests__/upload.spec.ts
+++ b/assets/js/__tests__/upload.spec.ts
@@ -87,11 +87,11 @@ describe('Image upload form', () => {
-
+
-
+
`,
);
@@ -210,4 +210,21 @@ describe('Image upload form', () => {
expect(scraperError.innerText).toEqual('Error 1 Error 2');
});
});
+
+ it('should prevent form submission if tag checks fail', async () => {
+ await new Promise(resolve => {
+ form.addEventListener('submit', event => {
+ event.preventDefault();
+ resolve();
+ });
+ fireEvent.submit(form);
+ });
+
+ const succeededUnloadEvent = new Event('beforeunload', { cancelable: true });
+ expect(fireEvent(window, succeededUnloadEvent)).toBe(true);
+ await waitFor(() => {
+ assertSubmitButtonIsEnabled();
+ expect(form.querySelectorAll('.help-block')).toHaveLength(1);
+ });
+ });
});
diff --git a/assets/js/upload.js b/assets/js/upload.js
index 8153fad8..fe068899 100644
--- a/assets/js/upload.js
+++ b/assets/js/upload.js
@@ -238,7 +238,7 @@ function setupImageUpload() {
}
function disableUploadButton() {
- const submitButton = $('.input--separate-top');
+ const submitButton = $('.button.input--separate-top');
if (submitButton !== null) {
submitButton.disabled = true;
submitButton.innerText = 'Please wait...';