iguazio.dashboard-react-controls 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ @import '../../scss/mixins';
2
+ @import '../../scss/colors';
3
+ @import '../../scss/borders';
4
+ @import '../../scss/shadows';
5
+
6
+ .form-field {
7
+ position: relative;
8
+ display: block;
9
+ width: 100%;
10
+
11
+ &__label {
12
+ margin-bottom: 5px;
13
+ color: $topaz;
14
+ font-size: 12px;
15
+ text-transform: capitalize;
16
+ background-color: transparent;
17
+
18
+ &-disabled {
19
+ color: $spunPearl;
20
+ }
21
+ }
22
+
23
+ &__select {
24
+ padding-left: 16px;
25
+ padding-right: 30px;
26
+ cursor: pointer;
27
+
28
+ @include fieldWrapper;
29
+
30
+ &-active:not(.without-border) {
31
+ background: $alabaster;
32
+ }
33
+
34
+ &-disabled {
35
+ color: $spunPearl;
36
+ cursor: not-allowed;
37
+ }
38
+
39
+ &.without {
40
+ &-border {
41
+ border-color: transparent;
42
+
43
+ .form-field__caret {
44
+ display: none;
45
+ }
46
+
47
+ &:hover {
48
+ .form-field__caret {
49
+ display: block;
50
+ }
51
+ }
52
+ }
53
+
54
+ &-label {
55
+ padding-left: 16px;
56
+ }
57
+ }
58
+
59
+ &-dense {
60
+ padding-top: 12px;
61
+ padding-bottom: 12px;
62
+ }
63
+
64
+ &-normal {
65
+ padding-top: 14px;
66
+ padding-bottom: 14px;
67
+ }
68
+
69
+ &-medium {
70
+ padding-top: 16px;
71
+ padding-bottom: 16px;
72
+ }
73
+
74
+ &-chunky {
75
+ padding-top: 18px;
76
+ padding-bottom: 18px;
77
+ }
78
+
79
+ &-value {
80
+ display: block;
81
+ min-height: 18px;
82
+ }
83
+ }
84
+ }
85
+
86
+ // .select {
87
+ // position: relative;
88
+ // display: flex;
89
+ // flex-flow: column;
90
+ // flex: 1 0;
91
+ // cursor: pointer;
92
+
93
+ // @include fieldWrapper;
94
+
95
+ // &__label {
96
+ // margin-bottom: 5px;
97
+ // color: $topaz;
98
+ // font-size: 12px;
99
+ // text-transform: capitalize;
100
+ // background-color: transparent;
101
+
102
+ // &-mandatory {
103
+ // color: $amaranth;
104
+ // }
105
+
106
+ // &-disabled {
107
+ // color: $spunPearl;
108
+
109
+ // .form-field__label-mandatory {
110
+ // color: $spunPearl;
111
+ // }
112
+ // }
113
+ // }
114
+
115
+ // &_active:not(.without-border) {
116
+ // background: $alabaster;
117
+ // }
118
+
119
+ // &__caret {
120
+ // position: absolute;
121
+ // top: 50%;
122
+ // right: 10px;
123
+ // transform: translate(0%, -50%);
124
+ // }
125
+
126
+ // &.without {
127
+ // &-border {
128
+ // border: none;
129
+
130
+ // .select__caret {
131
+ // display: none;
132
+ // }
133
+
134
+ // &:hover {
135
+ // .select__caret {
136
+ // display: block;
137
+ // }
138
+ // }
139
+ // }
140
+
141
+ // &-label {
142
+ // padding-left: 16px;
143
+ // }
144
+ // }
145
+
146
+ // &__header {
147
+ // position: relative;
148
+ // display: flex;
149
+ // align-items: center;
150
+ // width: 100%;
151
+ // height: 100%;
152
+ // }
153
+
154
+ // &__value {
155
+ // min-width: 96px;
156
+ // min-height: 1em;
157
+ // padding-right: 50px;
158
+ // overflow: hidden;
159
+ // color: $mulledWine;
160
+ // white-space: nowrap;
161
+ // text-overflow: ellipsis;
162
+
163
+ // &_floating {
164
+ // position: relative;
165
+ // top: 6px;
166
+ // left: 16px;
167
+ // }
168
+ // }
169
+
170
+ // &__label {
171
+ // top: 15px;
172
+ // left: 0;
173
+ // padding: 0 5px 0 16px;
174
+ // color: $topaz;
175
+ // font-size: 15px;
176
+ // text-transform: capitalize;
177
+ // transition: 200ms ease;
178
+
179
+ // &_floating {
180
+ // position: absolute;
181
+ // top: 0;
182
+ // left: 0;
183
+ // padding-top: 9px;
184
+ // font-weight: 700;
185
+ // font-size: 10px;
186
+ // line-height: 12px;
187
+ // letter-spacing: 0.5px;
188
+ // transition: 200ms ease;
189
+ // }
190
+
191
+ // &_top {
192
+ // position: absolute;
193
+ // top: -20px;
194
+ // left: 0;
195
+ // padding: 0;
196
+ // font-weight: bold;
197
+ // font-size: 12px;
198
+ // line-height: 15px;
199
+
200
+ // & + .select__value {
201
+ // padding-left: 15px;
202
+ // }
203
+ // }
204
+ // }
205
+
206
+ // &__options-list {
207
+ // .pop-up-dialog {
208
+ // width: 100%;
209
+ // padding: 0;
210
+
211
+ // &__header {
212
+ // display: none;
213
+ // }
214
+ // }
215
+ // }
216
+
217
+ // &.disabled {
218
+ // cursor: not-allowed;
219
+
220
+ // .select__label,
221
+ // .select__value {
222
+ // color: $spunPearl;
223
+ // }
224
+ // }
225
+
226
+ // .sub-label {
227
+ // margin-left: 5px;
228
+ // overflow: hidden;
229
+ // color: $topaz;
230
+ // white-space: nowrap;
231
+ // text-overflow: ellipsis;
232
+ // }
233
+
234
+ // &__body {
235
+ // width: 100%;
236
+ // max-height: 250px;
237
+ // overflow-y: auto;
238
+ // color: $mulledWineTwo;
239
+ // background-color: $white;
240
+ // border: $primaryBorder;
241
+ // border-radius: 2px;
242
+ // box-shadow: $filterShadow;
243
+ // }
244
+
245
+ // &__search {
246
+ // width: 100%;
247
+
248
+ // input {
249
+ // width: 100%;
250
+ // padding: 10px;
251
+ // border: none;
252
+ // border-bottom: $primaryBorder;
253
+ // }
254
+ // }
255
+
256
+ // .actions {
257
+ // position: absolute;
258
+ // right: 25px;
259
+ // }
260
+
261
+ // .disabled {
262
+ // color: $spunPearl;
263
+ // cursor: default;
264
+ // user-select: none;
265
+
266
+ // &:hover {
267
+ // background-color: $white;
268
+ // }
269
+ // }
270
+
271
+ // .pop-up-dialog__overlay {
272
+ // top: 100%;
273
+ // right: calc(100% + 10px);
274
+ // }
275
+
276
+ // &-dense {
277
+ // height: 40px;
278
+
279
+ // .select__label_floating {
280
+ // padding-top: 6px;
281
+ // }
282
+ // }
283
+
284
+ // &-normal {
285
+ // height: 48px;
286
+ // }
287
+
288
+ // &-medium {
289
+ // height: 52px;
290
+
291
+ // .select__label_floating {
292
+ // padding-top: 11px;
293
+ // }
294
+ // }
295
+
296
+ // &-chunky {
297
+ // height: 56px;
298
+
299
+ // .select__label_floating {
300
+ // padding-top: 13px;
301
+ // }
302
+ // }
303
+ // }
@@ -17,13 +17,13 @@ var _classnames = _interopRequireDefault(require("classnames"));
17
17
 
18
18
  var _Backdrop = _interopRequireDefault(require("../Backdrop/Backdrop"));
19
19
 
20
- var _components = require("igz-controls/components");
20
+ var _RoundedIcon = _interopRequireDefault(require("../RoundedIcon/RoundedIcon"));
21
21
 
22
22
  var _constants = require("../../constants");
23
23
 
24
24
  var _types = require("../../types");
25
25
 
26
- var _close = require("igz-controls/images/close.svg");
26
+ var _close = require("../../images/close.svg");
27
27
 
28
28
  require("./Modal.scss");
29
29
 
@@ -37,7 +37,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
37
37
 
38
38
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39
39
 
40
- var JSX_MODAL = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
40
+ var JSX_MODAL = function JSX_MODAL(_ref) {
41
41
  var actions = _ref.actions,
42
42
  children = _ref.children,
43
43
  className = _ref.className,
@@ -60,11 +60,10 @@ var JSX_MODAL = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
60
60
  "data-testid": "modal",
61
61
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
62
62
  className: "modal__header-button",
63
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RoundedIcon, {
63
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RoundedIcon.default, {
64
+ "data-testid": "pop-up-close-btn",
64
65
  onClick: onClose,
65
66
  tooltipText: "Close",
66
- "data-testid": "pop-up-close-btn",
67
- ref: ref,
68
67
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_close.ReactComponent, {})
69
68
  })
70
69
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
@@ -93,13 +92,11 @@ var JSX_MODAL = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
93
92
  })
94
93
  })]
95
94
  });
96
- });
95
+ };
97
96
 
98
- var Modal = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
99
- return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/(0, _jsxRuntime.jsx)(JSX_MODAL, _objectSpread(_objectSpread({}, props), {}, {
100
- ref: ref
101
- })), document.getElementById('overlay_container'));
102
- });
97
+ var Modal = function Modal(props) {
98
+ return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/(0, _jsxRuntime.jsx)(JSX_MODAL, _objectSpread({}, props)), document.getElementById('overlay_container'));
99
+ };
103
100
 
104
101
  Modal.defaultProps = {
105
102
  actions: [],
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+
14
+ var _reactTransitionGroup = require("react-transition-group");
15
+
16
+ var _classnames = _interopRequireDefault(require("classnames"));
17
+
18
+ var _reactDom = require("react-dom");
19
+
20
+ var _questionMark = require("../../images/question-mark.svg");
21
+
22
+ var _tip = _interopRequireDefault(require("./tip.scss"));
23
+
24
+ var _jsxRuntime = require("react/jsx-runtime");
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+
28
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
+
30
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+
32
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
33
+
34
+ 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."); }
35
+
36
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
37
+
38
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
39
+
40
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
41
+
42
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
43
+
44
+ var arrowOffset = parseInt(_tip.default.arrowoffset);
45
+ var arrowLength = parseInt(_tip.default.arrowlength);
46
+ var iconLength = parseInt(_tip.default.iconlength);
47
+ var minTextLength = 40;
48
+
49
+ var Tip = function Tip(_ref) {
50
+ var className = _ref.className,
51
+ text = _ref.text;
52
+
53
+ var _useState = (0, _react.useState)(false),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ isShow = _useState2[0],
56
+ setIsShow = _useState2[1];
57
+
58
+ var _useState3 = (0, _react.useState)('tip_top tip_left'),
59
+ _useState4 = _slicedToArray(_useState3, 2),
60
+ tipClassName = _useState4[0],
61
+ setTipClassName = _useState4[1];
62
+
63
+ var iconRef = (0, _react.useRef)();
64
+ var tipBodyRef = (0, _react.useRef)();
65
+ var tipContainerClassNames = (0, _classnames.default)(className, 'tip-container');
66
+ var tipClassNames = (0, _classnames.default)('tip', tipClassName, text.length <= minTextLength ? 'tip_small' : 'tip_big');
67
+ var handleMouseEnter = (0, _react.useCallback)(function (event) {
68
+ setIsShow(true);
69
+ var iconRect = iconRef.current.getBoundingClientRect();
70
+ var tipRect = tipBodyRef.current.getBoundingClientRect();
71
+ var widthPosition = iconRect.left > tipRect.width - arrowOffset ? 'tip_left' : 'tip_right';
72
+ var heightPosition = iconRect.top > tipRect.height + arrowLength ? 'tip_top' : 'tip_bottom';
73
+ setTipClassName("".concat(heightPosition, " ").concat(widthPosition));
74
+
75
+ if (widthPosition === 'tip_left') {
76
+ var computedArrowOffset = arrowOffset + (iconLength + arrowLength) / 2;
77
+ tipBodyRef.current.style.left = "".concat(iconRect.left - (tipRect.width - computedArrowOffset), "px");
78
+ } else {
79
+ var _computedArrowOffset = arrowOffset - (iconLength - arrowLength) / 2;
80
+
81
+ tipBodyRef.current.style.left = "".concat(iconRect.left - _computedArrowOffset, "px");
82
+ }
83
+
84
+ tipBodyRef.current.style.top = heightPosition === 'tip_top' ? "".concat(iconRect.top - tipRect.height - arrowLength, "px") : "".concat(iconRect.bottom + arrowLength, "px");
85
+ }, []);
86
+
87
+ var handleMouseLeave = function handleMouseLeave() {
88
+ setIsShow(false);
89
+ };
90
+
91
+ (0, _react.useEffect)(function () {
92
+ var node = iconRef.current;
93
+
94
+ if (iconRef.current) {
95
+ node.addEventListener('mouseenter', handleMouseEnter);
96
+ node.addEventListener('mouseleave', handleMouseLeave);
97
+ return function () {
98
+ node.removeEventListener('mouseenter', handleMouseEnter);
99
+ node.removeEventListener('mouseleave', handleMouseLeave);
100
+ };
101
+ }
102
+ }, [handleMouseEnter, isShow]);
103
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
104
+ "data-testid": "tip",
105
+ className: tipContainerClassNames,
106
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_questionMark.ReactComponent, {
107
+ "data-testid": "tip-icon",
108
+ ref: iconRef
109
+ }), /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactTransitionGroup.CSSTransition, {
110
+ in: isShow,
111
+ timeout: 200,
112
+ classNames: "fade",
113
+ unmountOnExit: true,
114
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
115
+ ref: tipBodyRef,
116
+ "data-testid": "tip-text",
117
+ className: tipClassNames,
118
+ children: text
119
+ })
120
+ }), document.getElementById('overlay_container'))]
121
+ });
122
+ };
123
+
124
+ Tip.defaultProps = {
125
+ className: ''
126
+ };
127
+ Tip.propTypes = {
128
+ className: _propTypes.default.string,
129
+ text: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]).isRequired
130
+ };
131
+ var _default = Tip;
132
+ exports.default = _default;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ var _react = _interopRequireDefault(require("react"));
6
+
7
+ var _react2 = require("@testing-library/react");
8
+
9
+ var _Tip = _interopRequireDefault(require("./Tip"));
10
+
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
16
+
17
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
18
+
19
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20
+
21
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
22
+
23
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
24
+
25
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
26
+
27
+ jest.mock('../../images/question-mark.svg', function () {
28
+ return {
29
+ ReactComponent: 'Question-icon'
30
+ };
31
+ });
32
+
33
+ var renderComponent = function renderComponent(props) {
34
+ return (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tip.default, _objectSpread({}, props)));
35
+ };
36
+
37
+ describe('Tip component', function () {
38
+ var wrapper;
39
+ beforeEach(function () {
40
+ var props = {
41
+ text: 'Show tip component'
42
+ };
43
+ wrapper = renderComponent(props);
44
+ });
45
+ it('renders without crashing', function () {
46
+ expect(wrapper.queryByTestId('tip')).not.toBeNull();
47
+ });
48
+ it('should display tip text if mouse over the icon', function () {
49
+ var tipIcon = wrapper.getByTestId('tip-icon');
50
+
51
+ _react2.fireEvent.mouseEnter(tipIcon);
52
+
53
+ expect(wrapper.queryByTestId('tip-text')).not.toBeNull();
54
+ });
55
+ it('should hide tip text if mouse leave the icon', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
56
+ var tipIcon, tipText;
57
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
58
+ while (1) {
59
+ switch (_context.prev = _context.next) {
60
+ case 0:
61
+ tipIcon = wrapper.getByTestId('tip-icon');
62
+
63
+ _react2.fireEvent.mouseEnter(tipIcon);
64
+
65
+ expect(wrapper.queryByTestId('tip-text')).not.toBeNull();
66
+
67
+ _react2.fireEvent.mouseLeave(tipIcon);
68
+
69
+ _context.next = 6;
70
+ return (0, _react2.waitForElementToBeRemoved)(function () {
71
+ return wrapper.queryByTestId('tip-text');
72
+ });
73
+
74
+ case 6:
75
+ tipText = _context.sent;
76
+ expect(tipText).toBeUndefined();
77
+
78
+ case 8:
79
+ case "end":
80
+ return _context.stop();
81
+ }
82
+ }
83
+ }, _callee);
84
+ })));
85
+ it('should add the class "tip_big" if the length of the prop text is more than 40 characters', function () {
86
+ wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tip.default, {
87
+ text: "Lorem Ipsum is simply dummy text of the printing and typesetting"
88
+ }));
89
+ var tipIcon = wrapper.getByTestId('tip-icon');
90
+
91
+ _react2.fireEvent.mouseEnter(tipIcon);
92
+
93
+ var tipText = wrapper.getByTestId('tip-text');
94
+ expect(tipText.className).toMatch('tip_big');
95
+ });
96
+ });