Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Oct 26, 2022
1 parent ba8b78c commit 251a42e
Showing 1 changed file with 8 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import { SecurityStepId, securityTourConfig } from './tour_config';
import { useKibana } from '../../lib/kibana';

jest.mock('../../lib/kibana');
jest.mock('react-router-dom', () => {
const original = jest.requireActual('react-router-dom');

return {
...original,
useLocation: jest.fn().mockReturnValue({ pathname: '/alerts' }),
};
});

describe('useTourContext', () => {
const mockCompleteGuideStep = jest.fn();
Expand Down Expand Up @@ -82,46 +90,4 @@ describe('useTourContext', () => {
});
});
});
it('when the tourStatus changes, reset active step to 1', async () => {
(useKibana as jest.Mock).mockReturnValue({
services: {
guidedOnboarding: {
guidedOnboardingApi: {
isGuideStepActive$: (_: string, currentStep: SecurityStepId) =>
of(currentStep === SecurityStepId.alertsCases),
},
},
},
});
await act(async () => {
const { result, waitForNextUpdate, rerender } = renderHook(() => useTourContext(), {
wrapper: TourContextProvider,
});
await waitForNextUpdate();

// set SecurityStepId.alertsCases activeStep to 3
result.current.incrementStep(SecurityStepId.alertsCases, 3);
expect(result.current.activeStep).toBe(3);
expect(result.current.isTourShown(SecurityStepId.alertsCases)).toBe(true);
expect(result.current.isTourShown(SecurityStepId.rules)).toBe(false);

// update active step to be SecurityStepId.rules
(useKibana as jest.Mock).mockReturnValue({
services: {
guidedOnboarding: {
guidedOnboardingApi: {
isGuideStepActive$: (_: string, currentStep: SecurityStepId) =>
of(currentStep === SecurityStepId.rules),
},
},
},
});
rerender();

// check that activeStep has been reset
expect(result.current.activeStep).toBe(1);
expect(result.current.isTourShown(SecurityStepId.alertsCases)).toBe(false);
expect(result.current.isTourShown(SecurityStepId.rules)).toBe(true);
});
});
});

0 comments on commit 251a42e

Please sign in to comment.