@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
90 lines (71 loc) • 2.27 kB
JavaScript
import * as React from "react";
import { cleanup, renderHook } from "@testing-library/react-hooks";
import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
import { waitFor } from "@testing-library/react-native";
const navigator = {
getPathname: () => "pathnameMock",
push: jest.fn(),
data: {},
};
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
useNavigation: () => navigator,
useRoute: () => ({ pathname: "pathnameMock" }),
useProfilerLogging: () => {
return jest.fn();
},
}));
jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils/", () => ({
useAnalytics: () => ({
sendOnClickEvent: jest.fn(),
}),
}));
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
ZappPipesEntryContext: {
useZappPipesContext: jest.fn(() => [undefined, jest.fn()]),
},
}));
const { useCellClick } = require("../");
const mockProps = {
item: {},
component: {
rules: {
component_cells_selectable: true,
},
},
index: 0,
};
const onCellTap = jest.fn();
const actionExecutor = {
handleEntryActions: jest.fn(() => Promise.resolve()),
};
const wrapper = ({ children }) => (
<CellTapContext.Provider value={onCellTap}>
<ActionExecutorContext.Provider value={actionExecutor}>
{children}
</ActionExecutorContext.Provider>
</CellTapContext.Provider>
);
describe("useCellClick", () => {
it("returns a function", () => {
const { result } = renderHook(() => useCellClick(mockProps));
expect(typeof result.current).toBe("function");
cleanup();
});
it("runs default logic", () => {
const { result } = renderHook(() => useCellClick(mockProps));
const useCellClickHook = result.current;
useCellClickHook();
expect(onCellTap).not.toHaveBeenCalled();
cleanup();
});
it("runs onCellTap", async () => {
const { result } = renderHook(() => useCellClick(mockProps), { wrapper });
const useCellClickHook = result.current;
useCellClickHook();
await waitFor(() => {
expect(onCellTap).toHaveBeenCalled();
});
cleanup();
});
});