UNPKG

@applicaster/quick-brick-core

Version:

Core package for Applicaster's Quick Brick App

130 lines (109 loc) 2.89 kB
import * as React from "react"; import { View, Text } from "react-native"; import { render, screen } from "@testing-library/react-native"; import QuickBrickComponents from "@applicaster/zapp-react-native-ui-components"; import { Provider } from "react-redux"; import { createZappApp } from "../index"; const components = QuickBrickComponents; const cellStyles = {}; const plugin1 = { module: jest.fn(), name: "Plugin1", type: "general", identifier: "pc1", }; const plugin2 = { module: jest.fn(), name: "Plugin2", type: "general", identifier: "pc2", }; const plugins = [plugin1, plugin2]; const styles = {}; const pipesEndpoints = {}; const rivers = []; const appSettings = { runtimeConfigurationUrls: {}, }; const pc1 = { plugin: { api: {}, identifier: "pc1", }, configuration_json: null, }; const pc2 = { plugin: { api: {}, identifier: "pc2", }, configuration_json: { foo: "bar" }, }; const pluginConfigurations = [pc1, pc2]; const remoteConfigurations = { localizations: {} }; const App = () => ( <View> <Text>React App</Text> </View> ); const zappAppConfig = { components, cellStyles, plugins, pluginConfigurations, remoteConfigurations, styles, rivers, pipesEndpoints, appSettings, App, }; jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({ getLegacyInitialProps: jest.fn(() => ({ initialProps: {} })), })); jest.mock( "@applicaster/zapp-react-native-ui-components/Components/River", () => { const View = require("react-native").View; return { River: jest.fn(() => <View testID="mock-river" />), }; } ); describe("createZappApp", () => { it("renders the provided React App", () => { const ZappApp = createZappApp({ App }); render(<ZappApp />); expect(screen.toJSON()).toMatchSnapshot(); }); it("has a Provider component with an initialized store", () => { const ZappApp = createZappApp(zappAppConfig); const { UNSAFE_root } = render(<ZappApp />); const providerInstance = UNSAFE_root.findByType(Provider); const store = providerInstance.props.store; expect(store).toEqual( expect.objectContaining({ dispatch: expect.any(Function), subscribe: expect.any(Function), getState: expect.any(Function), replaceReducer: expect.any(Function), }) ); expect(store.getState()).toEqual( expect.objectContaining({ styles: expect.any(Object), rivers: expect.any(Object), plugins: expect.arrayContaining(plugins.map(expect.objectContaining)), components, appSettings: { runtimeConfigurationUrls: expect.any(Object), }, zappPipes: {}, }) ); }); it("has a display name", () => { const ZappApp = createZappApp(zappAppConfig); expect(ZappApp.displayName).toBe("ZappAppRoot"); }); });