Skip to content

Commit 1b3bf7a

Browse files
committed
[-]: prev callback no-op 보완
1 parent 96f4e83 commit 1b3bf7a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/main/src/core/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const reducer = (state: State, action: Action): State => {
4949
};
5050
}
5151
case ActionType.PREV:
52-
state.tutorial.steps[state.index]?.onPrevStep?.();
5352
if (state.index > 0) {
53+
state.tutorial.steps[state.index]?.onPrevStep?.();
5454
return {
5555
...state,
5656
index: state.index - 1,

packages/main/test/store.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,24 @@ describe('store step callbacks', () => {
4343
expect(onPrevStep).toHaveBeenCalledTimes(1);
4444
expect(screen.getByTestId('title')).toHaveTextContent('Step 1');
4545
});
46+
47+
test('tutorial.prev does not invoke onPrevStep when already on the first step', () => {
48+
const onPrevStep = jest.fn();
49+
50+
render(<StateProbe />);
51+
52+
act(() => {
53+
tutorial.open({
54+
steps: [{ title: 'Step 1', targetIds: ['first-target'], onPrevStep }],
55+
options: {},
56+
});
57+
});
58+
59+
act(() => {
60+
tutorial.prev();
61+
});
62+
63+
expect(onPrevStep).not.toHaveBeenCalled();
64+
expect(screen.getByTestId('title')).toHaveTextContent('Step 1');
65+
});
4666
});

0 commit comments

Comments
 (0)