@@ -920,5 +920,155 @@ describe('<Wizard />', () => {
920920 expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
921921 expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
922922 } ) ;
923+
924+ it ( 'crossroads variable predicts in realtime' , ( ) => {
925+ const wizardSchema = {
926+ fields : [ {
927+ component : componentTypes . WIZARD ,
928+ name : 'wizard' ,
929+ predictSteps : true ,
930+ crossroads : [ 'source.source-type' ] ,
931+ fields : [ {
932+ title : 'first-step' ,
933+ stepKey : 1 ,
934+ nextStep : {
935+ when : 'source.source-type' ,
936+ stepMapper : {
937+ aws : 'aws' ,
938+ google : 'summary' ,
939+ } ,
940+ } ,
941+ fields : [ {
942+ name : 'source.source-type' ,
943+ label : 'Source type' ,
944+ component : componentTypes . TEXT_FIELD ,
945+ } ] ,
946+ } , {
947+ title : 'second-step' ,
948+ stepKey : 'aws' ,
949+ nextStep : 'summary' ,
950+ fields : [ ] ,
951+ } ,
952+ {
953+ title : 'summary' ,
954+ stepKey : 'summary' ,
955+ fields : [ ] ,
956+ } ] ,
957+ } ] ,
958+ } ;
959+
960+ const wrapper = mount ( < FormRenderer
961+ { ...initialProps }
962+ schema = { wizardSchema }
963+ /> ) ;
964+
965+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 1 ) ;
966+
967+ changeValue ( wrapper , 'aws' ) ;
968+
969+ // predict steps for aws
970+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 3 ) ;
971+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
972+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
973+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 2 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
974+
975+ changeValue ( wrapper , 'google' ) ;
976+
977+ // predict steps for google
978+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
979+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
980+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
981+
982+ nextButtonClick ( wrapper ) ;
983+
984+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
985+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
986+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
987+
988+ // click on first nav link
989+ wrapper . find ( '.pf-c-wizard__nav-item' ) . first ( ) . childAt ( 0 ) . simulate ( 'click' ) ;
990+ wrapper . update ( ) ;
991+
992+ // keep the second step enabled
993+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
994+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
995+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
996+
997+ changeValue ( wrapper , 'aws' ) ;
998+
999+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 3 ) ;
1000+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
1001+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
1002+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 2 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
1003+
1004+ changeValue ( wrapper , 'google' ) ;
1005+
1006+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
1007+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
1008+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
1009+ } ) ;
1010+
1011+ it ( 'crossroads variable predicts in realtime - disableForwardJumping' , ( ) => {
1012+ const wizardSchema = {
1013+ fields : [ {
1014+ component : componentTypes . WIZARD ,
1015+ name : 'wizard' ,
1016+ predictSteps : true ,
1017+ crossroads : [ 'source.source-type' ] ,
1018+ fields : [ {
1019+ title : 'first-step' ,
1020+ stepKey : 1 ,
1021+ nextStep : {
1022+ when : 'source.source-type' ,
1023+ stepMapper : {
1024+ aws : 'aws' ,
1025+ google : 'summary' ,
1026+ } ,
1027+ } ,
1028+ disableForwardJumping : true ,
1029+ fields : [ {
1030+ name : 'source.source-type' ,
1031+ label : 'Source type' ,
1032+ component : componentTypes . TEXT_FIELD ,
1033+ } ] ,
1034+ } , {
1035+ title : 'second-step' ,
1036+ stepKey : 'aws' ,
1037+ nextStep : 'summary' ,
1038+ fields : [ ] ,
1039+ } ,
1040+ {
1041+ title : 'summary' ,
1042+ stepKey : 'summary' ,
1043+ fields : [ ] ,
1044+ } ] ,
1045+ } ] ,
1046+ } ;
1047+
1048+ const wrapper = mount ( < FormRenderer
1049+ { ...initialProps }
1050+ schema = { wizardSchema }
1051+ /> ) ;
1052+
1053+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 1 ) ;
1054+
1055+ changeValue ( wrapper , 'google' ) ;
1056+
1057+ // predict steps for google
1058+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
1059+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
1060+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
1061+
1062+ nextButtonClick ( wrapper ) ;
1063+
1064+ // click on first nav link
1065+ wrapper . find ( '.pf-c-wizard__nav-item' ) . first ( ) . childAt ( 0 ) . simulate ( 'click' ) ;
1066+ wrapper . update ( ) ;
1067+
1068+ // keep the second step enabled
1069+ expect ( wrapper . find ( 'WizardNavItem' ) ) . toHaveLength ( 2 ) ;
1070+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 0 ) . props ( ) . isDisabled ) . toEqual ( false ) ;
1071+ expect ( wrapper . find ( 'WizardNavItem' ) . at ( 1 ) . props ( ) . isDisabled ) . toEqual ( true ) ;
1072+ } ) ;
9231073 } ) ;
9241074} ) ;
0 commit comments