Skip to content

Commit

Permalink
FIO-9350 Wizard: Simplify async flow for flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
blakekrammes committed Nov 25, 2024
1 parent 87eeb2f commit f24a926
Showing 1 changed file with 53 additions and 65 deletions.
118 changes: 53 additions & 65 deletions test/unit/Wizard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,80 +317,68 @@ describe('Wizard tests', () => {
.catch((err) => done(err));
});

it('Should show conditional page inside nested wizard', function(done) {
it.only('Should show conditional page inside nested wizard', async () => {
const formElement = document.createElement('div');
const wizard = new Wizard(formElement);
const nestedWizard = _.cloneDeep(wizardTestForm.form);
nestedWizard.components[2].conditional = { show: true, when: 'checkbox', eq: 'true' };

wizard.setForm(formWithNestedWizard).then(() => {
const nestedFormComp = wizard.getComponent('formNested');

nestedFormComp.loadSubForm = ()=> {
nestedFormComp.formObj = nestedWizard;
nestedFormComp.subFormLoading = false;
return new Promise((resolve) => resolve(nestedWizard));
};

nestedFormComp.createSubForm();

setTimeout(() => {
const checkPage = (pageNumber) => {
assert.equal(wizard.page, pageNumber, `Should open wizard page ${pageNumber + 1}`);
};

checkPage(0);
assert.equal(wizard.pages.length, 4, 'Should have 4 pages');
assert.equal(wizard.allPages.length, 4, 'Should have 4 pages');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 4, 'Should contain refs to breadcrumbs of parent and nested wizard');

clickWizardBtn(wizard, 'link[3]');

setTimeout(() => {
checkPage(3);

assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should hav submit btn on the last page');
wizard.getComponent('checkbox').setValue(true);

setTimeout(() => {
checkPage(3);

assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should have submit btn on the last page');
wizard.getComponent('checkbox').setValue(true);

setTimeout(() => {
checkPage(3);
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], false, 'Should not have submit btn ');
assert.equal(wizard.pages.length, 5, 'Should show conditional page');
assert.equal(wizard.allPages.length, 5, 'Should show conditional page');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 5, 'Should contain refs to breadcrumbs of visible conditional page');

clickWizardBtn(wizard, 'next');
await wizard.setForm(formWithNestedWizard);

const nestedFormComp = wizard.getComponent('formNested');

setTimeout(() => {
checkPage(4);
clickWizardBtn(wizard, 'previous');
nestedFormComp.loadSubForm = () => {
nestedFormComp.formObj = nestedWizard;
nestedFormComp.subFormLoading = false;
return new Promise((resolve) => resolve(nestedWizard));
};

setTimeout(() => {
checkPage(3);
wizard.getComponent('checkbox').setValue(false);
nestedFormComp.createSubForm();
await wait(300);

setTimeout(() => {
assert.equal(wizard.pages.length, 4, 'Should hide conditional page');
assert.equal(wizard.allPages.length, 4, 'Should hide conditional page');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 4, 'Should contain refs to breadcrumbs of visible pages');
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should have submit btn on the last page');
const checkPage = (pageNumber) => {
assert.equal(wizard.page, pageNumber, `Should open wizard page ${pageNumber + 1}`);
};

checkPage(0);
assert.equal(wizard.pages.length, 4, 'Should have 4 pages');
assert.equal(wizard.allPages.length, 4, 'Should have 4 pages');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 4, 'Should contain refs to breadcrumbs of parent and nested wizard');

done();
}, 500);
}, 300);
}, 300);
}, 500);
}, 300);
}, 300);
}, 300);
})
.catch((err) => done(err));
clickWizardBtn(wizard, 'link[3]');
await wait(300);

checkPage(3);
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should hav submit btn on the last page');
wizard.getComponent('checkbox').setValue(true);
await wait(300);

checkPage(3);
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should have submit btn on the last page');
wizard.getComponent('checkbox').setValue(true);
await wait(500);

checkPage(3);
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], false, 'Should not have submit btn ');
assert.equal(wizard.pages.length, 5, 'Should show conditional page');
assert.equal(wizard.allPages.length, 5, 'Should show conditional page');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 5, 'Should contain refs to breadcrumbs of visible conditional page');

clickWizardBtn(wizard, 'next');
await wait(300);

checkPage(4);
clickWizardBtn(wizard, 'previous');
await wait(300);

checkPage(3);
wizard.getComponent('checkbox').setValue(false);
await wait(500);

assert.equal(wizard.pages.length, 4, 'Should hide conditional page');
assert.equal(wizard.allPages.length, 4, 'Should hide conditional page');
assert.equal(wizard.refs[`${wizard.wizardKey}-link`].length, 4, 'Should contain refs to breadcrumbs of visible pages');
assert.deepEqual(!!wizard.refs[`${wizard.wizardKey}-submit`], true, 'Should have submit btn on the last page');
}).timeout(6000);

it('Should trigger validation of nested wizard before going to the next page', function (done) {
Expand Down

0 comments on commit f24a926

Please sign in to comment.