Skip to content

Commit 60b8929

Browse files
committed
Add dynamic step test cases
1 parent 0dcb798 commit 60b8929

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/useWizard.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)