mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-31 19:36:44 +01:00
tests for client side tag validation
This commit is contained in:
parent
b713524989
commit
4010a8a277
1 changed files with 36 additions and 22 deletions
|
@ -25,7 +25,8 @@ const errorResponse = {
|
|||
};
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
const tagSets = ['safe', 'one, two, three', 'safe, expicit', 'safe, two, three'];
|
||||
const tagSets = ['', 'a tag', 'safe', 'one, two, three', 'safe, explicit', 'safe, explicit, three', 'safe, two, three'];
|
||||
const tagErrorCounts = [1, 2, 1, 1, 2, 1, 0];
|
||||
|
||||
describe('Image upload form', () => {
|
||||
let mockPng: File;
|
||||
|
@ -213,28 +214,41 @@ describe('Image upload form', () => {
|
|||
});
|
||||
});
|
||||
|
||||
async function submitForm(frm): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
function onSubmit() {
|
||||
frm.removeEventListener('submit', onSubmit);
|
||||
resolve(true);
|
||||
}
|
||||
|
||||
frm.addEventListener('submit', onSubmit);
|
||||
|
||||
if (!fireEvent.submit(frm)) {
|
||||
frm.removeEventListener('submit', onSubmit);
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it('should prevent form submission if tag checks fail', async () => {
|
||||
tagSets.forEach(tags => {
|
||||
taginputEl.value = tags;
|
||||
//TODO fire submit event
|
||||
// check whether the form fully submitted or was prevented by tag checks
|
||||
// verify the number of error help blocks added
|
||||
// check if the submit button is enabled/disabled
|
||||
});
|
||||
|
||||
await new Promise<void>(resolve => {
|
||||
form.addEventListener('submit', event => {
|
||||
event.preventDefault();
|
||||
resolve();
|
||||
});
|
||||
fireEvent.submit(form);
|
||||
});
|
||||
for (let i = 0; i < tagSets.length; i += 1) {
|
||||
taginputEl.value = tagSets[i];
|
||||
|
||||
if (await submitForm(form)) {
|
||||
// form submit succeeded
|
||||
await waitFor(() => {
|
||||
assertSubmitButtonIsDisabled();
|
||||
const succeededUnloadEvent = new Event('beforeunload', { cancelable: true });
|
||||
expect(fireEvent(window, succeededUnloadEvent)).toBe(true);
|
||||
});
|
||||
} else {
|
||||
// form submit prevented
|
||||
frm = form;
|
||||
await waitFor(() => {
|
||||
assertSubmitButtonIsEnabled();
|
||||
expect(form.querySelectorAll('.help-block')).toHaveLength(1);
|
||||
expect(frm.querySelectorAll('.help-block')).toHaveLength(tagErrorCounts[i]);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue