UNPKG

@applicaster/quick-brick-core

Version:

Core package for Applicaster's Quick Brick App

132 lines (108 loc) 2.97 kB
import * as React from "react"; import { View, Text } from "react-native"; import { shallow } from "enzyme"; import { shallowToJson } from "enzyme-to-json"; 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: {} })), })); describe("createZappApp", () => { it("returns a react component", () => { const ZappApp = createZappApp({}); const wrapper = shallow(<ZappApp />); expect(shallowToJson(wrapper)).toMatchSnapshot(); }); it("renders the provided React App", () => { const ZappApp = createZappApp({ App }); const wrapper = shallow(<ZappApp />); expect(shallowToJson(wrapper)).toMatchSnapshot(); }); it("has a <Provider /> component with an initialized store", () => { const ZappApp = createZappApp(zappAppConfig); const wrapper = shallow(<ZappApp />); const providerNode = wrapper.find(Provider); const store = providerNode.prop("store"); expect(providerNode.length).toBe(1); expect(store).toEqual( expect.objectContaining({ dispatch: expect.any(Function), subscribe: expect.any(Function), getState: expect.any(Function), replaceReducer: expect.any(Function), }) ); expect(store.getState()).toMatchSnapshot(); 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"); }); });