mocking out a test that actually compiles

This commit is contained in:
wrenny-ko 2024-08-27 19:16:13 -04:00
parent b7733a2ae5
commit 204e48d05b
2 changed files with 20 additions and 3 deletions

View file

@ -87,11 +87,11 @@ describe('Image upload form', () => {
<input id="image_sources_0_source" name="image[sources][0][source]" type="text" class="js-source-url" />
<textarea id="image_tag_input" name="image[tag_input]" class="js-image-tags-input"></textarea>
<div class="js-taginput" value="safe, pony, third tag"/>
<div class="js-taginput" value="safe, pony"></div>
<button id="tagsinput-save" type="button" class="button">Save</button>
<textarea id="image_description" name="image[description]" class="js-image-descr-input"></textarea>
<div class="actions">
<button class="button" type="submit">Upload</button>
<button class="button input--separate-top" type="submit">Upload</button>
</div>
</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<void>(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);
});
});
});

View file

@ -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...';