Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Apr 12, 2024
1 parent b8f6f1e commit 6437416
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 142 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"core-js": "^3.36.0",
"dialog-polyfill": "^0.5.6",
"dom-autoscroller": "^2.3.4",
"dompurify": "^3.0.9",
"dompurify": "^3.1.0",
"downloadjs": "^1.4.7",
"dragula": "^3.7.3",
"eventemitter3": "^5.0.1",
Expand All @@ -122,8 +122,8 @@
"vanilla-picker": "^2.12.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.3.0",
"@typescript-eslint/parser": "^7.3.0",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"ace-builds": "1.32.9",
"async-limiter": "^2.0.0",
"bootstrap-icons": "^1.10.5",
Expand Down Expand Up @@ -170,15 +170,15 @@
"pretty": "^2.0.0",
"pygments-css": "^1.0.0",
"raw-loader": "^4.0.2",
"sass": "^1.72.0",
"sass": "^1.74.1",
"shortcut-buttons-flatpickr": "^0.4.0",
"sinon": "^17.0.1",
"string-replace-loader": "^3.1.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "5.3.3",
"typescript": "5.4.5",
"webpack": "^5.90.3",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.1",
"webpack-node-externals": "^3.0.0",
"webpack-stream": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ export default class Webform extends NestedDataComponent {
if (this.submitted) {
// show server errors while they are not cleaned/fixed
const nonComponentServerErrors = _.filter(this.serverErrors || [], err => !err.component && !err.path);
this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : null);
this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : errors);
}

// See if we need to save the draft of the form.
Expand Down
55 changes: 26 additions & 29 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,49 +109,47 @@ describe('Webform tests', function() {
number2.setValue(7);
setTimeout(()=> {
assert.equal(form.errors.length, 1);
assert.equal(!!number.error, true);

assert.equal(number.errors.length, 1);
errorClasses.forEach(cl => assert.equal(number.element.classList.contains(cl), false, '(1) Should not set error classes for hidden components.'));
number2.setValue(3);

setTimeout(() => {
assert.equal(form.errors.length, 0);
assert.equal(!!number.error, false);
assert.equal(number.errors.length, 0);
errorClasses.forEach(cl => assert.equal(number.element.classList.contains(cl), false, '(2) Should not set error classes for hidden components.'));

textField.setValue('test');
setTimeout(() => {
assert.equal(form.errors.length, 1);
assert.equal(!!textArea.error, true);
assert.equal(textArea.errors.length, 1);
assert.equal(textArea.visible, true);

checkbox.setValue(true);
setTimeout(()=> {
assert.equal(textArea.visible, false);
assert.equal(form.errors.length, 1);
assert.equal(!!textArea.error, true);
assert.equal(textArea.errors.length, 1);
errorClasses.forEach(cl => assert.equal(textArea.element.classList.contains(cl), false));

number2.setValue(9);
form.submit();
setTimeout(()=> {
assert.equal(form.errors.length, 2);
assert.equal(!!textArea.error, true);
assert.equal(!!number.error, true);
assert.equal(!!form.alert, true);
assert.equal(form.refs.errorRef.length, 2);
errorClasses.forEach(cl => assert.equal(number.element.classList.contains(cl), false));
errorClasses.forEach(cl => assert.equal(textArea.element.classList.contains(cl), false));

textField.setValue('test test test');
number2.setValue(1);
setTimeout(() => {
form.submit();
setTimeout(()=> {
assert.equal(form.errors.length, 0);
assert.equal(!!textArea.error, false);
assert.equal(!!number.error, false);
assert.equal(!!form.alert, false);

done();
assert.equal(form.errors.length, 2);
assert.equal(textArea.errors.length, 1);
assert.equal(number.errors.length, 1);
assert.equal(!!form.alert, true);
assert.equal(form.refs.errorRef.length, 2);
errorClasses.forEach(cl => assert.equal(number.element.classList.contains(cl), false));
errorClasses.forEach(cl => assert.equal(textArea.element.classList.contains(cl), false));
textField.setValue('test test test');
number2.setValue(1);
setTimeout(()=> {
assert.equal(form.errors.length, 0);
assert.equal(textArea.errors.length, 0);
assert.equal(number.errors.length, 0);
assert.equal(!!form.alert, false);
done();
}, 300);
}, 300);
}, 300);
}, 300);
Expand Down Expand Up @@ -185,19 +183,19 @@ describe('Webform tests', function() {
number2.setValue(7);
setTimeout(()=> {
assert.equal(form.errors.length, 0);
assert.equal(!!number.error, false);
assert.equal(number.errors.length, 0);

textField.setValue('test');
setTimeout(() => {
assert.equal(form.errors.length, 1);
assert.equal(!!textArea.error, true);
assert.equal(textArea.errors.length, 1);
assert.equal(textArea.visible, true);

checkbox.setValue(true);
setTimeout(()=> {
assert.equal(textArea.visible, false);
assert.equal(form.errors.length, 0);
assert.equal(!!textArea.error, false);
assert.equal(textArea.errors.length, 0);
done();
}, 300);
}, 300);
Expand Down Expand Up @@ -1272,8 +1270,7 @@ describe('Webform tests', function() {
.catch((err) => done(err));
});

it(`Should show validation errors and update validation errors list when opening and editing edit grid rows
in draft modal mode after pushing submit btn`, function(done) {
it('Should show validation errors and update validation errors list when opening and editing edit grid rows in draft modal mode after pushing submit btn', function(done) {
const formElement = document.createElement('div');
const formWithDraftModals = new Webform(formElement, { sanitize: true });

Expand Down
9 changes: 6 additions & 3 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3418,6 +3418,11 @@ export default class Component extends Element {

shouldSkipValidation(data, row, flags = {}) {
const { validateWhenHidden = false } = this.component || {};
const forceValidOnHidden = (!this.visible || !this.checkCondition(row, data)) && !validateWhenHidden;
if (forceValidOnHidden) {
// If this component is forced valid when it is hidden, then we also need to reset the errors for this component.
this._errors = [];
}
const rules = [
// Do not validate if the flags say not too.
() => flags.noValidate,
Expand All @@ -3428,9 +3433,7 @@ export default class Component extends Element {
// Check to see if we are editing and if so, check component persistence.
() => this.isValueHidden(),
// Force valid if component is hidden.
() => !this.visible && !validateWhenHidden,
// Force valid if component is conditionally hidden.
() => !this.checkCondition(row, data) && !validateWhenHidden
() => forceValidOnHidden
];

return rules.some(pred => pred());
Expand Down
2 changes: 1 addition & 1 deletion src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ describe('Select Component', () => {
var searchHasBeenDebounced = false;
var originalDebounce = _.debounce;
_.debounce = (fn, timeout, opts) => {
searchHasBeenDebounced = timeout === 700;
searchHasBeenDebounced = true;
return originalDebounce(fn, 0, opts);
};

Expand Down
Loading

0 comments on commit 6437416

Please sign in to comment.