Skip to content

Commit

Permalink
add mock for useNavigation
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jan 6, 2025
1 parent fb6edfd commit dda9de1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions editor.planx.uk/src/@planx/components/Send/Public.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { SendIntegration } from "@opensystemslab/planx-core/types";
import { waitFor } from "@testing-library/react";
import { screen, waitFor } from "@testing-library/react";
import axios from "axios";
import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { act } from "react-dom/test-utils";
import * as ReactNavi from "react-navi";
import { setup } from "testUtils";
import { it,vi } from "vitest";
import { it, vi } from "vitest";
import { axe } from "vitest-axe";

import hasuraEventsResponseMock from "./mocks/hasuraEventsResponseMock";
Expand All @@ -16,6 +17,10 @@ const { getState, setState } = useStore;

let initialState: FullStore;

vi.spyOn(ReactNavi, "useNavigation").mockImplementation(
() => ({ navigate: vi.fn() }) as any,
);

/**
* Adds a small tick to allow MUI to render (e.g. card transitions)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Link from "@mui/material/Link";
import Typography from "@mui/material/Typography";
import React from "react";
import { useNavigation } from "react-navi";

const NavigateToPublishedButton: React.FC = () => {
const { navigate } = useNavigation();

const handleClick = () => {
navigate("published");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const BUTTON_COMPONENTS = {
"navigate-to-published": NavigateToPublishedButton,
} as const;

const TEST_ENVIRONMENTS = new Set(["preview", "draft"]);

const OrNavigationButton = ({
handleSubmit,
}: {
Expand All @@ -35,7 +37,6 @@ const OrNavigationButton = ({
]);

const endOfUrl = window.location.pathname.split("/").slice(-1)[0];
const TEST_ENVIRONMENTS = new Set(["preview", "draft"]);

const isTestEnvironment: boolean = TEST_ENVIRONMENTS.has(endOfUrl);

Expand Down Expand Up @@ -67,7 +68,7 @@ const OrNavigationButton = ({
ButtonComponent && (
<InnerContainer>
<Typography variant="body1">or</Typography>
{<ButtonComponent />}
<ButtonComponent />
</InnerContainer>
)
);
Expand Down

0 comments on commit dda9de1

Please sign in to comment.