import * as R from "ramda"; import React from "react"; import { renderHook } from "@testing-library/react-hooks"; import { Provider } from "react-redux"; import { createStore } from "redux"; import { useEntryScreenId } from "../"; describe("useEntryScreenId", () => { const mappedScreenId = "mapped-id"; const initialState = { contentTypes: { mappedEntry: { screen_id: mappedScreenId } }, }; const store = createStore(R.always(initialState)); const wrapper: React.FC = ({ children }) => ( {children} ); it("returns undefined when entry is not provided", () => { const { result } = renderHook(() => useEntryScreenId(), { wrapper }); expect(result.current).toBe(undefined); }); describe("For entry containing screen_type", () => { it("returns screen_type from entry", () => { const screenType = "test-id"; const entry = { id: "foo", screen_type: screenType, type: { value: "entry" }, }; const { result } = renderHook(() => useEntryScreenId(entry), { wrapper }); expect(result.current).toBe(screenType); }); }); describe("For entry type existing in the contentTypes", () => { it("returns mapped screen id from content types", () => { const entry = { id: "foo", type: { value: "mappedEntry" }, }; const { result } = renderHook(() => useEntryScreenId(entry), { wrapper }); expect(result.current).toBe(mappedScreenId); }); }); describe("For entry type existing in the contentTypes and screen_type on the entry", () => { it("prefer screen_type from the entry", () => { const screenType = "test-id"; const entry = { id: "foo", screen_type: screenType, type: { value: "mappedEntry" }, }; const { result } = renderHook(() => useEntryScreenId(entry), { wrapper }); expect(result.current).toBe(screenType); }); }); });