diff --git a/src/customizationContext/__tests__/CustomizationContext.test.js b/src/customizationContext/__tests__/CustomizationContext.test.js new file mode 100644 index 0000000..9634afb --- /dev/null +++ b/src/customizationContext/__tests__/CustomizationContext.test.js @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * + * This is free software, licensed under the GNU General Public License v3. + * See /LICENSE for more information. + */ + +import React from "react"; + +import { render, wait } from "customTestRender"; +import mockAxios from "jest-mock-axios"; + +import { + useCustomizationContext, + CustomizationContextProvider, +} from "../CustomizationContext"; + +const CUSTOM = "Description / component for customized reForis (Shield)"; +const ORIGINAL = "Description / component for original reForis (other devices)"; + +function CustomizationTest() { + const isCustomized = useCustomizationContext(); + + return

{isCustomized ? CUSTOM : ORIGINAL}

; +} + +describe("CustomizationContext", () => { + let componentContainer; + + it("should render component without customization", async () => { + const { container, getByText } = render( + + + + ); + componentContainer = container; + + mockAxios.mockResponse({ data: {} }); + await wait(() => getByText(ORIGINAL)); + + expect(componentContainer).toMatchSnapshot(); + }); + + it("should render customized component", async () => { + const { container, getByText } = render( + + + + ); + componentContainer = container; + + mockAxios.mockResponse({ data: { customization: "shield" } }); + await wait(() => getByText(CUSTOM)); + + expect(componentContainer).toMatchSnapshot(); + }); +}); diff --git a/src/customizationContext/__tests__/__snapshots__/CustomizationContext.test.js.snap b/src/customizationContext/__tests__/__snapshots__/CustomizationContext.test.js.snap new file mode 100644 index 0000000..eb6fb1b --- /dev/null +++ b/src/customizationContext/__tests__/__snapshots__/CustomizationContext.test.js.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomizationContext should render component without customization 1`] = ` +
+

+ Description / component for original reForis (other devices) +

+
+`; + +exports[`CustomizationContext should render customized component 1`] = ` +
+

+ Description / component for customized reForis (Shield) +

+
+`; diff --git a/src/testUtils/customTestRender.js b/src/testUtils/customTestRender.js index 8d41a60..c256358 100644 --- a/src/testUtils/customTestRender.js +++ b/src/testUtils/customTestRender.js @@ -14,6 +14,7 @@ import { render } from "@testing-library/react"; import PropTypes from "prop-types"; import { AlertContextMock } from "./alertContextMock"; +import { CustomizationContextMock } from "./cutomizationContextMock"; Wrapper.propTypes = { children: PropTypes.oneOfType([ @@ -25,9 +26,11 @@ Wrapper.propTypes = { function Wrapper({ children }) { return ( - - {children} - + + + {children} + + ); } diff --git a/src/testUtils/cutomizationContextMock.js b/src/testUtils/cutomizationContextMock.js new file mode 100644 index 0000000..3b07a29 --- /dev/null +++ b/src/testUtils/cutomizationContextMock.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * + * This is free software, licensed under the GNU General Public License v3. + * See /LICENSE for more information. + */ + +import React from "react"; + +window.CustomizationContext = React.createContext(); + +const isCustomized = jest.fn(); + +function CustomizationContextMock({ children }) { + return ( + + {children} + + ); +} + +export { CustomizationContextMock };