File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -224,4 +224,56 @@ describe('useWizard', () => {
224224 }
225225 } ) ;
226226 } ) ;
227+
228+ test ( 'should update step count when dynamic step is added' , ( ) => {
229+ const steps = [ 'one' , 'two' , 'three' ] ;
230+
231+ const { result, rerender } = renderHook ( ( ) => useWizard ( ) , {
232+ initialProps : {
233+ startIndex : 0 ,
234+ } ,
235+ wrapper : ( { children, startIndex } ) => (
236+ < Wizard startIndex = { startIndex } >
237+ { steps . map ( ( step ) => (
238+ < p key = { step } > { children } </ p >
239+ ) ) }
240+ </ Wizard >
241+ ) ,
242+ } ) ;
243+
244+ expect ( result . current . stepCount ) . toBe ( 3 ) ;
245+
246+ steps . push ( 'four' ) ;
247+ rerender ( ) ;
248+
249+ expect ( result . current . stepCount ) . toBe ( 4 ) ;
250+ } ) ;
251+
252+ test ( 'should go to step index of dynamic step' , ( ) => {
253+ const steps = [ 'one' , 'two' , 'three' ] ;
254+
255+ const { result, rerender } = renderHook ( ( ) => useWizard ( ) , {
256+ initialProps : {
257+ startIndex : 0 ,
258+ } ,
259+ wrapper : ( { children, startIndex } ) => (
260+ < Wizard startIndex = { startIndex } >
261+ { steps . map ( ( step ) => (
262+ < p key = { step } > { children } </ p >
263+ ) ) }
264+ </ Wizard >
265+ ) ,
266+ } ) ;
267+
268+ steps . push ( 'four' ) ;
269+ rerender ( ) ;
270+
271+ act ( ( ) => {
272+ result . current . goToStep ( 3 ) ;
273+ } ) ;
274+
275+ expect ( result . current . activeStep ) . toBe ( 3 ) ;
276+ expect ( result . current . isFirstStep ) . toBe ( false ) ;
277+ expect ( result . current . isLastStep ) . toBe ( true ) ;
278+ } ) ;
227279} ) ;
You can’t perform that action at this time.
0 commit comments