Skip to content

Commit 0925301

Browse files
committed
Add tests
1 parent ee5bd97 commit 0925301

File tree

2 files changed

+164
-4
lines changed

2 files changed

+164
-4
lines changed

packages/pf4-component-mapper/src/form-fields/wizard/wizard.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class Wizard extends React.Component {
5959

6060
handlePrev = () => this.jumpToStep(this.state.activeStepIndex - 1);
6161

62-
findActiveFields = visitedSteps =>
63-
visitedSteps.map(key =>this.findCurrentStep(key).fields.map(({ name }) => name))
64-
.reduce((acc, curr) => curr.concat(acc.map(item => item)), []);
65-
6662
handleSubmit = (values, visitedSteps, getRegisteredFields) => {
6763
// Add the final step fields to history
6864
const finalRegisteredFieldsHistory = {

packages/pf4-component-mapper/src/tests/wizard/wizard.test.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,168 @@ describe('<Wizard />', () => {
480480

481481
expect(wrapper.find('.pf-c-wizard__nav-item').last().childAt(0).prop('aria-disabled')).toEqual(false);
482482
});
483+
484+
describe('predicting steps', () => {
485+
const FIRST_TITLE = 'Get started with adding source';
486+
const SECOND_TITLE_AWS = 'Configure AWS';
487+
const SECOND_TITLE_GOOLE = 'Configure google';
488+
const THIRD_TITLE = 'Summary';
489+
490+
const wizardSchema = {
491+
fields: [{
492+
component: componentTypes.WIZARD,
493+
name: 'wizard',
494+
predictSteps: true,
495+
fields: [{
496+
title: FIRST_TITLE,
497+
stepKey: 1,
498+
nextStep: {
499+
when: 'source.source-type',
500+
stepMapper: {
501+
aws: 'aws',
502+
google: 'google',
503+
},
504+
},
505+
fields: [{
506+
name: 'source.source-type',
507+
label: 'Source type',
508+
component: componentTypes.TEXT_FIELD,
509+
}],
510+
}, {
511+
title: SECOND_TITLE_AWS,
512+
stepKey: 'aws',
513+
nextStep: 'summary',
514+
fields: [{
515+
component: componentTypes.TEXT_FIELD,
516+
name: 'aws-field',
517+
label: 'Aws field part',
518+
}],
519+
}, {
520+
title: SECOND_TITLE_GOOLE,
521+
stepKey: 'google',
522+
nextStep: 'summary',
523+
fields: [{
524+
component: componentTypes.TEXT_FIELD,
525+
name: 'google.google-field',
526+
label: 'Google field part',
527+
}],
528+
}, {
529+
title: THIRD_TITLE,
530+
fields: [],
531+
stepKey: 'summary',
532+
}],
533+
}],
534+
};
535+
536+
const nextButtonClick = (wrapper) => {
537+
wrapper.find('button').at(0).simulate('click');
538+
wrapper.update();
539+
};
540+
541+
const backButtonClick = (wrapper) => {
542+
wrapper.find('button').at(1).simulate('click');
543+
wrapper.update();
544+
};
545+
546+
const changeValue = (wrapper, value) => {
547+
wrapper.find('input').instance().value = value;
548+
wrapper.find('input').simulate('change');
549+
wrapper.update();
550+
};
551+
552+
it('predict steps with dynamic wizard', () => {
553+
const wrapper = mount(<FormRenderer
554+
schema={ wizardSchema }
555+
formFieldsMapper={ formFieldsMapper }
556+
layoutMapper={ layoutMapper }
557+
onSubmit={ jest.fn() }
558+
onCancel={ jest.fn() }
559+
showFormControls={ false }
560+
/>);
561+
562+
expect(wrapper.find('WizardNavItem')).toHaveLength(1);
563+
expect(wrapper.find('WizardNavItem').at(0).text()).toEqual(FIRST_TITLE);
564+
565+
changeValue(wrapper, 'aws');
566+
nextButtonClick(wrapper);
567+
568+
expect(wrapper.find('WizardNavItem')).toHaveLength(3);
569+
expect(wrapper.find('WizardNavItem').at(0).text()).toEqual(FIRST_TITLE);
570+
expect(wrapper.find('WizardNavItem').at(1).text()).toEqual(SECOND_TITLE_AWS);
571+
expect(wrapper.find('WizardNavItem').at(2).text()).toEqual(THIRD_TITLE);
572+
});
573+
574+
it('reset nav when jumped into compileMapper step', () => {
575+
const wrapper = mount(<FormRenderer
576+
schema={ wizardSchema }
577+
formFieldsMapper={ formFieldsMapper }
578+
layoutMapper={ layoutMapper }
579+
onSubmit={ jest.fn() }
580+
onCancel={ jest.fn() }
581+
showFormControls={ false }
582+
/>);
583+
584+
changeValue(wrapper, 'aws');
585+
nextButtonClick(wrapper);
586+
587+
expect(wrapper.find('WizardNavItem')).toHaveLength(3);
588+
589+
backButtonClick(wrapper);
590+
591+
expect(wrapper.find('WizardNavItem')).toHaveLength(1);
592+
expect(wrapper.find('WizardNavItem').at(0).text()).toEqual(FIRST_TITLE);
593+
});
594+
595+
it('disable nav when jumped into disableForwardJumping step', () => {
596+
const wizardSchema = {
597+
fields: [{
598+
component: componentTypes.WIZARD,
599+
name: 'wizard',
600+
predictSteps: true,
601+
fields: [{
602+
title: FIRST_TITLE,
603+
stepKey: 1,
604+
nextStep: 'aws',
605+
disableForwardJumping: true,
606+
fields: [{
607+
name: 'source.source-type',
608+
label: 'Source type',
609+
component: componentTypes.TEXT_FIELD,
610+
}],
611+
}, {
612+
title: SECOND_TITLE_AWS,
613+
stepKey: 'aws',
614+
nextStep: 'summary',
615+
fields: [{
616+
component: componentTypes.TEXT_FIELD,
617+
name: 'aws-field',
618+
label: 'Aws field part',
619+
}],
620+
}],
621+
}],
622+
};
623+
624+
const wrapper = mount(<FormRenderer
625+
schema={ wizardSchema }
626+
formFieldsMapper={ formFieldsMapper }
627+
layoutMapper={ layoutMapper }
628+
onSubmit={ jest.fn() }
629+
onCancel={ jest.fn() }
630+
showFormControls={ false }
631+
/>);
632+
633+
changeValue(wrapper, 'aws');
634+
nextButtonClick(wrapper);
635+
636+
expect(wrapper.find('WizardNavItem')).toHaveLength(2);
637+
expect(wrapper.find('WizardNavItem').at(0).props().isDisabled).toEqual(false);
638+
expect(wrapper.find('WizardNavItem').at(1).props().isDisabled).toEqual(false);
639+
640+
backButtonClick(wrapper);
641+
642+
expect(wrapper.find('WizardNavItem')).toHaveLength(2);
643+
expect(wrapper.find('WizardNavItem').at(0).props().isDisabled).toEqual(false);
644+
expect(wrapper.find('WizardNavItem').at(1).props().isDisabled).toEqual(true);
645+
});
646+
});
483647
});

0 commit comments

Comments
 (0)