UNPKG

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

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

96 lines (75 loc) 2.85 kB
import * as React from "react"; import { View } from "react-native"; import { shallow } from "enzyme"; import { shallowToJson } from "enzyme-to-json"; import { testCellStyle } from "./TestCellStyle"; import { singleView } from "./SingleView"; import { entry } from "./testEntry"; import { singleElement } from "./testElements"; jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({ useRoute: jest.fn(() => ({ screenData: { id: "test" } })), })); jest.mock("@applicaster/zapp-react-native-utils/screenState", () => ({ useScreenState: jest.fn(() => ({ get: jest.fn(), setSelectedEntry: jest.fn(), })), })); const { masterCellBuilder } = require("../index"); const mock_singleElement = singleElement; describe("masterCellBuilder", () => { describe("when using default options", () => { const MasterCell = masterCellBuilder({ cellConfiguration: testCellStyle }); it("returns a function", () => { expect(MasterCell).toMatchSnapshot(); }); it("renders correctly", () => { const wrapper = shallow( <View> <MasterCell item={entry} /> </View> ); expect(shallowToJson(wrapper)).toMatchSnapshot(); }); it("can be invoked as a React Component", () => { const wrapper = shallow(<MasterCell item={entry} state={null} />); expect(shallowToJson(wrapper)).toMatchSnapshot(); }); }); describe("when using custom containerStyle", () => { const MasterCell = masterCellBuilder({ cellConfiguration: singleView, containerStyle: { backgroundColor: "black" }, }); it("renders correctly", () => { const renderer = shallow(<MasterCell item={entry} />); expect(shallowToJson(renderer)).toMatchSnapshot(); }); }); describe("when using a custom data adapter", () => { const dataAdapter = jest.fn(() => () => mock_singleElement); const MasterCell = masterCellBuilder({ cellConfiguration: singleView, dataAdapter, }); it("renders correctly", () => { const renderer = shallow(<MasterCell item={entry} />); expect(shallowToJson(renderer)).toMatchSnapshot(); expect(dataAdapter).toHaveBeenCalledWith(singleView); }); }); describe("when using custom default components", () => { // the collapsable prop is added here to easily check from the snapshot that the mock // component is being used instead of the default one const CustomView = jest.fn((props) => <View {...props} collapsable />); const components = { View: CustomView }; const MasterCell = masterCellBuilder({ cellConfiguration: singleView, components, }); it("renders correctly", () => { const renderer = shallow(<MasterCell item={entry} />); expect(shallowToJson(renderer)).toMatchSnapshot(); }); }); });