From 79b0f27f58e72f99335909d55a3b411f1ed4220e Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Tue, 29 Oct 2024 13:59:15 +0300 Subject: [PATCH] FIO-9259 fixed errors list for parent wizard with nested wizard --- src/Wizard.js | 2 +- src/components/form/Form.js | 2 +- test/unit/Wizard.unit.js | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/Wizard.js b/src/Wizard.js index 37ffb053cf..35c800f497 100644 --- a/src/Wizard.js +++ b/src/Wizard.js @@ -819,7 +819,7 @@ export default class Wizard extends Webform { else { this.currentPage.components.forEach((comp) => comp.setPristine(false)); this.scrollIntoView(this.element, true); - return Promise.reject(this.showErrors(errors, true)); + return Promise.reject(super.showErrors(errors, true)); } } diff --git a/src/components/form/Form.js b/src/components/form/Form.js index f402414fb2..c9d36281cf 100644 --- a/src/components/form/Form.js +++ b/src/components/form/Form.js @@ -535,7 +535,7 @@ export default class FormComponent extends Component { options = options || {}; const silentCheck = options.silentCheck || false; - if (this.subForm) { + if (this.subForm && !this.isNestedWizard) { return this.subForm.checkValidity(this.subFormData, dirty, null, silentCheck, errors); } diff --git a/test/unit/Wizard.unit.js b/test/unit/Wizard.unit.js index cd9fb0319b..62eab3c671 100644 --- a/test/unit/Wizard.unit.js +++ b/test/unit/Wizard.unit.js @@ -715,6 +715,59 @@ describe('Wizard tests', () => { .catch((err) => done(err)); }); + it('should set correct errors list for parent wizard before clicking on the Next button', function(done) { + const formElement = document.createElement('div'); + const wizard = new Wizard(formElement); + const nestedWizard = _.cloneDeep(wizardTestForm.form); + const parentWizardForm = _.cloneDeep(formWithNestedWizard); + parentWizardForm.components[1].components.push({ + label: 'Parent Text', + applyMaskOn: 'change', + tableView: true, + validate: { + required: true + }, + validateWhenHidden: false, + key: 'parentText', + type: 'textfield', + input: true + }) + const clickEvent = new Event('click'); + + wizard.setForm(parentWizardForm).then(() => { + const nestedFormComp = wizard.getComponent('formNested'); + + nestedFormComp.loadSubForm = ()=> { + nestedFormComp.formObj = nestedWizard; + nestedFormComp.subFormLoading = false; + return new Promise((resolve) => resolve(nestedWizard)); + }; + + nestedFormComp.createSubForm(); + + setTimeout(() => { + const clickWizardBtn = (pathPart) => { + const btn = _.get(wizard.refs, `${wizard.wizardKey}-${pathPart}`); + btn.dispatchEvent(clickEvent); + }; + + clickWizardBtn('link[1]'); + + setTimeout(() => { + assert.equal(wizard.page, 1, `Should open wizard page 2`); + clickWizardBtn('next'); + + setTimeout(() => { + assert.equal(wizard.errors.length, 1); + assert.equal(wizard.refs.errorRef.length, 1, 'Should have an error'); + assert.equal(wizard.errors[0].message, 'Parent Text is required'); + done(); + }, 200); + }, 200); + }, 200) + }) + .catch((err) => done(err)); + }) it('Should execute advanced logic for wizard pages', function(done) { const formElement = document.createElement('div');