Skip to content

Commit

Permalink
Fixing tests with latest @formio/core.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Jan 9, 2024
1 parent 4ee663e commit 3fffd2d
Show file tree
Hide file tree
Showing 9 changed files with 1,345 additions and 1,308 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"dependencies": {
"@formio/bootstrap": "^3.0.0-rc.20",
"@formio/choices.js": "^10.2.0",
"@formio/core": "^2.0.0-rc.2",
"@formio/core": "^2.0.0-rc.6",
"@formio/text-mask-addons": "^3.8.0-formio.2",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand Down
24 changes: 12 additions & 12 deletions resources/latest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FormTests from '../test/forms';
import Webform from './Webform';
import 'flatpickr';
import AllComponents from './components';
import { Formio } from './Formio';
import { Formio } from './formio.form.js';
import {
settingErrors,
clearOnHide,
Expand Down
20 changes: 15 additions & 5 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { conformToMask } from '@formio/vanilla-text-mask';
import tippy from 'tippy.js';
import _ from 'lodash';
import isMobile from 'ismobilejs';
import { processOne, processOneSync, validateProcess, validateProcessSync } from '@formio/core/process';
import { processOne, processOneSync, validateProcessInfo } from '@formio/core/process';

import { Formio } from '../../../Formio';
import * as FormioUtils from '../../../utils/utils';
Expand Down Expand Up @@ -3026,7 +3026,7 @@ export default class Component extends Element {
scope: validationScope,
instance: this,
processors: [
validateProcessSync
validateProcessInfo
]
});
const errors = validationScope.errors;
Expand Down Expand Up @@ -3113,7 +3113,7 @@ export default class Component extends Element {
instance: this,
scope: { errors: [] },
processors: [
async ? validateProcess : validateProcessSync
validateProcessInfo
]
};

Expand Down Expand Up @@ -3144,7 +3144,12 @@ export default class Component extends Element {
return this.validateComponent(data, row, flags).then((errors) => {
allErrors.push(...errors);
if (this.parent && this.parent.childErrors) {
this.parent.childErrors.push(...errors);
if (errors.length) {
this.parent.childErrors.push(...errors);
}
else {
_.remove(this.parent.childErrors, (err) => err.component.key === this.component.key);
}
}
this.showValidationErrors(errors, data, row, flags);
return errors.length === 0;
Expand All @@ -3155,7 +3160,12 @@ export default class Component extends Element {
this.showValidationErrors(errors, data, row, flags);
allErrors.push(...errors);
if (this.parent && this.parent.childErrors) {
this.parent.childErrors.push(...errors);
if (errors.length) {
this.parent.childErrors.push(...errors);
}
else {
_.remove(this.parent.childErrors, (err) => err.component.key === this.component.key);
}
}
return errors.length === 0;
}
Expand Down
30 changes: 19 additions & 11 deletions src/components/_classes/nested/NestedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,24 +669,32 @@ export default class NestedComponent extends Field {
components = components || this.component.components;
data = data || this.rootValue;
const { async, dirty, process } = flags;
const validationProcessorProcess = (context) => this.validationProcessor(context, flags);
const checkModalProcessorProcess = ({ instance, component, components }) => {
// If we just validated the last component, and there are errors from our parent, then we need to show a model of those errors.
if (
instance &&
instance.parent &&
(component === components[components.length - 1]) &&
instance.parent.componentModal
) {
instance.parent.checkModal(instance.parent.childErrors, dirty);
}
};
const processorContext = {
process: process || 'unknown',
components,
instances: this.componentsMap,
data: data,
scope: { errors: [] },
processors: [
(context) => this.validationProcessor(context, flags),
({ instance, component, components }) => {
// If we just validated the last component, and there are errors from our parent, then we need to show a model of those errors.
if (
instance &&
instance.parent &&
(component === components[components.length - 1]) &&
instance.parent.componentModal
) {
instance.parent.checkModal(instance.parent.childErrors, dirty);
}
{
process: validationProcessorProcess,
processSync: validationProcessorProcess
},
{
process: checkModalProcessorProcess,
processSync: checkModalProcessorProcess
}
]
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/editgrid/EditGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ export default class EditGridComponent extends NestedArrayComponent {
const editGridValue = _.get(rootValue, this.path, []);
editGridValue[editRow.rowIndex] = editRow.data;
_.set(rootValue, this.path, editGridValue);
const validationProcessorProcess = (context) => this.validationProcessor(context, { dirty, silentCheck });
editRow.errors = processSync({
components: fastCloneDeep(this.component.components).map((component) => {
component.parentPath = `${this.path}[${editRow.rowIndex}]`;
Expand All @@ -1170,7 +1171,10 @@ export default class EditGridComponent extends NestedArrayComponent {
instances: this.componentsMap,
scope: { errors: [] },
processors: [
(context) => this.validationProcessor(context, { dirty, silentCheck })
{
process: validationProcessorProcess,
processSync: validationProcessorProcess
}
]
}).errors;
}
Expand Down Expand Up @@ -1273,7 +1277,7 @@ export default class EditGridComponent extends NestedArrayComponent {
return false;
}

const message = this.invalid || this.invalidMessage(data, dirty);
const message = this.invalid || this.invalidMessage(data, dirty, false, row);
if (allRowErrors.length && this.root?.submitted && !message) {
this._errors = this.setCustomValidity(message, dirty);
errors.push(...this._errors);
Expand Down
2 changes: 1 addition & 1 deletion src/components/tags/Tags.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Tags Component', function() {
assert.equal(tags.errors.length, 1, 'Should set error after Tags component was blurred');
done();
}, 500);
}, 300);
}, 350);
}).catch(done);
});
});
9 changes: 4 additions & 5 deletions test/forms/helpers/testBasicComponentSettings/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ export default {
'validate.custom': {
'Should execute custom validation'(form, done, test) {
test.timeout(3000);
const testComponents = form.components.filter(comp => !['button'].includes(comp.component.type));

assert.deepEqual(form.errors.length, 0, 'Should not show validation errors');
form.setPristine(false);
Expand All @@ -834,9 +833,9 @@ export default {
});

setTimeout(() => {
assert.deepEqual(form.errors.length, testComponents.length, 'Form should contain references to all components errors');
assert.deepEqual(form.errors.length, form.components.length, 'Form should contain references to all components errors');

testComponents.forEach(comp => {
form.components.forEach(comp => {
const compKey = comp.component.key;
const compType = comp.component.type;
const getExpectedErrorMessage = () => 'Custom validation message: component is invalid.';
Expand All @@ -857,13 +856,13 @@ export default {
return _.isNumber(comp.dataValue) ? 33333333 : comp.defaultValue;
};

_.each(testComponents, (comp) => {
_.each(form.components, (comp) => {
comp.setValue(getSetValue(comp));
});

setTimeout(() => {
assert.deepEqual(form.visibleErrors.length, 0, 'Should remove validation errors after setting valid values');
testComponents.forEach(comp => {
form.components.forEach(comp => {
const compKey = comp.component.key;
const compType = comp.component.type;

Expand Down
Loading

0 comments on commit 3fffd2d

Please sign in to comment.