UNPKG

@applicaster/zapp-react-native-ui-components

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

147 lines (121 loc) 3.7 kB
import React from "react"; import TestRenderer from "react-test-renderer"; import { cleanup } from "@testing-library/react-native"; import { Provider } from "react-redux"; import configureStore from "redux-mock-store"; import * as themeUtils from "@applicaster/zapp-react-native-utils/theme"; // silences the errors related to React-native-gesture-handler in tests jest.mock( "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation", () => () => null ); jest.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ top: 50 }), })); jest.mock("react-native", () => { const RN = jest.genMockFromModule("react-native"); const actualRN = jest.requireActual("react-native"); const Dims = { get: jest .fn() .mockReturnValue({ width: 100, height: 100, scale: 1, fontScale: 1 }), addEventListener: jest.fn(), removeEventListener: jest.fn(), }; const Easing = { in: jest.fn(), bezier: jest.fn(), }; return { ...RN, Platform: { OS: "ios" }, NativeModules: { QuickBrickCommunicationModule: {}, UIManager: {} }, StyleSheet: { create: jest.fn((x) => x) }, FlatList: actualRN.FlatList, View: actualRN.View, Dimensions: Dims, ActivityIndicator: actualRN.ActivityIndicator, Animated: { timing: jest.fn(() => ({ start: jest.fn() })), Value: function AnimatedValue() { return {}; }, View: actualRN.Animated.View, }, findNodeHandle: jest.fn(), NativeEventEmitter: jest.fn(), requireNativeComponent: jest.fn(), Easing, }; }); const mock_rtl_flag = false; const riverComponents = [ { id: "A1", component_type: "hero", styles: { cell_styles: ["some", "obsolete", "ids"], }, }, { id: "A2", component_type: "grid", styles: { master_cell_id: "uuid-5678-B", }, }, ]; const screenData = { ui_components: riverComponents, rules: { pull_to_refresh_enabled: false }, id: "A1234", }; jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({ useIsRTL: jest.fn(() => mock_rtl_flag), })); jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({ useNavigation: jest.fn(() => ({ currentRoute: "/river/A1234" })), useRoute: jest.fn(() => ({ pathname: "/river/A1234", screenData })), useProfilerLogging: jest.fn(), useIsScreenActive: jest.fn().mockReturnValue(true), })); jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({ useCurrentScreenData: jest.fn(() => screenData), useScreenData: jest.fn(() => screenData), useScreenContext: jest.fn(() => screenData), })); const { View } = require("react-native"); const { ComponentsMap } = require("../ComponentsMap/ComponentsMap"); const theme = require("./theme-mock.json"); const mockStore = configureStore(); const components = { Hero: jest.fn(() => <View />), Grid: jest.fn(() => <View />), }; const cellStyles = { "uuid-1234-A": {}, "uuid-5678-B": {}, }; const plugins = []; const navigation = {}; const props = { components, cellStyles, riverComponents, navigation }; const store = mockStore({ components, cellStyles, plugins }); jest.useFakeTimers(); describe("componentsMap", () => { let themeSpy; afterEach(() => { themeSpy.mockClear(); cleanup(); }); it("renders renders components map correctly", () => { themeSpy = jest .spyOn(themeUtils, "useTheme") .mockImplementation(() => () => theme); const wrapper = TestRenderer.create( <Provider store={store}> <ComponentsMap {...props} /> </Provider> ); expect(wrapper.toJSON()).toMatchSnapshot(); }); });