@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
163 lines (160 loc) • 9.1 kB
JavaScript
;
require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _Layout = _interopRequireWildcard(require("../Layout"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : 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); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
describe('Layout Specs', function () {
var layoutPropAlign = [['baseline', 'baseline'], ['center', 'center'], ['end', 'flex-end'], ['start', 'flex-start']];
layoutPropAlign.forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
value = _ref2[0],
resolved = _ref2[1];
test("should apply '".concat(resolved, "' style value given an align prop value of \"").concat(value, "\""), function () {
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], {
align: value,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
children: "Body"
})
}));
var layout = _react.screen.getByText('Body').parentElement;
var expected = resolved;
expect(layout).toHaveStyle({
'align-items': expected
});
});
});
test('should apply a class for inline', function () {
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], {
inline: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
children: "Body"
})
}));
var layout = _react.screen.getByText('Body').parentElement;
var expected = 'inline';
expect(layout).toHaveClass(expected);
});
// Tests for prop and className combinations
var propStyleCombination = [['orientation', ['horizontal', 'vertical']]];
propStyleCombination.forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
prop = _ref4[0],
vals = _ref4[1];
vals.forEach(function (value) {
test("should apply classes for ".concat(prop), function () {
var propValue = _defineProperty({}, prop, value);
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], _objectSpread(_objectSpread({}, propValue), {}, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
children: "Body"
})
})));
var layout = _react.screen.getByText('Body').parentElement;
var expected = value;
expect(layout).toHaveClass(expected);
});
});
});
// Test for boolean classes
var cellBooleanPropClasses = ['shrink'];
cellBooleanPropClasses.forEach(function (prop) {
test("should apply a class for ".concat(prop), function () {
var props = _defineProperty({}, prop, true);
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, _objectSpread(_objectSpread({}, props), {}, {
children: "Body"
})));
var layout = _react.screen.getByText('Body');
var expected = prop;
expect(layout).toHaveClass(expected);
});
});
var cellPropSize = [['size', ['100px', '50%', '5em']]];
cellPropSize.forEach(function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
prop = _ref6[0],
vals = _ref6[1];
vals.forEach(function (value) {
test("should apply flexBasis styles the size prop value ".concat(value), function () {
var propValue = _defineProperty({}, prop, value);
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, _objectSpread(_objectSpread({}, propValue), {}, {
children: "Body"
}))
}));
var layoutCell = _react.screen.getByText('Body');
var expected = value;
expect(layoutCell).toHaveStyle({
'flex-basis': expected
});
});
});
});
test('should apply a class for grow', function () {
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
children: "Body"
}));
var cell = _react.screen.getByText('Body');
var expected = 'grow';
expect(cell).toHaveClass(expected);
});
test('should apply classes for grow and size and flexBasis styles the size prop value 100px', function () {
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], {
style: {
width: "300px"
},
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
grow: true,
size: "100px",
children: "Body"
})
}));
var cell = _react.screen.getByText('Body');
var expectedGrowClass = 'grow';
var expectedSizeClass = 'size';
var expectedFlexBasis = '100px';
expect(cell).toHaveClass(expectedGrowClass);
expect(cell).toHaveClass(expectedSizeClass);
expect(cell).toHaveStyle({
'flex-basis': expectedFlexBasis
});
});
test('should not be apply a class for grow when using shrink', function () {
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
grow: true,
shrink: true,
children: "Body"
}));
var cell = _react.screen.getByText('Body');
var notExpected = 'grow';
expect(cell).not.toHaveClass(notExpected);
});
test('should return a DOM node reference for `componentRef` on `Layout`', function () {
var ref = jest.fn();
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout["default"], {
ref: ref
}));
var expected = 'DIV';
var actual = ref.mock.calls[0][0].nodeName;
expect(actual).toBe(expected);
});
test('should return a DOM node reference for `componentRef` on `Cell`', function () {
var ref = jest.fn();
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
ref: ref
}));
var expected = 'DIV';
var actual = ref.mock.calls[0][0].nodeName;
expect(actual).toBe(expected);
});
});