Skip to content

Commit

Permalink
chore: added submit button validation test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaiir committed Apr 18, 2024
1 parent d1e3b63 commit 78af6eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,33 @@ describe('Form', function () {
expect(document.body.innerHTML).not.to.contain('Field is required.');
});

it('should trigger all required on submit button click', async function () {
// given
const data = {};

// when
await bootstrapForm({
container,
data,
schema: requiredSchema,
});

// when
const submitButton = container.querySelector('.fjs-button');
fireEvent.click(submitButton);

const validateCount = requiredSchema.components.filter((c) => (c.validate || {}).required).length;

// then
await waitFor(() => {
const errors = container.querySelectorAll('.fjs-form-field-error');
expect(errors).to.have.length(validateCount);
for (const error of errors) {
expect(error.textContent).to.eql('Field is required.');
}
});
});

const runFocusBlurTest = function (id, index, selector) {
it('focus and blur events should trigger for ' + id, async function () {
// given
Expand Down
4 changes: 4 additions & 0 deletions packages/form-js-viewer/test/spec/required.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
"validate": {
"required": true
}
},
{
"label": "Submit",
"type": "button"
}
],
"type": "default"
Expand Down

0 comments on commit 78af6eb

Please sign in to comment.