UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

176 lines (173 loc) 10.4 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _Transition = _interopRequireWildcard(require("../Transition")); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } describe('Transition Specs', function () { // NOTE: Feature not yet implemented test.skip('should apply author classes', function () { var className = 'classA classB'; var ChildNode = function ChildNode(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, { children: "Body" })); }; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { className: className, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })); var expected = className; var actual = _react.screen.getByText('Body'); expect(actual).toHaveClass(expected); }); // NOTE: Feature not yet implemented test.skip('should apply author styles', function () { var styles = { color: '#000000', backgroundColor: '#FFFFFF' }; var ChildNode = function ChildNode(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, { children: "Body" })); }; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { style: styles, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })); var expected = styles; var actual = _react.screen.getByText('Body'); expect(actual).toHaveStyle(expected); }); test('should apply \'shown\' class when visible', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, { "data-testid": "transition" })); var expected = 'shown'; var actual = _react.screen.getByTestId('transition'); expect(actual).toHaveClass(expected); }); test('should apply \'hidden\' class when not visible', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, { "data-testid": "transition", visible: false })); var expected = 'hidden'; var actual = _react.screen.getByTestId('transition'); expect(actual).toHaveClass(expected); }); test('should apply \'shown\' class when visible with noAnimation', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, { "data-testid": "transition", noAnimation: true })); var expected = 'shown'; var actual = _react.screen.getByTestId('transition'); expect(actual).toHaveClass(expected); }); test('should apply \'hidden\' class when not visible with noAnimation', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition.TransitionBase, { "data-testid": "transition", noAnimation: true, visible: false })); var expected = 'hidden'; var actual = _react.screen.getByTestId('transition'); expect(actual).toHaveClass(expected); }); test('should fire \'onShow\' event with type when \'visible\' prop bacomes true', function () { var handleShow = jest.fn(); var ChildNode = function ChildNode(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, { children: "Body" })); }; var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { noAnimation: true, onShow: handleShow, visible: false, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })), rerender = _render.rerender; rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { noAnimation: true, onShow: handleShow, visible: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })); var expected = 1; var expectedType = { type: 'onShow' }; var actual = handleShow.mock.calls.length && handleShow.mock.calls[0][0]; expect(handleShow).toBeCalledTimes(expected); expect(actual).toMatchObject(expectedType); }); test('should fire \'onHide\' event with type when \'visible\' prop bacomes false', function () { var handleHide = jest.fn(); var ChildNode = function ChildNode(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, { children: "Body" })); }; var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { noAnimation: true, onHide: handleHide, visible: true, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })), rerender = _render2.rerender; rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], { noAnimation: true, onHide: handleHide, visible: false, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildNode, {}) })); var expected = 1; var expectedType = { type: 'onHide' }; var actual = handleHide.mock.calls.length && handleHide.mock.calls[0][0]; expect(handleHide).toBeCalledTimes(expected); expect(actual).toMatchObject(expectedType); }); // Tests for prop and className combinations var directionCombination = [['up', 'up'], ['right', 'right'], ['down', 'down'], ['left', 'left']]; var durationCombination = [['short', 'short'], ['medium', 'medium'], ['long', 'long']]; var timingFunctionCombination = [['ease', 'ease'], ['ease-in', 'ease-in'], ['ease-out', 'ease-out'], ['ease-in-out', 'ease-in-out'], ['ease-in-quart', 'ease-in-quart'], ['ease-out-quart', 'ease-out-quart'], ['linear', 'linear']]; var propStyleCombination = [['duration', durationCombination], ['direction', directionCombination], ['timingFunction', timingFunctionCombination]]; propStyleCombination.forEach(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), prop = _ref2[0], val = _ref2[1]; val.forEach(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 2), key = _ref4[0], value = _ref4[1]; test("should apply classes for ".concat(prop, "=\"").concat(value, "\""), function () { var propValue = _defineProperty({}, prop, value); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], _objectSpread(_objectSpread({}, propValue), {}, { "data-testid": "transition", visible: true, children: "Body" }))); var expected = key; var actual = _react.screen.getByTestId('transition'); expect(actual).toHaveClass(expected); }); }); }); });