Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Nov 8, 2022
1 parent 3b91a69 commit 2df8a1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('useTourContext', () => {
jest.clearAllMocks();
});
// @ts-ignore
const stepIds = Object.values(SecurityStepId);
describe.each(stepIds)('%s', (stepId) => {
const stepIds = [SecurityStepId.alertsCases];
describe.each(stepIds)('%s', (stepId: SecurityStepId) => {
it('if guidedOnboardingApi?.isGuideStepActive$ is false, isTourShown should be false', () => {
(useKibana as jest.Mock).mockReturnValue({
services: {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('useTourContext', () => {
});
expect(result.current.activeStep).toBe(1);
});
it('increment step properly increments for each stepId, and if attempted to increment beyond length of tour config steps resets activeStep to 1', async () => {
it('incrementStep properly increments for each stepId, and if attempted to increment beyond length of tour config steps resets activeStep to 1', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() => useTourContext(), {
wrapper: TourContextProvider,
Expand All @@ -96,5 +96,16 @@ describe('useTourContext', () => {
expect(result.current.activeStep).toBe(1);
});
});

it('when provided, incrementStep sets activeStep to step number argument', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() => useTourContext(), {
wrapper: TourContextProvider,
});
await waitForNextUpdate();
result.current.incrementStep(stepId, 7);
expect(result.current.activeStep).toBe(7);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const CaseDetailsLinkComponent: React.FC<{
const { formatUrl, search } = useFormatUrl(SecurityPageName.case);
const { navigateToApp } = useKibana().services.application;
const { activeStep, isTourShown } = useTourContext();
const isTourActive = useMemo(
const isTourStepActive = useMemo(
() =>
activeStep === AlertsCasesTourSteps.viewCase &&
isTourShown(SecurityStepId.alertsCases) &&
Expand All @@ -279,7 +279,7 @@ const CaseDetailsLinkComponent: React.FC<{
const goToCaseDetails = useCallback(
async (ev?) => {
if (ev) ev.preventDefault();
await navigateToApp(APP_UI_ID, {
return navigateToApp(APP_UI_ID, {
deepLinkId: SecurityPageName.case,
path: getCaseDetailsUrl({ id: detailName, search }),
});
Expand All @@ -288,14 +288,14 @@ const CaseDetailsLinkComponent: React.FC<{
);

useEffect(() => {
if (isTourActive)
if (isTourStepActive)
document.querySelector(`[tour-step="RelatedCases-accordion"]`)?.scrollIntoView();
}, [isTourActive]);
}, [isTourStepActive]);

return (
<GuidedOnboardingTourStep
onClick={goToCaseDetails}
isTourAnchor={isTourActive}
isTourAnchor={isTourStepActive}
step={AlertsCasesTourSteps.viewCase}
stepId={SecurityStepId.alertsCases}
>
Expand Down

0 comments on commit 2df8a1c

Please sign in to comment.