Skip to content

Commit

Permalink
WIP: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Jun 18, 2024
1 parent f58394c commit cfb7592
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/form/Form.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Webform from '../../Webform';
import { Formio } from '../../formio.form.js';
import formModalEdit from './fixtures/formModalEdit';
import { formComponentWithConditionalRenderingForm } from '../../../test/formtest';
import TextFieldComponent from '../textfield/TextField.js';

Check warning on line 21 in src/components/form/Form.unit.js

View workflow job for this annotation

GitHub Actions / setup

'TextFieldComponent' is defined but never used

describe('Form Component', () => {
it('Should build a form component', () => {
Expand Down Expand Up @@ -371,6 +372,34 @@ describe('SaveDraft functionality for Nested Form', () => {
done();
});

it('Changes to the child form should trigger a `modified` change in the parent', (done) => {
const formElement = document.createElement('div');
Formio.createForm(
formElement,
'http://localhost:3000/idwqwhclwioyqbw/testdraftparent',
{
saveDraft: true
}
).then((form) => {
form.on('change', ({ changed }, _, modified) => {
if (changed) {
const { instance } = changed;
if (instance instanceof Webform) {
assert(modified === true, 'the modified flag should bubble to the root');
done();
}
}
});
setTimeout(() => {
const tfNestedInput = form.getComponent('form.nested')?.refs?.input?.[0];
assert(tfNestedInput !== undefined, 'We have the input element');
tfNestedInput.value = 'testNested';
const inputEvent = new Event('input');
tfNestedInput.dispatchEvent(inputEvent);
}, 200);
}).catch((err) => done(err));
});

it('Should save draft for Nested Form and for the Parent Form', function(done) {
const formElement = document.createElement('div');
Formio.createForm(
Expand Down

0 comments on commit cfb7592

Please sign in to comment.