UNPKG

@wix/design-system

Version:

@wix/design-system

298 lines 8.87 kB
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"; import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/Breadcrumbs/test/Breadcrumbs.visual.jsx", _this = this; import _regeneratorRuntime from "@babel/runtime/regenerator"; 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; })(); } 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; } import React from 'react'; import { storiesOf } from '@storybook/react'; import Breadcrumbs from '../Breadcrumbs'; import { SIZES, SKINS } from '../constants'; import { Box } from '../..'; import { clickElement, focusElement } from '../../utils/test-utils/visual'; var sizes = Object.values(SIZES); var test = function test(it, props) { return { it: it, props: props }; }; var items = [{ id: 1, value: 'first item' }, { id: 2, value: 'second item' }, { id: 3, value: 'third item' }]; var itemsWithLinks = [{ id: 1, value: 'Wix', link: 'http://www.wix.com' }, { id: 2, value: 'Google', customElement: /*#__PURE__*/React.createElement("a", { style: { color: 'inherit', textDecoration: 'inherit' }, href: "http://www.google.com", __self: this, __source: { fileName: _jsxFileName, lineNumber: 24, columnNumber: 7 } }, "Google") }, { id: 3, value: 'Yahoo', link: 'http://www.yahoo.com' }]; var tests = [{ describe: 'Standard', its: [{ it: 'without links', props: { items: items } }, { it: 'with links', props: { items: itemsWithLinks } }] }, { describe: 'Sizes', its: sizes.map(function (size) { return test(size, { size: size }); }) }, { describe: 'Items', its: [{ it: 'single item', props: { items: [{ id: 1, value: 'first item' }] } }, { it: 'multiple items', props: { items: items } }, { it: 'customElement items', props: { items: items.map(function (item) { return _objectSpread(_objectSpread({}, item), {}, { customElement: /*#__PURE__*/React.createElement("div", { style: { backgroundColor: 'red' }, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 70, columnNumber: 15 } }, "".concat(item.value, " custom")) }); }) } }, { it: 'disabled items', props: { items: items.map(function (item) { return _objectSpread(_objectSpread({}, item), {}, { disabled: true }); }) } }, { it: 'long text items', props: { items: [{ id: 1, value: 'first item' }, { id: 2, value: 'This is a very very very very long text that will be cropped by ellipsis at some point' }] } }] }, { describe: 'skin', its: [{ it: 'overrides theme', props: { theme: SKINS.onDarkBackground, skin: SKINS.onWhiteBackground } }] }]; tests.forEach(function (_ref) { var describe = _ref.describe, its = _ref.its; its.forEach(function (_ref2) { var it = _ref2.it, props = _ref2.props; storiesOf("Breadcrumbs".concat(describe ? '/' + describe : ''), module).add(it, function () { return /*#__PURE__*/React.createElement(Breadcrumbs, _extends({ items: items }, props, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 113, columnNumber: 13 } })); }); }); }); var breadcrumbsWithBoxWrapper = [{ boxBackground: 'D10', theme: SKINS.onDarkBackground }, { boxBackground: 'D80', theme: SKINS.onWhiteBackground }, { boxBackground: 'D70', theme: SKINS.onGrayBackground }]; breadcrumbsWithBoxWrapper.forEach(function (_ref3) { var theme = _ref3.theme, boxBackground = _ref3.boxBackground; storiesOf("Breadcrumbs/Themes", module).add(theme, function () { return /*#__PURE__*/React.createElement(Box, { backgroundColor: boxBackground, width: "400px", padding: "10px", __self: _this, __source: { fileName: _jsxFileName, lineNumber: 126, columnNumber: 5 } }, /*#__PURE__*/React.createElement(Breadcrumbs, { items: items, theme: theme, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 127, columnNumber: 7 } })); }); }); var interactiveDataHook = 'interactive-breadcrumbs'; var breadcrumbsItemDataHook = 'breadcrumb-clickable-0'; var InteractiveEyeTest = /*#__PURE__*/function (_React$Component) { function InteractiveEyeTest() { var _this2; _classCallCheck(this, InteractiveEyeTest); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, InteractiveEyeTest, [].concat(args)); _this2.state = { activeId: 2 }; _this2.onClick = function (_ref4) { var id = _ref4.id; return _this2.setState({ activeId: id }); }; return _this2; } _inherits(InteractiveEyeTest, _React$Component); return _createClass(InteractiveEyeTest, [{ key: "componentDidMount", value: function () { var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: this.props.componentDidMount(); case 1: case "end": return _context.stop(); } }, _callee, this); })); function componentDidMount() { return _componentDidMount.apply(this, arguments); } return componentDidMount; }() }, { key: "render", value: function render() { var items = this.props.items; var activeId = this.state.activeId; return /*#__PURE__*/React.createElement(Breadcrumbs, { dataHook: interactiveDataHook, items: items, activeId: activeId, onClick: this.onClick, __self: this, __source: { fileName: _jsxFileName, lineNumber: 148, columnNumber: 7 } }); } }]); }(React.Component); var interactiveTests = [{ describe: 'Active item', its: [{ it: 'should be in bold once clicked upon', componentDidMount: function componentDidMount() { clickElement(breadcrumbsItemDataHook); focusElement(breadcrumbsItemDataHook); }, props: { items: items } }] }]; interactiveTests.forEach(function (_ref5) { var describe = _ref5.describe, its = _ref5.its; its.forEach(function (_ref6) { var it = _ref6.it, props = _ref6.props, componentDidMount = _ref6.componentDidMount; storiesOf("Breadcrumbs".concat(describe ? '/' + describe : ''), module).add(it, function () { return /*#__PURE__*/React.createElement(InteractiveEyeTest, _extends({}, props, { componentDidMount: componentDidMount, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 179, columnNumber: 9 } })); }); }); });