UNPKG

react-conditional-components-renderer

Version:
54 lines (53 loc) 3.45 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importDefault(require("react")); const react_2 = require("@testing-library/react"); const Choice_1 = __importDefault(require("../Choice")); const InCaseOf_1 = __importDefault(require("../InCaseOf")); const Otherwise_1 = __importDefault(require("../Otherwise")); describe("<Choice />", () => { test(`should render First choice component when first case be true`, () => { const { getByText } = (0, react_2.render)(react_1.default.createElement(Choice_1.default, null, react_1.default.createElement(InCaseOf_1.default, { test: true }, react_1.default.createElement("div", null, "Show First choice")), react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show Second choice")), react_1.default.createElement(Otherwise_1.default, null, react_1.default.createElement("div", null, "Show default choice")))); const elementText = getByText(/Show First choice/i); expect(elementText).toBeTruthy(); }); test(`should render Second choice component when second case be true`, () => { const { getByText } = (0, react_2.render)(react_1.default.createElement(Choice_1.default, null, react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show First choice")), react_1.default.createElement(InCaseOf_1.default, { test: true }, react_1.default.createElement("div", null, "Show Second choice")), react_1.default.createElement(Otherwise_1.default, null, react_1.default.createElement("div", null, "Show default choice")))); const elementText = getByText(/Show Second choice/i); expect(elementText).toBeTruthy(); }); test(`should render Default choice component when any case be true`, () => { const { getByText } = (0, react_2.render)(react_1.default.createElement(Choice_1.default, null, react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show First choice")), react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show Second choice")), react_1.default.createElement(Otherwise_1.default, null, react_1.default.createElement("div", null, "Show default choice")))); const elementText = getByText(/Show default choice/i); expect(elementText).toBeTruthy(); }); test(`shouldn't render any component when any case be true and without OtherWiseComponent`, () => { const { container } = (0, react_2.render)(react_1.default.createElement(Choice_1.default, null, react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show First choice")), react_1.default.createElement(InCaseOf_1.default, { test: false }, react_1.default.createElement("div", null, "Show Second choice")))); expect(container.firstChild).toBeNull(); }); });