UNPKG

optimizely-oui

Version:

Optimizely's Component Library.

75 lines (70 loc) 3.15 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _index = _interopRequireDefault(require("../index")); var _enzyme = require("enzyme"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } describe("components/Table/TR", function () { it("should render as a `tr`", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], null)); expect(component.type()).toBe("tr"); }); it("should render children", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], null, _react["default"].createElement("td", null))); expect(component.containsMatchingElement(_react["default"].createElement("td", null))).toBe(true); }); it("should render with test section", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { testSection: "goose" })); expect(component.is('[data-test-section="goose"]')).toBe(true); }); it("should render without a border if noBorder is passed", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { noBorder: true, testSection: "goose" })); expect(component.hasClass("no-border")).toBe(true); }); it("should render with a highlight if isHighlighted is passed", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { isHighlighted: true, testSection: "goose" })); expect(component.hasClass("oui-table-row--highlighted")).toBe(true); }); it("should render with link styles if isLink prop is passed", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { isLink: true, testSection: "goose" })); expect(component.hasClass("oui-table-row--link")).toBeTruthy(); }); it("should trigger function when row is clicked", function () { var mockFunction = jest.fn(); var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { onRowClick: mockFunction, testSection: "goose" })); component.find('[data-test-section="goose"]').simulate("click"); expect(mockFunction).toHaveBeenCalled(); }); describe("when given a className", function () { it("appends it to the root element", function () { var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { className: "extra-class" }, "Text")); expect(component.prop("className").includes("extra-class")).toBe(true); }); }); describe("when given an unknown prop", function () { it("passes it to the root element", function () { // @ts-ignore: `unknownProps` is not part of any typed interface and therefore a good test value. var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], { unknownProp: "some value" }, "Text")); expect(component).toHaveProp({ unknownProp: "some value" }); }); }); });