1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-10-04 12:14:19 +02:00
foris-js/src/utils/__tests__/conditionalHOCs.test.js

111 lines
4.4 KiB
JavaScript
Raw Normal View History

2019-11-07 18:21:14 +01:00
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://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 } from "customTestRender";
import {
withEither, withSpinner, withSending, withSpinnerOnSending, withError, withErrorMessage,
} from "../conditionalHOCs";
import { API_STATE } from "api/utils";
describe("conditional HOCs", () => {
const First = () => <p>First</p>;
const Alternative = () => <p>Alternative</p>;
describe("withEither", () => {
it("should render First component", () => {
const withAlternative = withEither(() => false, Alternative);
const FirstWithConditional = withAlternative(First);
const { getByText } = render(<FirstWithConditional />);
expect(getByText("First")).toBeDefined();
});
it("should render Alternative component", () => {
const withAlternative = withEither(() => true, Alternative);
const FirstWithConditional = withAlternative(First);
const { getByText } = render(<FirstWithConditional />);
expect(getByText("Alternative")).toBeDefined();
});
});
describe("withSpinner", () => {
it("should render First component", () => {
const withSpinnerHidden = withSpinner(() => false);
const FirstWithConditional = withSpinnerHidden(First);
const { getByText } = render(<FirstWithConditional />);
expect(getByText("First")).toBeDefined();
});
it("should render spinner", () => {
const withSpinnerVisible = withSpinner(() => true);
const FirstWithConditional = withSpinnerVisible(First);
const { container } = render(<FirstWithConditional />);
expect(container).toMatchSnapshot();
});
});
describe("withSending", () => {
it("should render First component", () => {
const withAlternative = withSending(Alternative);
const FirstWithConditional = withAlternative(First);
const { getByText } = render(<FirstWithConditional apiState={API_STATE.SUCCESS} />);
expect(getByText("First")).toBeDefined();
});
it("should render Alternative component", () => {
const withAlternative = withSending(Alternative);
const FirstWithConditional = withAlternative(First);
const { getByText } = render(<FirstWithConditional apiState={API_STATE.SENDING} />);
expect(getByText("Alternative")).toBeDefined();
});
});
describe("withSpinnerOnSending", () => {
it("should render First component", () => {
const FirstWithConditional = withSpinnerOnSending(First);
const { getByText } = render(<FirstWithConditional apiState={API_STATE.SUCCESS} />);
expect(getByText("First")).toBeDefined();
});
it("should render spinner", () => {
const FirstWithConditional = withSpinnerOnSending(First);
const { container } = render(<FirstWithConditional apiState={API_STATE.SENDING} />);
expect(container).toMatchSnapshot();
});
});
describe("withError", () => {
it("should render First component", () => {
const withErrorHidden = withError(() => false);
const FirstWithConditional = withErrorHidden(First);
const { getByText } = render(<FirstWithConditional />);
expect(getByText("First")).toBeDefined();
});
it("should render error message", () => {
const withErrorVisible = withError(() => true);
const FirstWithConditional = withErrorVisible(First);
const { container } = render(<FirstWithConditional />);
expect(container).toMatchSnapshot();
});
});
describe("withErrorMessage", () => {
it("should render First component", () => {
const FirstWithConditional = withErrorMessage(First);
const { getByText } = render(<FirstWithConditional apiState={API_STATE.SUCCESS} />);
expect(getByText("First")).toBeDefined();
});
it("should render error message", () => {
const FirstWithConditional = withErrorMessage(First);
const { container } = render(<FirstWithConditional apiState={API_STATE.ERROR} />);
expect(container).toMatchSnapshot();
});
});
});