@wix/design-system
Version:
@wix/design-system
474 lines • 14.3 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _extends from "@babel/runtime/helpers/extends";
var _excluded = ["componentDidMount", "rtl"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/MultiSelect/test/MultiSelect.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); }
import React, { useEffect } from 'react';
import { storiesOf } from '@wix/wix-storybook-utils/dynamic-stories';
import MultiSelect from '../MultiSelect';
import FormField from '../../FormField';
import { RTLWrapper } from '../../../stories/utils/RTLWrapper';
import { focusElement, clickElement } from '../../utils/test-utils/visual';
var interactiveDataHook = 'interactive-multiselect';
var inputDataHook = 'wsr-custom-input';
var options = [{
value: 'Alabama',
id: 'AL'
}, {
value: 'Alaska',
id: 'AK'
}, {
value: 'Arizona',
id: 'AZ'
}, {
value: 'Arkansas',
id: 'AR'
}, {
value: 'California',
id: 'CA'
}, {
value: 'North Carolina',
id: 'NC'
}, {
value: 'Colorado',
id: 'CO'
}, {
value: 'Connecticut',
id: 'CT'
}, {
value: 'Delaware',
id: 'DL'
}, {
value: 'Florida',
id: 'FL'
}, {
value: 'Georgia',
id: 'GA'
}, {
value: 'Hawaii',
id: 'HI'
}, {
value: 'Idaho',
id: 'IL'
}, {
value: 'Illinois',
id: 'IN'
}, {
value: 'Indiana',
id: 'IA'
}];
var tests = [{
describe: 'Basic',
its: [{
it: 'should render MultiSelect with customSuffix over 400px width',
props: {
customSuffix: /*#__PURE__*/React.createElement("div", {
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 38,
columnNumber: 25
}
}, "some button"),
tags: [{
id: '1',
label: 'aaaaaaaaaaaa'
}, {
id: '2',
label: 'aaaaaaaaaaaa'
}, {
id: '3',
label: 'aaaaaaaaaaaa'
}]
},
width: '400px'
}, {
it: 'should render MultiSelect with customPrefix over 400px width',
props: {
customPrefix: /*#__PURE__*/React.createElement("div", {
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 50,
columnNumber: 25
}
}, "some button"),
tags: [{
id: '1',
label: 'aaaaaaaaaaaa'
}, {
id: '2',
label: 'aaaaaaaaaaaa'
}, {
id: '3',
label: 'aaaaaaaaaaaa'
}]
},
width: '400px'
}, {
it: 'should render MultiSelect with customSuffix',
props: {
customSuffix: /*#__PURE__*/React.createElement("div", {
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 62,
columnNumber: 25
}
}, "some button"),
tags: [{
id: '1',
label: 'aaaaaaaaaaaa'
}, {
id: '2',
label: 'aaaaaaaaaaaa'
}, {
id: '3',
label: 'aaaaaaaaaaaa'
}]
}
}, {
it: 'should render MultiSelect with customPrefix',
props: {
customPrefix: /*#__PURE__*/React.createElement("div", {
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 73,
columnNumber: 25
}
}, "some button"),
tags: [{
id: '1',
label: 'aaaaaaaaaaaa'
}, {
id: '2',
label: 'aaaaaaaaaaaa'
}, {
id: '3',
label: 'aaaaaaaaaaaa'
}]
}
}, {
it: 'should render MultiSelect with "select" mode',
props: {
tags: [{
id: '1',
label: 'aaaaaaaaaaaa'
}, {
id: '2',
label: 'aaaaaaaaaaaa'
}, {
id: '3',
label: 'aaaaaaaaaaaa'
}, {
id: '4',
label: 'aaaaaaaaaaaa'
}, {
id: '5',
label: 'aaaaaaaaaaaa'
}, {
id: '6',
label: 'aaaaaaaaaaaa'
}],
mode: 'select'
},
width: '400px'
}, {
it: 'should fill input with tags without breaking a line',
props: {
tags: [{
id: '1',
label: 'a'
}, {
id: '2',
label: 'b'
}, {
id: '3',
label: 'c'
}, {
id: '4',
label: 'd'
}, {
id: '5',
label: 'e'
}, {
id: '6',
label: 'f'
}, {
id: '7',
label: 'f'
}]
},
width: '400px'
}, {
it: 'should render tags without remove button when readOnly mode is ON',
props: {
readOnly: true,
tags: [{
id: '1',
label: 'a'
}, {
id: '2',
label: 'b'
}]
}
}, {
it: 'should render tags without remove button when readOnly mode is ON as onReorder function is passed',
props: {
readOnly: true,
onReorder: function onReorder() {
return null;
},
tags: [{
id: '1',
label: 'a'
}, {
id: '2',
label: 'b'
}]
}
}, {
it: 'should render disabled MultiSelect',
props: {
disabled: true,
tags: [{
id: '1',
label: 'Alabama'
}, {
id: '2',
label: 'Alaska'
}, {
id: '3',
label: 'Arizona'
}, {
id: '4',
label: 'Arkansas'
}]
},
width: '500px'
}, {
it: 'should render disabled MultiSelect with a placeholder',
props: {
disabled: true,
placeholder: 'This is a MultiSelect placeholder'
},
width: '500px'
}, {
it: 'should render readOnly MultiSelect',
props: {
readOnly: true
},
width: '500px'
}]
}, {
describe: 'With Status',
its: [{
it: 'error',
props: {
mode: 'select',
status: 'error'
}
}, {
it: 'warning',
props: {
mode: 'select',
status: 'warning'
}
}, {
it: 'loading',
props: {
mode: 'select',
status: 'loading'
}
}]
}];
tests.forEach(function (_ref) {
var describe = _ref.describe,
its = _ref.its;
its.forEach(function (_ref2) {
var it = _ref2.it,
props = _ref2.props,
width = _ref2.width;
storiesOf("MultiSelect".concat(describe ? '/' + describe : ''), module).add(it, function () {
return /*#__PURE__*/React.createElement("div", {
style: {
width: width
},
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 195,
columnNumber: 9
}
}, /*#__PURE__*/React.createElement(MultiSelect, _extends({}, props, {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 196,
columnNumber: 11
}
})));
});
});
});
var interactiveTests = [{
describe: 'Directional tests',
its: [{
it: 'LTR should show 2 tags',
componentDidMount: function componentDidMount() {
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
return _regenerator().w(function (_context) {
while (1) switch (_context.n) {
case 0:
clickElement(inputDataHook);
focusElement(inputDataHook);
case 1:
return _context.a(2);
}
}, _callee);
}))();
},
props: {
tags: [{
id: 'AL',
label: 'Alabama (AL)'
}, {
id: 'AZ',
label: 'Arizona (AZ)'
}],
options: options
}
}, {
it: 'RTL should show 2 tags',
componentDidMount: function componentDidMount() {
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
return _regenerator().w(function (_context2) {
while (1) switch (_context2.n) {
case 0:
clickElement(inputDataHook);
focusElement(inputDataHook);
case 1:
return _context2.a(2);
}
}, _callee2);
}))();
},
props: {
tags: [{
id: 'AL',
label: 'Alabama (AL)'
}, {
id: 'AZ',
label: 'Arizona (AZ)'
}],
options: options
},
rtl: true
}]
}];
var InteractiveEyeTest = function InteractiveEyeTest(_ref3) {
var componentDidMount = _ref3.componentDidMount,
rtl = _ref3.rtl,
props = _objectWithoutProperties(_ref3, _excluded);
useEffect(function () {
componentDidMount();
}, [componentDidMount]);
return /*#__PURE__*/React.createElement(RTLWrapper, {
rtl: rtl,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 245,
columnNumber: 5
}
}, /*#__PURE__*/React.createElement(MultiSelect, _extends({
dataHook: interactiveDataHook
}, props, {
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 246,
columnNumber: 7
}
})));
};
interactiveTests.forEach(function (_ref4) {
var describe = _ref4.describe,
its = _ref4.its;
its.forEach(function (_ref5) {
var it = _ref5.it,
props = _ref5.props,
rtl = _ref5.rtl,
componentDidMount = _ref5.componentDidMount;
storiesOf("MultiSelect".concat(describe ? '/' + describe : ''), module).add(it, function () {
return /*#__PURE__*/React.createElement(InteractiveEyeTest, _extends({}, props, {
componentDidMount: componentDidMount,
rtl: rtl,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 256,
columnNumber: 9
}
}));
});
});
});
var multiselectWithFormFieldStatus = [{
describe: 'Form field status',
its: [{
it: 'Error',
props: {
status: 'error',
statusMessage: 'This is error message',
options: options
}
}, {
it: 'Warning',
props: {
status: 'warning',
statusMessage: 'This is warning message',
options: options
}
}, {
it: 'Loading',
props: {
status: 'loading',
statusMessage: 'This is loading message',
options: options
}
}]
}];
multiselectWithFormFieldStatus.forEach(function (_ref6) {
var describe = _ref6.describe,
its = _ref6.its;
its.forEach(function (_ref7) {
var it = _ref7.it,
props = _ref7.props;
storiesOf("MultiSelect".concat(describe ? '/' + describe : ''), module).add(it, function () {
return /*#__PURE__*/React.createElement(FormField, {
status: props.status,
statusMessage: props.statusMessage,
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 303,
columnNumber: 9
}
}, /*#__PURE__*/React.createElement(MultiSelect, {
options: props.options,
mode: "select",
__self: _this,
__source: {
fileName: _jsxFileName,
lineNumber: 304,
columnNumber: 11
}
}));
});
});
});