UNPKG

@wix/design-system

Version:

@wix/design-system

769 lines 25 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; var _excluded = ["componentDidMount"]; var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/TableActionCell/test/TableActionCell.visual.jsx", _this = this; function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); } function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import { storiesOf } from '@wix/wix-storybook-utils/dynamic-stories'; import React from 'react'; import { Download, Star, Add, ChevronDownSmall, Duplicate, Print, Delete } from '@wix/wix-ui-icons-common'; import Box from '../../Box'; import TableActionCell from '../TableActionCell'; import { clickElement } from '../../utils/test-utils/visual'; var interactiveDataHook = 'interactive-tableactioncell'; var clickSecondaryActions = function clickSecondaryActions() { return clickElement('table-action-cell-trigger-element'); }; var InteractiveEyeTest = /*#__PURE__*/function (_React$Component) { function InteractiveEyeTest() { _classCallCheck(this, InteractiveEyeTest); return _callSuper(this, InteractiveEyeTest, arguments); } _inherits(InteractiveEyeTest, _React$Component); return _createClass(InteractiveEyeTest, [{ key: "componentDidMount", value: function () { var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() { return _regenerator().w(function (_context) { while (1) switch (_context.n) { case 0: this.props.componentDidMount(); case 1: return _context.a(2); } }, _callee, this); })); function componentDidMount() { return _componentDidMount.apply(this, arguments); } return componentDidMount; }() }, { key: "render", value: function render() { var _this$props = this.props, componentDidMount = _this$props.componentDidMount, restProps = _objectWithoutProperties(_this$props, _excluded); return /*#__PURE__*/React.createElement(Box, { padding: 20, __self: this, __source: { fileName: _jsxFileName, lineNumber: 31, columnNumber: 7 } }, /*#__PURE__*/React.createElement(TableActionCell, _extends({ dataHook: interactiveDataHook }, restProps, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 32, columnNumber: 9 } }))); } }]); }(React.Component); var interactiveTests = [{ describe: 'Primary action', its: [{ it: 'Should allow making it always visible', props: { primaryAction: { onClick: function onClick() {}, visibility: 'always', text: 'text' } } }, { it: 'Should display a premium item skin with visibility always', props: { primaryAction: { onClick: function onClick() {}, visibility: 'always', text: 'Premium', skin: 'premium' } } }] }, { describe: 'Primary action array format', its: [{ it: 'Should display multiple primary actions with always show', props: { primaryAction: [{ text: 'Edit', onClick: function onClick() {}, priority: 'primary' }, { text: 'Delete', onClick: function onClick() {}, priority: 'secondary' }], alwaysShowPrimaryActions: true } }, { it: 'Should display multiple primary actions on hover only', props: { primaryAction: [{ text: 'Edit', onClick: function onClick() {}, priority: 'primary' }, { text: 'Delete', onClick: function onClick() {}, priority: 'secondary' }], alwaysShowPrimaryActions: false } }, { it: 'Should display multiple primary actions with primary priority', props: { primaryAction: [{ text: 'Save', onClick: function onClick() {}, priority: 'primary' }, { text: 'Cancel', onClick: function onClick() {}, priority: 'primary' }], alwaysShowPrimaryActions: true } }, { it: 'Should display multiple primary actions with secondary priority', props: { primaryAction: [{ text: 'View', onClick: function onClick() {}, priority: 'secondary' }, { text: 'Share', onClick: function onClick() {}, priority: 'secondary' }], alwaysShowPrimaryActions: true } }] }, { describe: 'Secondary Actions', its: [{ it: 'Should display a divider', props: { secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 151, columnNumber: 21 } }) }, { divider: true }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 156, columnNumber: 21 } }) }], numOfVisibleSecondaryActions: 0 }, componentDidMount: clickSecondaryActions }, { it: 'Should display a destructive item skin', props: { secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 169, columnNumber: 21 } }) }, { divider: true }, { text: 'Delete', icon: /*#__PURE__*/React.createElement(Delete, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 174, columnNumber: 21 } }), skin: 'destructive' }], numOfVisibleSecondaryActions: 0 }, componentDidMount: clickSecondaryActions }, { it: 'Should display a subtitle', props: { secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 188, columnNumber: 21 } }), subtitle: 'And sky' }], numOfVisibleSecondaryActions: 0 }, componentDidMount: clickSecondaryActions }, { it: 'Should display a premium item skin', props: { numOfVisibleSecondaryActions: 1, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 203, columnNumber: 21 } }), skin: 'premium' }] } }] }, { describe: 'Placeholder icons', its: [{ it: 'Should display normal placeholder icon', props: { primaryAction: { onClick: function onClick() {}, text: 'text' } } }, { it: 'Should display small placeholder icon', props: { size: 'small', primaryAction: { onClick: function onClick() {}, text: 'text' } } }] }, { describe: 'Small actions', its: [{ it: 'Should display small actions', props: { alwaysShowSecondaryActions: true, size: 'small', primaryAction: { onClick: function onClick() {}, text: 'text', skin: 'standard', prefixIcon: /*#__PURE__*/React.createElement(Add, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 247, columnNumber: 25 } }), suffixIcon: /*#__PURE__*/React.createElement(ChevronDownSmall, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 248, columnNumber: 25 } }) }, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 253, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Star action was triggered.'); } }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 258, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Download action was triggered.'); } }, { text: 'Duplicate', icon: /*#__PURE__*/React.createElement(Duplicate, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 263, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Duplicate action was triggered.'); } }, { text: 'Print', icon: /*#__PURE__*/React.createElement(Print, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 268, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Print action was triggered.'); } }] } }, { it: 'Should display small actions', props: { alwaysShowSecondaryActions: true, size: 'small', primaryAction: { onClick: function onClick() {}, text: 'text', skin: 'standard' }, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 287, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Star action was triggered.'); } }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 292, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Download action was triggered.'); } }, { text: 'Duplicate', icon: /*#__PURE__*/React.createElement(Duplicate, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 297, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Duplicate action was triggered.'); } }, { text: 'Print', icon: /*#__PURE__*/React.createElement(Print, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 302, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Print action was triggered.'); } }] } }, { it: 'Should display icon prefix in small actions', props: { alwaysShowSecondaryActions: true, size: 'small', primaryAction: { onClick: function onClick() {}, text: 'text', skin: 'standard', prefixIcon: /*#__PURE__*/React.createElement(Add, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 317, columnNumber: 25 } }) }, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 322, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Star action was triggered.'); } }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 327, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Download action was triggered.'); } }, { text: 'Duplicate', icon: /*#__PURE__*/React.createElement(Duplicate, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 332, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Duplicate action was triggered.'); } }, { text: 'Print', icon: /*#__PURE__*/React.createElement(Print, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 337, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Print action was triggered.'); } }] } }, { it: 'Should display icon suffix in small actions', props: { alwaysShowSecondaryActions: true, size: 'small', primaryAction: { onClick: function onClick() {}, text: 'text', skin: 'standard', suffixIcon: /*#__PURE__*/React.createElement(ChevronDownSmall, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 352, columnNumber: 25 } }) }, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 357, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Star action was triggered.'); } }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 362, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Download action was triggered.'); } }, { text: 'Duplicate', icon: /*#__PURE__*/React.createElement(Duplicate, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 367, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Duplicate action was triggered.'); } }, { text: 'Print', icon: /*#__PURE__*/React.createElement(Print, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 372, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Print action was triggered.'); } }] } }] }, { describe: 'Tiny actions', its: [{ it: 'Should display tiny actions', props: { alwaysShowSecondaryActions: true, size: 'tiny', primaryAction: { onClick: function onClick() {}, text: 'text', skin: 'standard', prefixIcon: /*#__PURE__*/React.createElement(Add, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 392, columnNumber: 25 } }), suffixIcon: /*#__PURE__*/React.createElement(ChevronDownSmall, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 393, columnNumber: 25 } }) }, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 398, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Star action was triggered.'); } }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 403, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Download action was triggered.'); } }, { text: 'Duplicate', icon: /*#__PURE__*/React.createElement(Duplicate, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 408, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Duplicate action was triggered.'); } }, { text: 'Print', icon: /*#__PURE__*/React.createElement(Print, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 413, columnNumber: 21 } }), onClick: function onClick() { return window.alert('Print action was triggered.'); } }] } }] }, { describe: 'More actions props', its: [{ it: 'Should display more actions button with tertiary priority', props: { secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 430, columnNumber: 21 } }), onClick: function onClick() {} }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 435, columnNumber: 21 } }), onClick: function onClick() {} }], numOfVisibleSecondaryActions: 0, moreActionsProps: { priority: 'tertiary' } } }, { it: 'Should display more actions button with dark skin', props: { secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 451, columnNumber: 21 } }), onClick: function onClick() {} }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 456, columnNumber: 21 } }), onClick: function onClick() {} }], numOfVisibleSecondaryActions: 0, moreActionsProps: { skin: 'dark' } } }] }, { describe: 'Secondary actions props', its: [{ it: 'Should display visible secondary actions with tertiary priority', props: { alwaysShowSecondaryActions: true, secondaryActions: [{ text: 'Star', icon: /*#__PURE__*/React.createElement(Star, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 478, columnNumber: 21 } }), onClick: function onClick() {} }, { text: 'Download', icon: /*#__PURE__*/React.createElement(Download, { __self: this, __source: { fileName: _jsxFileName, lineNumber: 483, columnNumber: 21 } }), onClick: function onClick() {} }], numOfVisibleSecondaryActions: 2, secondaryActionsProps: { priority: 'tertiary' } } }] }]; interactiveTests.forEach(function (_ref) { var describe = _ref.describe, its = _ref.its; its.forEach(function (_ref2) { var it = _ref2.it, props = _ref2.props, componentDidMount = _ref2.componentDidMount; storiesOf("TableActionCell".concat(describe ? '/' + describe : ''), module).add(it, function () { return /*#__PURE__*/React.createElement(InteractiveEyeTest, _extends({}, props, { componentDidMount: componentDidMount, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 502, columnNumber: 9 } })); }); }); });