@enact/ui 4.1.2 → 4.5.0-alpha.1
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.
- package/AnnounceDecorator/Announce.js +9 -9
- package/AnnounceDecorator/AnnounceDecorator.js +6 -4
- package/AnnounceDecorator/tests/Announce-specs.js +13 -5
- package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +9 -7
- package/AnnounceDecorator/tests/useAnnounce-specs.js +25 -17
- package/AnnounceDecorator/useAnnounce.js +1 -1
- package/BodyText/BodyText.d.ts +1 -1
- package/BodyText/BodyText.js +6 -4
- package/BodyText/tests/BodyText-specs.js +51 -37
- package/Button/Button.d.ts +6 -6
- package/Button/Button.js +11 -7
- package/Button/tests/Button-specs.js +104 -3
- package/CHANGELOG.md +25 -0
- package/Cancelable/Cancelable.js +12 -11
- package/Cancelable/tests/Cancelable-specs.js +133 -70
- package/Changeable/Changeable.js +9 -9
- package/Changeable/tests/Changeable-specs.js +172 -110
- package/ComponentOverride/ComponentOverride.js +6 -4
- package/FloatingLayer/FloatingLayer.js +40 -49
- package/FloatingLayer/FloatingLayer.module.css +3 -0
- package/FloatingLayer/FloatingLayerContainer.js +2 -2
- package/FloatingLayer/FloatingLayerDecorator.js +6 -4
- package/FloatingLayer/Scrim.js +9 -7
- package/FloatingLayer/index.js +1 -1
- package/FloatingLayer/tests/FloatingLayer-specs.js +83 -8
- package/FloatingLayer/tests/Scrim-specs.js +20 -11
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +17 -11
- package/FloatingLayer/useFloatingLayer.js +2 -2
- package/FloatingLayer/useFloatingLayerDecorator.js +1 -1
- package/ForwardRef/ForwardRef.js +3 -3
- package/GridListImageItem/GridListImageItem.d.ts +1 -1
- package/GridListImageItem/GridListImageItem.js +6 -4
- package/Group/Group.d.ts +2 -2
- package/Group/Group.js +7 -4
- package/Group/GroupItem.js +6 -4
- package/Group/tests/Group-specs.js +73 -43
- package/Heading/Heading.d.ts +2 -1
- package/Heading/Heading.js +6 -4
- package/Heading/tests/Heading-specs.js +27 -20
- package/Icon/Icon.d.ts +4 -4
- package/Icon/Icon.js +6 -4
- package/Icon/tests/Icon-specs.js +54 -33
- package/IconButton/IconButton.d.ts +4 -4
- package/IconButton/IconButton.js +6 -4
- package/IconButton/tests/IconButton-specs.js +2 -2
- package/Image/Image.js +6 -4
- package/Image/tests/Image-specs.js +41 -31
- package/ImageItem/ImageItem.js +8 -5
- package/ImageItem/tests/ImageItem-specs.js +75 -72
- package/Item/Item.js +6 -4
- package/Item/tests/Item-specs.js +59 -35
- package/LabeledIcon/LabeledIcon.d.ts +4 -4
- package/LabeledIcon/LabeledIcon.js +6 -4
- package/LabeledIcon/tests/LabeledIcon-specs.js +30 -19
- package/Layout/Cell.js +6 -4
- package/Layout/Layout.d.ts +16 -16
- package/Layout/Layout.js +6 -4
- package/Layout/tests/Layout-specs.js +42 -30
- package/Marquee/MarqueeBase.js +7 -9
- package/Marquee/MarqueeController.js +9 -9
- package/Marquee/MarqueeDecorator.js +18 -13
- package/Marquee/index.d.ts +4 -1
- package/Marquee/index.js +2 -1
- package/Marquee/tests/Marquee-specs.js +254 -122
- package/Measurable/Measurable.js +4 -4
- package/Media/Media.js +10 -10
- package/Placeholder/PlaceholderControllerDecorator.js +9 -9
- package/Placeholder/PlaceholderDecorator.js +9 -9
- package/ProgressBar/ProgressBar.js +6 -4
- package/ProgressBar/tests/ProgressBar-specs.js +60 -42
- package/README.md +1 -1
- package/RadioDecorator/RadioControllerDecorator.js +9 -9
- package/RadioDecorator/RadioDecorator.js +12 -14
- package/RadioDecorator/tests/RadioDecorator-specs.js +179 -65
- package/Repeater/Repeater.d.ts +2 -1
- package/Repeater/Repeater.js +6 -4
- package/Repeater/tests/Repeater-specs.js +90 -49
- package/Resizable/Resizable.js +10 -10
- package/Routable/Link.js +9 -7
- package/Routable/Routable.d.ts +2 -2
- package/Routable/Routable.js +10 -6
- package/Routable/Route.js +1 -1
- package/Routable/Router.js +14 -11
- package/Routable/tests/Routable-specs.js +29 -20
- package/Routable/tests/Router-specs.js +65 -41
- package/Routable/useLink.js +1 -1
- package/Routable/util.js +1 -1
- package/Scrollable/ScrollAnimator.js +2 -2
- package/Scrollable/ScrollThumb.js +3 -3
- package/Scrollable/Scrollable.js +14 -10
- package/Scrollable/ScrollableNative.js +14 -10
- package/Scrollable/Scrollbar.js +14 -8
- package/Scroller/Scroller.d.ts +2 -14
- package/Scroller/Scroller.js +8 -7
- package/Scroller/ScrollerBasic.js +18 -35
- package/Scroller/UiScrollerBase.js +9 -7
- package/Skinnable/Skinnable.js +6 -4
- package/Skinnable/tests/Skinnable-specs.js +104 -56
- package/Skinnable/tests/useSkins-specs.js +39 -44
- package/Skinnable/useSkins.js +1 -1
- package/Slider/Knob.js +6 -4
- package/Slider/PositionDecorator.js +9 -9
- package/Slider/Slider.d.ts +3 -3
- package/Slider/Slider.js +6 -4
- package/Slider/tests/Slider-specs.js +4 -4
- package/SlotItem/SlotItem.d.ts +2 -2
- package/SlotItem/SlotItem.js +6 -4
- package/SlotItem/tests/SlotItem-specs.js +4 -4
- package/Slottable/Slottable.js +3 -3
- package/Slottable/tests/Slottable-specs.js +67 -36
- package/Slottable/tests/useSlots-specs.js +68 -35
- package/Slottable/useSlots.js +6 -4
- package/Spinner/Spinner.d.ts +1 -1
- package/Spinner/Spinner.js +6 -4
- package/Spinner/tests/Spinner-specs.js +46 -31
- package/ToggleIcon/ToggleIcon.js +6 -4
- package/ToggleIcon/tests/ToggleIcon-specs.js +32 -20
- package/ToggleItem/ToggleItem.d.ts +13 -11
- package/ToggleItem/ToggleItem.js +6 -4
- package/ToggleItem/tests/ToggleItem-specs.js +54 -37
- package/Toggleable/Toggle.js +10 -10
- package/Toggleable/Toggleable.js +11 -17
- package/Toggleable/tests/Toggleable-specs.js +464 -324
- package/Toggleable/useToggle.js +4 -2
- package/Touchable/ClickAllow.js +2 -2
- package/Touchable/Drag.js +22 -22
- package/Touchable/Flick.js +22 -18
- package/Touchable/Hold.js +18 -23
- package/Touchable/Touch.js +2 -2
- package/Touchable/Touchable.d.ts +3 -3
- package/Touchable/Touchable.js +7 -4
- package/Touchable/config.js +3 -3
- package/Touchable/tests/Touchable-specs.js +225 -109
- package/Touchable/tests/useTouch-specs.js +163 -86
- package/Touchable/useTouch.js +4 -4
- package/Transition/Transition.d.ts +29 -27
- package/Transition/Transition.js +22 -17
- package/Transition/tests/Transition-specs.js +116 -36
- package/ViewManager/Arranger.js +3 -3
- package/ViewManager/TransitionGroup.js +10 -9
- package/ViewManager/View.js +7 -7
- package/ViewManager/ViewManager.d.ts +4 -4
- package/ViewManager/ViewManager.js +24 -22
- package/ViewManager/tests/View-specs.js +141 -81
- package/ViewManager/tests/ViewManager-specs.js +486 -193
- package/VirtualList/UiVirtualListBase.js +26 -35
- package/VirtualList/VirtualList.d.ts +11 -29
- package/VirtualList/VirtualList.js +10 -9
- package/VirtualList/VirtualListBase.js +1 -1
- package/VirtualList/VirtualListBasic.js +44 -61
- package/VirtualList/tests/VirtualList-specs.js +81 -95
- package/internal/IdProvider/IdProvider.js +3 -3
- package/internal/IdProvider/Provider.js +2 -2
- package/internal/IdProvider/tests/useId-specs.js +37 -20
- package/internal/Pure/Pure.js +9 -9
- package/internal/localized-fonts/localized-fonts.js +1 -1
- package/internal/validators/validators.js +1 -1
- package/package.json +11 -11
- package/resolution/ResolutionDecorator.js +9 -9
- package/resolution/index.js +2 -2
- package/resolution/resolution.js +4 -2
- package/resolution/tests/ResolutionDecorator-specs.js +17 -8
- package/styles/mixins.less +14 -2
- package/useControlledState/tests/useControlledState-specs.js +68 -43
- package/useControlledState/useControlledState.js +2 -2
- package/useScroll/ScrollAnimator.js +2 -2
- package/useScroll/Scrollbar.js +7 -4
- package/useScroll/ScrollbarTrack.js +6 -4
- package/useScroll/useScroll.js +18 -29
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
|
+
|
|
9
|
+
var _Button = require("../Button");
|
|
6
10
|
|
|
7
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
12
|
|
|
@@ -11,11 +15,108 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
11
15
|
describe('Button', function () {
|
|
12
16
|
test('should return a DOM node reference for `componentRef`', function () {
|
|
13
17
|
var ref = jest.fn();
|
|
14
|
-
(0,
|
|
18
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
15
19
|
ref: ref
|
|
16
20
|
}));
|
|
17
21
|
var expected = 'DIV';
|
|
18
22
|
var actual = ref.mock.calls[0][0].nodeName;
|
|
19
23
|
expect(actual).toBe(expected);
|
|
20
24
|
});
|
|
25
|
+
test('should have \'disabled\' HTML attribute when \'disabled\' prop is provided', function () {
|
|
26
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
27
|
+
disabled: true,
|
|
28
|
+
children: "I am a disabled Button"
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
var button = _react.screen.getByRole('button');
|
|
32
|
+
|
|
33
|
+
expect(button).toHaveAttribute('disabled');
|
|
34
|
+
});
|
|
35
|
+
test('should have default minWidth class', function () {
|
|
36
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {}));
|
|
37
|
+
|
|
38
|
+
var button = _react.screen.getByRole('button');
|
|
39
|
+
|
|
40
|
+
var expected = 'minWidth';
|
|
41
|
+
expect(button).toHaveClass(expected);
|
|
42
|
+
});
|
|
43
|
+
test('should have selected class when selected prop is set to true', function () {
|
|
44
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
|
|
45
|
+
selected: true
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
var button = _react.screen.getByRole('button');
|
|
49
|
+
|
|
50
|
+
var expected = 'selected';
|
|
51
|
+
expect(button).toHaveClass(expected);
|
|
52
|
+
});
|
|
53
|
+
test('should have pressed class when pressed prop is set to true', function () {
|
|
54
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
|
|
55
|
+
pressed: true
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
var button = _react.screen.getByRole('button');
|
|
59
|
+
|
|
60
|
+
var expected = 'pressed';
|
|
61
|
+
expect(button).toHaveClass(expected);
|
|
62
|
+
});
|
|
63
|
+
test('should have large class when size prop is set to large', function () {
|
|
64
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
|
|
65
|
+
size: "large"
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
var button = _react.screen.getByRole('button');
|
|
69
|
+
|
|
70
|
+
var expected = 'large';
|
|
71
|
+
expect(button).toHaveClass(expected);
|
|
72
|
+
});
|
|
73
|
+
test('should have small class when size prop is set to small', function () {
|
|
74
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
|
|
75
|
+
size: "small"
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
var button = _react.screen.getByRole('button');
|
|
79
|
+
|
|
80
|
+
var expected = 'small';
|
|
81
|
+
expect(button).toHaveClass(expected);
|
|
82
|
+
});
|
|
83
|
+
test('should have hasIcon class when icon prop is defined', function () {
|
|
84
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
85
|
+
icon: true,
|
|
86
|
+
children: "Hello Button!"
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
var button = _react.screen.getByRole('button');
|
|
90
|
+
|
|
91
|
+
var expected = 'hasIcon';
|
|
92
|
+
expect(button).toHaveClass(expected);
|
|
93
|
+
});
|
|
94
|
+
test('should call onClick', function () {
|
|
95
|
+
var handleCLick = jest.fn();
|
|
96
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
97
|
+
onClick: handleCLick,
|
|
98
|
+
children: "Hello Button!"
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
var button = _react.screen.getByRole('button');
|
|
102
|
+
|
|
103
|
+
_userEvent["default"].click(button);
|
|
104
|
+
|
|
105
|
+
var expected = 1;
|
|
106
|
+
expect(handleCLick).toHaveBeenCalledTimes(expected);
|
|
107
|
+
});
|
|
108
|
+
test('should not call onClick when button is disabled', function () {
|
|
109
|
+
var handleClick = jest.fn();
|
|
110
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
111
|
+
disabled: true,
|
|
112
|
+
onClick: handleClick,
|
|
113
|
+
children: "Hello Button!"
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
var button = _react.screen.getByRole('button');
|
|
117
|
+
|
|
118
|
+
_userEvent["default"].click(button);
|
|
119
|
+
|
|
120
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
21
122
|
});
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact ui module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [4.5.0-alpha.1] - 2022-04-15
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `ui/FloatingLayer` to stack popups always in the order in which they were opened
|
|
10
|
+
|
|
11
|
+
## [4.1.4] - 2022-03-24
|
|
12
|
+
|
|
13
|
+
### Removed
|
|
14
|
+
|
|
15
|
+
- `ui/Scroller` and `ui/VirtualList` prop `data-webos-voice-focused`, `data-webos-voice-disabled`, and `data-webos-voice-group-label`
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- `ui/MarqueeDecorator` `locale` type for `forceDirection` prop not to override the direction depending on contents
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `ui/Button` not to pass `icon` prop as children when `icon` is true
|
|
24
|
+
- `ui/Transition` to pass the event when handling transition event
|
|
25
|
+
|
|
26
|
+
## [4.1.3] - 2022-03-07
|
|
27
|
+
|
|
28
|
+
- Updated to use `forwardCustom` and add `type` when forwarding custom events
|
|
29
|
+
|
|
5
30
|
## [4.1.2] - 2021-12-22
|
|
6
31
|
|
|
7
32
|
### Fixed
|
package/Cancelable/Cancelable.js
CHANGED
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.Cancelable = void 0;
|
|
6
7
|
Object.defineProperty(exports, "addCancelHandler", {
|
|
7
8
|
enumerable: true,
|
|
8
9
|
get: function get() {
|
|
9
10
|
return _cancelHandler.addCancelHandler;
|
|
10
11
|
}
|
|
11
12
|
});
|
|
13
|
+
exports["default"] = void 0;
|
|
12
14
|
Object.defineProperty(exports, "removeCancelHandler", {
|
|
13
15
|
enumerable: true,
|
|
14
16
|
get: function get() {
|
|
15
17
|
return _cancelHandler.removeCancelHandler;
|
|
16
18
|
}
|
|
17
19
|
});
|
|
18
|
-
exports.Cancelable = exports["default"] = void 0;
|
|
19
20
|
|
|
20
21
|
var _handle = require("@enact/core/handle");
|
|
21
22
|
|
|
@@ -37,9 +38,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
37
38
|
|
|
38
39
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
39
40
|
|
|
40
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
41
|
+
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; }
|
|
41
42
|
|
|
42
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
43
|
+
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; }
|
|
43
44
|
|
|
44
45
|
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; }
|
|
45
46
|
|
|
@@ -47,15 +48,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
47
48
|
|
|
48
49
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
49
50
|
|
|
50
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
51
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
51
52
|
|
|
52
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
53
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
53
54
|
|
|
54
55
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
55
56
|
|
|
56
57
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
57
58
|
|
|
58
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
59
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
59
60
|
|
|
60
61
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
61
62
|
|
|
@@ -165,12 +166,12 @@ var defaultConfig = {
|
|
|
165
166
|
*/
|
|
166
167
|
|
|
167
168
|
var Cancelable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
168
|
-
var _class
|
|
169
|
+
var _class;
|
|
169
170
|
|
|
170
171
|
var onCancel = config.onCancel,
|
|
171
172
|
modal = config.modal,
|
|
172
173
|
Component = config.component;
|
|
173
|
-
!onCancel ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'onCancel must be specified with Cancelable') :
|
|
174
|
+
!onCancel ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'onCancel must be specified with Cancelable') : (0, _invariant["default"])(false) : void 0;
|
|
174
175
|
var onCancelIsString = typeof onCancel === 'string';
|
|
175
176
|
var onCancelIsFunction = typeof onCancel === 'function';
|
|
176
177
|
|
|
@@ -196,7 +197,7 @@ var Cancelable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped)
|
|
|
196
197
|
return stopped;
|
|
197
198
|
};
|
|
198
199
|
|
|
199
|
-
return
|
|
200
|
+
return _class = /*#__PURE__*/function (_ReactComponent) {
|
|
200
201
|
_inherits(_class, _ReactComponent);
|
|
201
202
|
|
|
202
203
|
var _super = _createSuper(_class);
|
|
@@ -208,7 +209,7 @@ var Cancelable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped)
|
|
|
208
209
|
|
|
209
210
|
_this = _super.call(this, props);
|
|
210
211
|
_this.handle = _handle.handle.bind(_assertThisInitialized(_this));
|
|
211
|
-
_this.handleCancel = _this.handle(_cancelHandler.forCancel, (0, _handle.
|
|
212
|
+
_this.handleCancel = _this.handle(_cancelHandler.forCancel, (0, _handle.forwardCustom)('onCancel'), dispatchCancelToConfig, _handle.stop, _handle.stopImmediate);
|
|
212
213
|
_this.handleKeyUp = _this.handle((0, _handle.forward)('onKeyUp'), // nesting handlers for DRYness. note that if any conditions return false in
|
|
213
214
|
// this.handleCancel(), this handler chain will stop too
|
|
214
215
|
_this.handleCancel);
|
|
@@ -273,7 +274,7 @@ var Cancelable = (0, _hoc["default"])(defaultConfig, function (config, Wrapped)
|
|
|
273
274
|
* @public
|
|
274
275
|
*/
|
|
275
276
|
onCancel: _propTypes["default"].func
|
|
276
|
-
},
|
|
277
|
+
}, _class;
|
|
277
278
|
});
|
|
278
279
|
exports.Cancelable = Cancelable;
|
|
279
280
|
var _default = Cancelable;
|
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
4
|
|
|
5
5
|
var _Cancelable = require("../Cancelable");
|
|
6
6
|
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
|
|
9
|
+
var _excluded = ["children", "className", "onKeyUp"];
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
|
+
|
|
19
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
|
+
|
|
9
21
|
describe('Cancelable', function () {
|
|
10
22
|
// Suite-wide setup
|
|
11
23
|
var Component = function Component(_ref) {
|
|
12
24
|
var children = _ref.children,
|
|
13
25
|
className = _ref.className,
|
|
14
|
-
onKeyUp = _ref.onKeyUp
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
onKeyUp = _ref.onKeyUp,
|
|
27
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
28
|
+
|
|
29
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
|
|
17
30
|
className: className,
|
|
31
|
+
"data-testid": "cancelable",
|
|
32
|
+
onKeyUp: onKeyUp
|
|
33
|
+
}, rest), {}, {
|
|
18
34
|
children: children
|
|
19
|
-
});
|
|
35
|
+
}));
|
|
20
36
|
};
|
|
21
37
|
|
|
22
38
|
var makeKeyEvent = function makeKeyEvent(keyCode) {
|
|
@@ -36,64 +52,95 @@ describe('Cancelable', function () {
|
|
|
36
52
|
return ev.stopPropagation();
|
|
37
53
|
};
|
|
38
54
|
|
|
39
|
-
test('should call onCancel from prop for escape key', function () {
|
|
55
|
+
test('should call onCancel with type from prop for escape key', function () {
|
|
40
56
|
var handleCancel = jest.fn(returnsTrue);
|
|
41
57
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
42
58
|
onCancel: 'onCustomEvent'
|
|
43
59
|
}, Component);
|
|
44
|
-
|
|
60
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
45
61
|
onCustomEvent: handleCancel
|
|
46
62
|
}));
|
|
47
|
-
|
|
63
|
+
|
|
64
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
65
|
+
|
|
66
|
+
_react.fireEvent.keyUp(component, makeKeyEvent(27));
|
|
67
|
+
|
|
48
68
|
var expected = 1;
|
|
49
|
-
var
|
|
50
|
-
|
|
69
|
+
var expectedType = {
|
|
70
|
+
type: 'onCustomEvent'
|
|
71
|
+
};
|
|
72
|
+
var actual = handleCancel.mock.calls.length && handleCancel.mock.calls[0][0];
|
|
73
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
74
|
+
expect(actual).toMatchObject(expectedType);
|
|
51
75
|
});
|
|
52
|
-
test('should only call onCancel for escape key by default', function () {
|
|
76
|
+
test('should only call onCancel with type for escape key by default', function () {
|
|
53
77
|
var handleCancel = jest.fn(returnsTrue);
|
|
54
78
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
55
79
|
onCancel: handleCancel
|
|
56
80
|
}, Component);
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
82
|
+
|
|
83
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
84
|
+
|
|
85
|
+
_react.fireEvent.keyUp(component, makeKeyEvent(27));
|
|
86
|
+
|
|
59
87
|
var expected = 1;
|
|
60
|
-
var
|
|
61
|
-
|
|
88
|
+
var expectedType = {
|
|
89
|
+
type: 'onCancel'
|
|
90
|
+
};
|
|
91
|
+
var actual = handleCancel.mock.calls.length && handleCancel.mock.calls[0][0];
|
|
92
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
93
|
+
expect(actual).toMatchObject(expectedType);
|
|
62
94
|
});
|
|
63
95
|
test('should not call onCancel for non-escape key', function () {
|
|
64
96
|
var handleCancel = jest.fn(returnsTrue);
|
|
65
97
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
66
98
|
onCancel: handleCancel
|
|
67
99
|
}, Component);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
100
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
101
|
+
|
|
102
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
103
|
+
|
|
104
|
+
_react.fireEvent.keyUp(component, makeKeyEvent(42));
|
|
105
|
+
|
|
106
|
+
expect(handleCancel).not.toHaveBeenCalled();
|
|
73
107
|
});
|
|
74
108
|
test('should stop propagation when handled', function () {
|
|
75
109
|
var handleCancel = jest.fn(stop);
|
|
110
|
+
var handleCancelParent = jest.fn(stop);
|
|
76
111
|
var keyEvent = makeKeyEvent(27);
|
|
77
112
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
78
113
|
onCancel: handleCancel
|
|
79
114
|
}, Component);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
115
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
116
|
+
onKeyUp: handleCancelParent,
|
|
117
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {})
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
121
|
+
|
|
122
|
+
_react.fireEvent.keyUp(component, keyEvent);
|
|
123
|
+
|
|
124
|
+
expect(handleCancelParent).not.toHaveBeenCalled();
|
|
85
125
|
});
|
|
86
126
|
test('should not stop propagation for not handled', function () {
|
|
87
127
|
var handleCancel = jest.fn(returnsTrue);
|
|
128
|
+
var handleCancelParent = jest.fn(returnsTrue);
|
|
88
129
|
var keyEvent = makeKeyEvent(42);
|
|
89
130
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
90
131
|
onCancel: handleCancel
|
|
91
132
|
}, Component);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
133
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
134
|
+
onKeyUp: handleCancelParent,
|
|
135
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {})
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
139
|
+
|
|
140
|
+
_react.fireEvent.keyUp(component, keyEvent);
|
|
141
|
+
|
|
142
|
+
var expected = 1;
|
|
143
|
+
expect(handleCancelParent).toHaveBeenCalledTimes(expected);
|
|
97
144
|
});
|
|
98
145
|
test('should forward to onKeyUp handler for any key', function () {
|
|
99
146
|
var handleKeyUp = jest.fn();
|
|
@@ -101,13 +148,16 @@ describe('Cancelable', function () {
|
|
|
101
148
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
102
149
|
onCancel: returnsTrue
|
|
103
150
|
}, Component);
|
|
104
|
-
|
|
151
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
105
152
|
onKeyUp: handleKeyUp
|
|
106
153
|
}));
|
|
107
|
-
|
|
154
|
+
|
|
155
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
156
|
+
|
|
157
|
+
_react.fireEvent.keyUp(component, keyEvent);
|
|
158
|
+
|
|
108
159
|
var expected = 1;
|
|
109
|
-
|
|
110
|
-
expect(actual).toBe(expected);
|
|
160
|
+
expect(handleKeyUp).toHaveBeenCalledTimes(expected);
|
|
111
161
|
});
|
|
112
162
|
test('should call onCancel when additional cancel handlers pass', function () {
|
|
113
163
|
var customCancelHandler = function customCancelHandler(ev) {
|
|
@@ -119,76 +169,94 @@ describe('Cancelable', function () {
|
|
|
119
169
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
120
170
|
onCancel: handleCancel
|
|
121
171
|
}, Component);
|
|
122
|
-
|
|
123
|
-
|
|
172
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
173
|
+
|
|
174
|
+
var component = _react.screen.getByTestId('cancelable');
|
|
175
|
+
|
|
176
|
+
_react.fireEvent.keyUp(component, makeKeyEvent(461));
|
|
177
|
+
|
|
124
178
|
(0, _Cancelable.removeCancelHandler)(customCancelHandler);
|
|
125
179
|
var expected = 1;
|
|
126
|
-
|
|
127
|
-
expect(actual).toBe(expected);
|
|
180
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
128
181
|
});
|
|
129
182
|
test('should bubble up the component tree when config handler does not call stopPropagation', function () {
|
|
130
183
|
var handleCancel = jest.fn(returnsTrue);
|
|
131
184
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
132
185
|
onCancel: handleCancel
|
|
133
186
|
}, Component);
|
|
134
|
-
|
|
187
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
135
188
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
189
|
+
"data-testid": "second",
|
|
136
190
|
className: "second"
|
|
137
191
|
})
|
|
138
192
|
}));
|
|
139
|
-
|
|
193
|
+
|
|
194
|
+
var secondComponent = _react.screen.getByTestId('second');
|
|
195
|
+
|
|
196
|
+
_react.fireEvent.keyUp(secondComponent, makeKeyEvent(27));
|
|
197
|
+
|
|
140
198
|
var expected = 2;
|
|
141
|
-
|
|
142
|
-
expect(actual).toBe(expected);
|
|
199
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
143
200
|
});
|
|
144
201
|
test('should not bubble up the component tree when config handler calls stopPropagation', function () {
|
|
145
202
|
var handleCancel = jest.fn(stop);
|
|
146
203
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
147
204
|
onCancel: handleCancel
|
|
148
205
|
}, Component);
|
|
149
|
-
|
|
206
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
150
207
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
208
|
+
"data-testid": "second",
|
|
151
209
|
className: "second"
|
|
152
210
|
})
|
|
153
211
|
}));
|
|
154
|
-
|
|
212
|
+
|
|
213
|
+
var secondComponent = _react.screen.getByTestId('second');
|
|
214
|
+
|
|
215
|
+
_react.fireEvent.keyUp(secondComponent, makeKeyEvent(27));
|
|
216
|
+
|
|
155
217
|
var expected = 1;
|
|
156
|
-
|
|
157
|
-
expect(actual).toBe(expected);
|
|
218
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
158
219
|
});
|
|
159
220
|
test('should bubble up the component tree when prop handler does not call stopPropagation', function () {
|
|
160
221
|
var handleCancel = jest.fn();
|
|
161
222
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
162
223
|
onCancel: 'onCustomEvent'
|
|
163
224
|
}, Component);
|
|
164
|
-
|
|
225
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
165
226
|
onCustomEvent: handleCancel,
|
|
166
227
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
228
|
+
"data-testid": "second",
|
|
167
229
|
className: "second",
|
|
168
230
|
onCustomEvent: returnsTrue
|
|
169
231
|
})
|
|
170
232
|
}));
|
|
171
|
-
|
|
233
|
+
|
|
234
|
+
var secondComponent = _react.screen.getByTestId('second');
|
|
235
|
+
|
|
236
|
+
_react.fireEvent.keyUp(secondComponent, makeKeyEvent(27));
|
|
237
|
+
|
|
172
238
|
var expected = 1;
|
|
173
|
-
|
|
174
|
-
expect(actual).toBe(expected);
|
|
239
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
175
240
|
});
|
|
176
241
|
test('should not bubble up the component tree when prop handler calls stopPropagation', function () {
|
|
177
242
|
var handleCancel = jest.fn();
|
|
178
243
|
var Comp = (0, _Cancelable.Cancelable)({
|
|
179
244
|
onCancel: 'onCustomEvent'
|
|
180
245
|
}, Component);
|
|
181
|
-
|
|
246
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
182
247
|
onCustomEvent: handleCancel,
|
|
183
248
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {
|
|
249
|
+
"data-testid": "second",
|
|
184
250
|
className: "second",
|
|
185
251
|
onCustomEvent: stop
|
|
186
252
|
})
|
|
187
253
|
}));
|
|
188
|
-
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
254
|
+
|
|
255
|
+
var secondComponent = _react.screen.getByTestId('second');
|
|
256
|
+
|
|
257
|
+
_react.fireEvent.keyUp(secondComponent, makeKeyEvent(27));
|
|
258
|
+
|
|
259
|
+
expect(handleCancel).not.toHaveBeenCalled();
|
|
192
260
|
});
|
|
193
261
|
describe('modal instances', function () {
|
|
194
262
|
var customEventHandler = function customEventHandler(ev) {
|
|
@@ -215,11 +283,10 @@ describe('Cancelable', function () {
|
|
|
215
283
|
modal: true,
|
|
216
284
|
onCancel: handleCancel
|
|
217
285
|
}, Component);
|
|
218
|
-
(0,
|
|
286
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
219
287
|
document.dispatchEvent(makeKeyboardEvent(27));
|
|
220
288
|
var expected = 1;
|
|
221
|
-
|
|
222
|
-
expect(actual).toBe(expected);
|
|
289
|
+
expect(handleCancel).toHaveBeenCalledTimes(expected);
|
|
223
290
|
});
|
|
224
291
|
test('should invoke modal handlers in LIFO order', function () {
|
|
225
292
|
var results = [];
|
|
@@ -239,12 +306,11 @@ describe('Cancelable', function () {
|
|
|
239
306
|
modal: true,
|
|
240
307
|
onCancel: append('second')
|
|
241
308
|
}, Component);
|
|
242
|
-
(0,
|
|
243
|
-
(0,
|
|
309
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(First, {}));
|
|
310
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Second, {}));
|
|
244
311
|
document.dispatchEvent(makeKeyboardEvent(27));
|
|
245
312
|
var expected = ['second', 'first'];
|
|
246
|
-
|
|
247
|
-
expect(actual).toEqual(expected);
|
|
313
|
+
expect(results).toEqual(expected);
|
|
248
314
|
});
|
|
249
315
|
test('should invoke nested modal handlers in LIFO order', function () {
|
|
250
316
|
var results = [];
|
|
@@ -264,13 +330,12 @@ describe('Cancelable', function () {
|
|
|
264
330
|
modal: true,
|
|
265
331
|
onCancel: append('second')
|
|
266
332
|
}, Component);
|
|
267
|
-
(0,
|
|
333
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(First, {
|
|
268
334
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Second, {})
|
|
269
335
|
}));
|
|
270
336
|
document.dispatchEvent(makeKeyboardEvent(27));
|
|
271
337
|
var expected = ['second', 'first'];
|
|
272
|
-
|
|
273
|
-
expect(actual).toEqual(expected);
|
|
338
|
+
expect(results).toEqual(expected);
|
|
274
339
|
});
|
|
275
340
|
test('should not invoke modal handlers after one calls stopPropagation', function () {
|
|
276
341
|
var handleCancel = jest.fn(returnsTrue);
|
|
@@ -282,12 +347,10 @@ describe('Cancelable', function () {
|
|
|
282
347
|
modal: true,
|
|
283
348
|
onCancel: stop
|
|
284
349
|
}, Component);
|
|
285
|
-
(0,
|
|
286
|
-
(0,
|
|
350
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(First, {}));
|
|
351
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Second, {}));
|
|
287
352
|
document.dispatchEvent(makeKeyboardEvent(27));
|
|
288
|
-
|
|
289
|
-
var actual = handleCancel.mock.calls.length;
|
|
290
|
-
expect(actual).toBe(expected);
|
|
353
|
+
expect(handleCancel).not.toHaveBeenCalled();
|
|
291
354
|
});
|
|
292
355
|
});
|
|
293
356
|
});
|