From f24a9262c85ce01867a2d090c90d8209d177e6ff Mon Sep 17 00:00:00 2001 From: Blake Krammes <49688912+blakekrammes@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:27:40 -0600 Subject: [PATCH] FIO-9350 Wizard: Simplify async flow for flaky test --- test/unit/Wizard.unit.js | 118 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 65 deletions(-) diff --git a/test/unit/Wizard.unit.js b/test/unit/Wizard.unit.js index 411249ad17..c9f5c0c933 100644 --- a/test/unit/Wizard.unit.js +++ b/test/unit/Wizard.unit.js @@ -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) {