Test updates

This commit is contained in:
Jonathan Bobel
2025-04-01 13:03:12 -04:00
parent 06c238269f
commit 032b9927aa
3 changed files with 144 additions and 14 deletions

View File

@@ -11,20 +11,21 @@ function announceUploadStatusFromElement() {
srRegion.textContent = '';
setTimeout(() => {
srRegion.textContent = message;
console.log(message);
}, 50);
}
}
document.addEventListener('DOMContentLoaded', () => {
announceUploadStatusFromElement();
});
// Exported for use in tests
function initUploadStatusAnnouncer() {
document.addEventListener('DOMContentLoaded', () => {
announceUploadStatusFromElement();
});
}
(function(Modules) {
"use strict";
Modules.FileUpload = function() {
this.submit = () => this.$form.trigger('submit');
this.showCancelButton = () => {
@@ -38,24 +39,25 @@ document.addEventListener('DOMContentLoaded', () => {
this.start = function(component) {
this.$form = $(component);
// Handle "Upload your file" button click — CSP-safe version
this.$form.on('click', '[data-module="upload-trigger"]', function () {
const inputId = $(this).data('file-input-id');
const fileInput = document.getElementById(inputId);
if (fileInput) fileInput.click();
});
// Clear the form if the user navigates back to the page
$(window).on("pageshow", () => this.$form[0].reset());
// Watch for file input changes
this.$form.on('change', '.file-upload-field', () => {
this.submit();
this.showCancelButton();
});
};
};
})(window.GOVUK.Modules);
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
announceUploadStatusFromElement,
initUploadStatusAnnouncer
};
}