@applicaster/zapp-react-native-ui-components
Version:
Applicaster Zapp React Native ui components for the Quick Brick App
119 lines (97 loc) • 2.82 kB
JavaScript
import React from "react";
import { shallow } from "enzyme";
import { shallowToJson } from "enzyme-to-json";
import configureStore from "redux-mock-store";
import { GeneralContentScreen } from "../../GeneralContentScreen";
import { FeedLoader } from "../../FeedLoader";
import { River } from "../index";
import { RiverComponent } from "../River";
import { ScreenResolver } from "../../ScreenResolver";
const river = {
home: true,
id: "A1234",
name: "foo",
type: "general_content",
ui_components: [
{
component_type: "hero",
},
{
component_type: "grid",
},
],
};
const riverWithScreenPlugin = {
home: false,
id: "C0987",
name: "Some-Screen-Plugin",
type: "some-screen-plugin",
ui_components: [],
};
const rivers = {
A1234: river,
B4567: { id: "B4567" },
C0987: riverWithScreenPlugin,
};
const contexts = {
setScreenTitle: () => {},
setScreenSummary: () => {},
setIsScreenWrappedInContainer: () => {},
};
const riverProps = {
river,
...contexts,
groupId: "ZF-C4",
};
const appData = { layoutVersion: "v1" };
const store = configureStore()({ rivers, appData });
describe("When River has a general_content type", () => {
const wrapper = shallow(<RiverComponent {...riverProps} />);
describe("<RiverComponent />", () => {
it("renders correctly", () => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it("it returns a GeneralContentScreen", () => {
expect(wrapper.find(GeneralContentScreen).length).toBe(1);
});
});
describe("<River />", () => {
const wrapper = shallow(<River screenId="A1234" store={store} />);
it("renders correctly", () => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
});
});
describe("When River has any other type other than general_content", () => {
const riverPropsWithScreenPlugin = {
river: riverWithScreenPlugin,
...contexts,
appData,
};
const wrapper = shallow(<RiverComponent {...riverPropsWithScreenPlugin} />);
describe("<RiverComponent />", () => {
it("renders correctly", () => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it("it returns a ScreenResolver", () => {
expect(wrapper.find(ScreenResolver).length).toBe(1);
});
});
});
describe("When River has feed url", () => {
const riverPropsWithFeedUrl = {
river,
...contexts,
feedUrl: "https://some-feed-url.net",
appData: { layoutVersion: "v1" },
};
const wrapper = shallow(<RiverComponent {...riverPropsWithFeedUrl} />);
describe("<RiverComponent />", () => {
it("renders correctly", () => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
it("it returns a FeedLoader if it's a v1 layout", () => {
expect(wrapper.find(FeedLoader).length).toBe(1);
});
});
});