@wix/design-system
Version:
@wix/design-system
475 lines • 11.1 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;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React, { useEffect } from 'react';
import { storiesOf } from '@storybook/react';
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__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
clickElement(inputDataHook);
focusElement(inputDataHook);
case 2:
case "end":
return _context.stop();
}
}, _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__*/_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
clickElement(inputDataHook);
focusElement(inputDataHook);
case 2:
case "end":
return _context2.stop();
}
}, _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
}
}));
});
});
});