Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hooks/useTourEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@

useUpdateEffect(() => {
if (run && size && status === STATUS.IDLE) {
store.current.updateState({ status: STATUS.READY });
if (validateSteps(steps, debug)) {
controls.start(stepIndex ?? initialStepIndex);
} else {
store.current.updateState({ status: STATUS.READY });
}
}
}, [run, size, status]);
}, [controls, debug, initialStepIndex, run, size, status, stepIndex, steps]);

usePropSync({
controls,
Expand All @@ -82,7 +86,7 @@
store,
});

useLifecycleEffect({

Check warning on line 89 in src/hooks/useTourEngine.ts

View workflow job for this annotation

GitHub Actions / validate

React Hook useLifecycleEffect received a function whose dependencies are unknown. Pass an inline function instead
addFailure,
controls,
emitEvent,
Expand All @@ -93,7 +97,7 @@
store,
});

useScrollEffect({

Check warning on line 100 in src/hooks/useTourEngine.ts

View workflow job for this annotation

GitHub Actions / validate

React Hook useScrollEffect received a function whose dependencies are unknown. Pass an inline function instead
emitEvent,
previousState,
props: mergedProps,
Expand Down
20 changes: 20 additions & 0 deletions test/hooks/useTourEngine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,26 @@ describe('useTourEngine', () => {
expect(result.current.state.size).toBe(3);
});
});

it('should start the tour when run is already true and steps arrive after mount', async () => {
const { rerender, result } = renderHook((props: Props) => useTourEngine(props), {
initialProps: createProps({ run: true, steps: [] }),
});

expect(result.current.state.status).toBe(STATUS.IDLE);
expect(mockOnEvent).not.toHaveBeenCalled();

rerender(createProps({ run: true, steps: testSteps }));

await waitFor(() => {
expect(result.current.state.status).toBe(STATUS.RUNNING);
});

expect(mockOnEvent).toHaveBeenCalledWith(
expect.objectContaining({ type: EVENTS.TOUR_START }),
expectControls(),
);
});
});

describe('Scroll', () => {
Expand Down
Loading