From 992379cf93c5bf1bc0dcfef0fbd09b176d0a9aa2 Mon Sep 17 00:00:00 2001 From: Gil Barbara Date: Tue, 20 Feb 2024 21:03:04 -0300 Subject: [PATCH] Fix overlay not rendering on tour restart --- src/components/Step.tsx | 4 +- .../__snapshots__/standard.spec.tsx.snap | 124 ++++++++++++++++++ test/tours/standard.spec.tsx | 22 ++++ 3 files changed, 148 insertions(+), 2 deletions(-) diff --git a/src/components/Step.tsx b/src/components/Step.tsx index 6eec3c0f..62f8c8e8 100644 --- a/src/components/Step.tsx +++ b/src/components/Step.tsx @@ -184,7 +184,7 @@ export default class JoyrideStep extends React.Component { }; setPopper: FloaterProps['getPopper'] = (popper, type) => { - const { action, step, store } = this.props; + const { action, lifecycle, step, store } = this.props; if (type === 'wrapper') { store.setPopper('beacon', popper); @@ -192,7 +192,7 @@ export default class JoyrideStep extends React.Component { store.setPopper('tooltip', popper); } - if (store.getPopper('beacon') && store.getPopper('tooltip')) { + if (store.getPopper('beacon') && store.getPopper('tooltip') && lifecycle === LIFECYCLE.INIT) { store.update({ action, lifecycle: LIFECYCLE.READY, diff --git a/test/tours/__snapshots__/standard.spec.tsx.snap b/test/tours/__snapshots__/standard.spec.tsx.snap index 331b272e..39d2dcf9 100644 --- a/test/tours/__snapshots__/standard.spec.tsx.snap +++ b/test/tours/__snapshots__/standard.spec.tsx.snap @@ -106,6 +106,130 @@ exports[`Joyride > Standard should render the content 1`] = ` `; +exports[`Joyride > Standard should restart the tour: beacon 1`] = ` + +`; + +exports[`Joyride > Standard should restart the tour: tooltip 1`] = ` +
+
+
+
+
+ The first step of many! Keep walking! +
+
+
+
+ +
+ +
+ +
+
+ + + + + +
+
+
+`; + exports[`Joyride > Standard should start the tour 1`] = `
Standard', () => { expect(mockGetPopper).toHaveBeenCalledTimes(13); }); + + it('should restart the tour', async () => { + mockCallback.mockClear(); + mockGetPopper.mockClear(); + + fireEvent.click(screen.getByTestId('start')); + + await waitFor(() => { + expect(mockCallback).toHaveBeenCalledTimes(3); + }); + + expect(screen.getByTestId('button-beacon')).toMatchSnapshot('beacon'); + + fireEvent.click(screen.getByTestId('button-beacon')); + + await waitFor(() => { + expect(mockCallback).toHaveBeenCalledTimes(4); + }); + + expect(screen.getById('react-joyride-step-0').querySelector('div')).toMatchSnapshot('tooltip'); + expect(screen.getByTestId('overlay')).toBeInTheDocument(); + }); });