Skip to content

Commit

Permalink
FIO-9259 fixed errors list for parent wizard with nested wizard (#5884)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban authored Oct 29, 2024
1 parent ce4ea45 commit 5b0a8fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
53 changes: 53 additions & 0 deletions test/unit/Wizard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 5b0a8fb

Please sign in to comment.