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
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ describe('guided-tour-context', () => {
expect(tour).toEqual(null);
expect(totalSteps).toEqual(undefined);
});

it('should not flash startTour when loaded transitions to true with completed tour', () => {
useSelectorMock.mockReturnValue({ A: true, B: false });
useResolvedExtensionsMock.mockReturnValue(mockTourExtension);
// Start with loaded: false (async ConfigMap fetch in progress)
useUserPreferenceMock.mockReturnValue([{ dev: { completed: false } }, () => null, false]);
const { result, rerender } = renderHook(() => useTourValuesForContext());
expect(result.current.tour).toEqual(null);

// Simulate ConfigMap load completing with completed: true
useUserPreferenceMock.mockReturnValue([{ dev: { completed: true } }, () => null, true]);
rerender();
const { tourState } = result.current;
expect(tourState?.startTour).not.toBe(true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
expect(tourState?.startTour).not.toBe(true);
expect(tourState?.startTour).toBe(false);

});
Comment thread
Cragsmann marked this conversation as resolved.
});

describe('useTourStatePerspective', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Reducer, Dispatch, ReducerAction } from 'react';
import { createContext, useReducer, useState, useEffect, useCallback } from 'react';
import { createContext, useReducer, useRef, useState, useEffect, useCallback } from 'react';
import { pick, union, isEqual } from 'lodash';
import { createSelector } from 'reselect';
import { useActivePerspective } from '@console/dynamic-plugin-sdk';
Expand Down Expand Up @@ -151,14 +151,18 @@ export const useTourValuesForContext = (): TourContextType => {
startTour: !completed,
});

const initializedWithLoadedData = useRef(false);
useEffect(() => {
tourDispatch({ type: TourActions.initialize, payload: { completed } });
setPerspective(activePerspective);
if (loaded) {
initializedWithLoadedData.current = true;
}
// only run effect when the active perspective changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activePerspective, loaded]);

if (!tour || !loaded) return { tour: null };
if (!tour || !loaded || !initializedWithLoadedData.current) return { tour: null };
const {
properties: {
tour: { intro, steps: unfilteredSteps, end },
Expand Down