@enact/ui 5.6.0 → 5.7.0
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 +8 -8
- package/AnnounceDecorator/AnnounceDecorator.js +5 -5
- package/BodyText/BodyText.js +5 -5
- package/BodyText/tests/BodyText-specs.js +2 -1
- package/Button/Button.js +5 -5
- package/CHANGELOG.md +18 -0
- package/Cancelable/Cancelable.js +9 -9
- package/Cancelable/tests/Cancelable-specs.js +5 -5
- package/Card/Card.js +5 -5
- package/Card/tests/Card-specs.js +2 -1
- package/Changeable/Changeable.js +9 -9
- package/ComponentOverride/ComponentOverride.js +15 -11
- package/FloatingLayer/FloatingLayer.js +10 -10
- package/FloatingLayer/FloatingLayerContainer.js +3 -3
- package/FloatingLayer/FloatingLayerDecorator.js +5 -5
- package/FloatingLayer/Scrim.js +9 -9
- package/FloatingLayer/tests/useFloatingLayerDecorator-specs.js +4 -4
- package/FloatingLayer/useFloatingLayer.js +3 -4
- package/ForwardRef/ForwardRef.js +5 -5
- package/Group/Group.js +5 -5
- package/Group/GroupItem.js +5 -5
- package/Group/tests/Group-specs.js +2 -1
- package/Heading/Heading.js +5 -5
- package/Icon/Icon.js +5 -5
- package/Icon/tests/Icon-specs.js +2 -1
- package/Image/Image.js +5 -5
- package/Image/tests/Image-specs.js +2 -1
- package/ImageItem/ImageItem.js +5 -5
- package/ImageItem/tests/ImageItem-specs.js +6 -5
- package/Item/Item.js +5 -5
- package/LabeledIcon/LabeledIcon.js +5 -5
- package/Layout/Cell.js +5 -5
- package/Layout/Layout.js +5 -5
- package/Layout/tests/Layout-specs.js +9 -9
- package/Marquee/Marquee.module.css +44 -0
- package/Marquee/MarqueeBase.js +134 -21
- package/Marquee/MarqueeController.js +4 -4
- package/Marquee/MarqueeDecorator.js +219 -27
- package/Marquee/index.d.ts +60 -12
- package/Marquee/tests/Marquee-specs.js +3 -3
- package/Marquee/tests/Marquee-vertical-specs.js +1358 -0
- package/Marquee/useMarqueeController.js +4 -4
- package/Marquee/utils.js +22 -0
- package/Marquee/verticalMeasure.js +118 -0
- package/Measurable/Measurable.js +8 -9
- package/Measurable/tests/Measurable-specs.js +7 -6
- package/Media/Media.js +10 -10
- package/Placeholder/PlaceholderControllerDecorator.js +9 -9
- package/Placeholder/PlaceholderDecorator.js +9 -9
- package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -4
- package/ProgressBar/ProgressBar.js +5 -5
- package/Repeater/Repeater.js +5 -5
- package/Repeater/tests/Repeater-specs.js +6 -5
- package/Resizable/Resizable.js +4 -4
- package/Resizable/tests/Resizable-specs.js +2 -1
- package/Resizable/tests/useResize-specs.js +4 -4
- package/Resizable/useResize.js +3 -3
- package/Routable/Link.js +9 -9
- package/Routable/Routable.js +5 -5
- package/Routable/Router.js +9 -9
- package/Routable/tests/Routable-specs.js +7 -8
- package/Routable/tests/Router-specs.js +1 -1
- package/Scroller/Scroller.js +4 -4
- package/Scroller/ScrollerBasic.js +10 -10
- package/Skinnable/Skinnable.js +5 -5
- package/Skinnable/tests/Skinnable-specs.js +4 -4
- package/Skinnable/tests/useSkins-specs.js +4 -4
- package/Slider/Knob.js +5 -5
- package/Slider/PositionDecorator.js +8 -8
- package/Slider/Slider.js +5 -5
- package/Slottable/Slottable.js +4 -4
- package/Slottable/useSlots.js +5 -5
- package/Spinner/Spinner.js +5 -5
- package/ToggleIcon/ToggleIcon.js +5 -5
- package/Toggleable/Toggle.js +5 -5
- package/Toggleable/Toggleable.js +9 -9
- package/Toggleable/useToggle.js +5 -5
- package/Touchable/ClickAllow.js +3 -3
- package/Touchable/Drag.js +6 -6
- package/Touchable/Flick.js +5 -5
- package/Touchable/Hold.js +5 -5
- package/Touchable/Pinch.js +6 -6
- package/Touchable/Touch.js +3 -3
- package/Touchable/Touchable.js +5 -5
- package/Touchable/config.js +4 -4
- package/Touchable/tests/Touchable-specs.js +1 -1
- package/Touchable/tests/useTouch-specs.js +5 -5
- package/Touchable/useTouch.js +7 -8
- package/Transition/Transition.js +14 -13
- package/Transition/tests/Transition-specs.js +9 -9
- package/ViewManager/Arranger.js +4 -4
- package/ViewManager/TransitionGroup.js +7 -7
- package/ViewManager/View.js +9 -9
- package/ViewManager/ViewManager.js +11 -10
- package/ViewManager/tests/ViewManager-specs.js +6 -6
- package/VirtualList/VirtualList.js +4 -4
- package/VirtualList/VirtualListBasic.js +67 -47
- package/VirtualList/tests/VirtualGridList-native-specs.js +5 -5
- package/VirtualList/tests/VirtualGridList-specs.js +16 -15
- package/VirtualList/tests/VirtualList-native-specs.js +164 -16
- package/VirtualList/tests/VirtualList-specs.js +16 -15
- package/internal/IdProvider/IdProvider.js +4 -4
- package/internal/IdProvider/Provider.js +3 -3
- package/internal/IdProvider/tests/IdProvider-specs.js +4 -4
- package/internal/IdProvider/tests/useId-specs.js +16 -8
- package/internal/Pure/Pure.js +9 -9
- package/internal/Pure/tests/Pure-specs.js +8 -8
- package/internal/localized-fonts/localized-fonts.js +3 -4
- package/package.json +6 -6
- package/resolution/ResolutionDecorator.js +71 -87
- package/resolution/index.js +2 -1
- package/resolution/tests/resolution-specs.js +7 -8
- package/useControlledState/tests/useControlledState-specs.js +3 -4
- package/useControlledState/useControlledState.js +3 -4
- package/useScroll/ScrollAnimator.js +3 -3
- package/useScroll/Scrollbar.js +5 -5
- package/useScroll/ScrollbarTrack.js +5 -5
- package/useScroll/scrollMotion.js +126 -0
- package/useScroll/tests/scrollMotion-specs.js +215 -0
- package/useScroll/tests/useScroll-specs.js +430 -9
- package/useScroll/useScroll.js +156 -92
|
@@ -0,0 +1,1358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _keymap = require("@enact/core/keymap");
|
|
4
|
+
require("@testing-library/jest-dom");
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
var _resolution = require("../../resolution");
|
|
7
|
+
var _index = require("../index.js");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _verticalMeasure = require("../verticalMeasure");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var _excluded = ["maxLines"],
|
|
12
|
+
_excluded2 = ["contentHeight", "lineHeight", "lineRects"];
|
|
13
|
+
/* global HTMLElement */
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
function _defineProperties(r, t) { for (var o = 0; o < t.length; o++) { var i = t[o]; i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(r, _toPropertyKey(i.key), i); } }
|
|
16
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
|
+
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; }
|
|
18
|
+
function _objectSpread(r) { for (var t = 1; t < arguments.length; t++) { var o = null != arguments[t] ? arguments[t] : {}; t % 2 ? ownKeys(Object(o), !0).forEach(function (t) { _defineProperty(r, t, o[t]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(o)) : ownKeys(Object(o)).forEach(function (e) { Object.defineProperty(r, e, Object.getOwnPropertyDescriptor(o, e)); }); } return r; }
|
|
19
|
+
function _defineProperty(r, t, o) { return (t = _toPropertyKey(t)) in r ? Object.defineProperty(r, t, { value: o, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = o, r; }
|
|
20
|
+
function _toPropertyKey(r) { var o = _toPrimitive(r, "string"); return "symbol" == typeof o ? o : o + ""; }
|
|
21
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
22
|
+
function _objectWithoutProperties(t, r) { if (null == t) return {}; var o, n, i = _objectWithoutPropertiesLoose(t, r); if (Object.getOwnPropertySymbols) { var l = Object.getOwnPropertySymbols(t); for (n = 0; n < l.length; n++) o = l[n], -1 === r.indexOf(o) && {}.propertyIsEnumerable.call(t, o) && (i[o] = t[o]); } return i; }
|
|
23
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
24
|
+
var VerticalMarqueeBase = (0, _index.MarqueeDecorator)({
|
|
25
|
+
orientation: 'vertical'
|
|
26
|
+
}, 'div');
|
|
27
|
+
var VerticalMarquee = function VerticalMarquee(_ref) {
|
|
28
|
+
var maxLines = _ref.maxLines,
|
|
29
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarqueeBase, _objectSpread(_objectSpread({}, props), {}, {
|
|
31
|
+
marqueeMaxLines: maxLines
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
var isScrolling = function isScrolling(view) {
|
|
35
|
+
var track = view.querySelector('[data-vertical-marquee-track]');
|
|
36
|
+
return Boolean(track && track.style.transform.startsWith('translateY(-'));
|
|
37
|
+
};
|
|
38
|
+
var marqueeNode = function marqueeNode(view) {
|
|
39
|
+
return view.querySelector('[data-vertical-marquee]');
|
|
40
|
+
};
|
|
41
|
+
var longText = 'A long piece of text that is measured as overflowing the visible line count.';
|
|
42
|
+
(0, _keymap.add)('pointerHide', 1537);
|
|
43
|
+
var rect = function rect(height) {
|
|
44
|
+
return {
|
|
45
|
+
bottom: height,
|
|
46
|
+
height: height,
|
|
47
|
+
left: 0,
|
|
48
|
+
right: 100,
|
|
49
|
+
top: 0,
|
|
50
|
+
width: 100,
|
|
51
|
+
x: 0,
|
|
52
|
+
y: 0,
|
|
53
|
+
toJSON: function toJSON() {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
var mockBox = function mockBox(metrics) {
|
|
59
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
60
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
61
|
+
var style = originalStyle(node);
|
|
62
|
+
return new Proxy(style, {
|
|
63
|
+
get: function get(target, prop, receiver) {
|
|
64
|
+
if (prop === 'lineHeight' || prop === 'fontSize') return "".concat(metrics.lineHeight, "px");
|
|
65
|
+
var value = Reflect.get(target, prop, receiver);
|
|
66
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
71
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? metrics.contentHeight : 0;
|
|
72
|
+
return rect(height);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var mockLineBoxes = function mockLineBoxes(lineRects) {
|
|
76
|
+
jest.spyOn(document, 'createRange').mockImplementation(function () {
|
|
77
|
+
return {
|
|
78
|
+
getClientRects: function getClientRects() {
|
|
79
|
+
return lineRects;
|
|
80
|
+
},
|
|
81
|
+
selectNodeContents: function selectNodeContents() {}
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
describe('VerticalMarquee Specs', function () {
|
|
86
|
+
test('should not become focusable on its own when marqueeOn is focus', function () {
|
|
87
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
88
|
+
"data-testid": "vertical-marquee",
|
|
89
|
+
children: "Text"
|
|
90
|
+
}));
|
|
91
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
92
|
+
expect(view).not.toHaveAttribute('tabindex');
|
|
93
|
+
});
|
|
94
|
+
test('should forward tabIndex from the parent', function () {
|
|
95
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
96
|
+
"data-testid": "vertical-marquee",
|
|
97
|
+
tabIndex: -1,
|
|
98
|
+
children: "Text"
|
|
99
|
+
}));
|
|
100
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
101
|
+
expect(view).toHaveAttribute('tabindex', '-1');
|
|
102
|
+
});
|
|
103
|
+
test('should mount children once and measure from a DOM clone', function () {
|
|
104
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
105
|
+
"data-testid": "vertical-marquee",
|
|
106
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
107
|
+
id: "marquee-child",
|
|
108
|
+
children: "Hello"
|
|
109
|
+
})
|
|
110
|
+
}));
|
|
111
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
112
|
+
var measurer = view.querySelector('[data-vertical-marquee-measurer]');
|
|
113
|
+
expect(view.querySelectorAll('#marquee-child')).toHaveLength(1);
|
|
114
|
+
expect(view.textContent).toBe('Hello');
|
|
115
|
+
expect(measurer.textContent).toBe('');
|
|
116
|
+
expect(measurer.querySelector('#marquee-child')).toBeNull();
|
|
117
|
+
});
|
|
118
|
+
test('should render its children', function () {
|
|
119
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
120
|
+
"data-testid": "vertical-marquee",
|
|
121
|
+
children: "Hello Vertical Marquee"
|
|
122
|
+
}));
|
|
123
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
124
|
+
expect(view.textContent).toBe('Hello Vertical Marquee');
|
|
125
|
+
expect(view.querySelector('[data-vertical-marquee]')).not.toBeNull();
|
|
126
|
+
});
|
|
127
|
+
test('should set the visible line count from maxLines', function () {
|
|
128
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
129
|
+
"data-testid": "vertical-marquee",
|
|
130
|
+
maxLines: 4,
|
|
131
|
+
children: "Lines"
|
|
132
|
+
}));
|
|
133
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
134
|
+
var expected = '4';
|
|
135
|
+
var actual = marqueeNode(view).style.getPropertyValue('--vertical-marquee-lines');
|
|
136
|
+
expect(actual).toBe(expected);
|
|
137
|
+
});
|
|
138
|
+
test('should render a plain block when marqueeDisabled is true', function () {
|
|
139
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
140
|
+
css: {
|
|
141
|
+
vertical: 'app-vertical'
|
|
142
|
+
},
|
|
143
|
+
"data-testid": "vertical-marquee",
|
|
144
|
+
marqueeDisabled: true,
|
|
145
|
+
children: "Plain text"
|
|
146
|
+
}));
|
|
147
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
148
|
+
expect(view).toHaveTextContent('Plain text');
|
|
149
|
+
expect(view.querySelector('[data-vertical-marquee-measurer]')).toBeNull();
|
|
150
|
+
expect(view.querySelector('[data-vertical-marquee-track]')).toBeNull();
|
|
151
|
+
expect(view).not.toHaveAttribute('css');
|
|
152
|
+
});
|
|
153
|
+
test('should fall back to one line when maxLines is not positive', function () {
|
|
154
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
155
|
+
"data-testid": "vertical-marquee",
|
|
156
|
+
maxLines: 0,
|
|
157
|
+
children: "Lines"
|
|
158
|
+
}));
|
|
159
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
160
|
+
expect(marqueeNode(view).style.getPropertyValue('--vertical-marquee-lines')).toBe('1');
|
|
161
|
+
});
|
|
162
|
+
test('should apply a custom class name', function () {
|
|
163
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
164
|
+
className: "custom",
|
|
165
|
+
"data-testid": "vertical-marquee",
|
|
166
|
+
children: "Text"
|
|
167
|
+
}));
|
|
168
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
169
|
+
expect(view).toHaveClass('custom');
|
|
170
|
+
});
|
|
171
|
+
describe('overflow measurement', function () {
|
|
172
|
+
beforeEach(function () {
|
|
173
|
+
global.ResizeObserver = /*#__PURE__*/function () {
|
|
174
|
+
function _class() {
|
|
175
|
+
_classCallCheck(this, _class);
|
|
176
|
+
}
|
|
177
|
+
return _createClass(_class, [{
|
|
178
|
+
key: "observe",
|
|
179
|
+
value: function observe() {}
|
|
180
|
+
}, {
|
|
181
|
+
key: "disconnect",
|
|
182
|
+
value: function disconnect() {}
|
|
183
|
+
}]);
|
|
184
|
+
}();
|
|
185
|
+
});
|
|
186
|
+
afterEach(function () {
|
|
187
|
+
delete global.ResizeObserver;
|
|
188
|
+
jest.useRealTimers();
|
|
189
|
+
jest.restoreAllMocks();
|
|
190
|
+
});
|
|
191
|
+
var setup = function setup(_ref2) {
|
|
192
|
+
var contentHeight = _ref2.contentHeight,
|
|
193
|
+
lineHeight = _ref2.lineHeight,
|
|
194
|
+
lineRects = _ref2.lineRects,
|
|
195
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
196
|
+
jest.useFakeTimers();
|
|
197
|
+
mockBox({
|
|
198
|
+
contentHeight: contentHeight,
|
|
199
|
+
lineHeight: lineHeight
|
|
200
|
+
});
|
|
201
|
+
if (lineRects) mockLineBoxes(lineRects);
|
|
202
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, _objectSpread(_objectSpread({
|
|
203
|
+
"data-testid": "vertical-marquee"
|
|
204
|
+
}, props), {}, {
|
|
205
|
+
children: longText
|
|
206
|
+
})));
|
|
207
|
+
return _react.screen.getByTestId('vertical-marquee');
|
|
208
|
+
};
|
|
209
|
+
test('should scroll one full cycle after focus when text overflows maxLines', function () {
|
|
210
|
+
var view = setup({
|
|
211
|
+
contentHeight: 300,
|
|
212
|
+
lineHeight: 30,
|
|
213
|
+
marqueeDelay: 1000,
|
|
214
|
+
marqueeSpacing: '0%',
|
|
215
|
+
marqueeSpeed: 30,
|
|
216
|
+
maxLines: 3
|
|
217
|
+
});
|
|
218
|
+
_react.fireEvent.focus(view);
|
|
219
|
+
(0, _react.act)(function () {
|
|
220
|
+
jest.advanceTimersByTime(1000);
|
|
221
|
+
});
|
|
222
|
+
var track = view.querySelector('[data-vertical-marquee-track]');
|
|
223
|
+
expect(isScrolling(view)).toBe(true);
|
|
224
|
+
expect(track.style.transform).toBe('translateY(-300px)');
|
|
225
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(2);
|
|
226
|
+
});
|
|
227
|
+
test('should pause after a cycle and then scroll again', function () {
|
|
228
|
+
var view = setup({
|
|
229
|
+
contentHeight: 300,
|
|
230
|
+
lineHeight: 30,
|
|
231
|
+
marqueeDelay: 1000,
|
|
232
|
+
marqueeResetDelay: 1000,
|
|
233
|
+
marqueeSpacing: '0%',
|
|
234
|
+
marqueeSpeed: 30,
|
|
235
|
+
maxLines: 3
|
|
236
|
+
});
|
|
237
|
+
var track = function track() {
|
|
238
|
+
return view.querySelector('[data-vertical-marquee-track]');
|
|
239
|
+
};
|
|
240
|
+
_react.fireEvent.focus(view);
|
|
241
|
+
(0, _react.act)(function () {
|
|
242
|
+
jest.advanceTimersByTime(1000);
|
|
243
|
+
});
|
|
244
|
+
_react.fireEvent.transitionEnd(track());
|
|
245
|
+
expect(isScrolling(view)).toBe(false);
|
|
246
|
+
expect(track().style.transform).toBe('translateY(0)');
|
|
247
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(2);
|
|
248
|
+
(0, _react.act)(function () {
|
|
249
|
+
jest.advanceTimersByTime(2000);
|
|
250
|
+
});
|
|
251
|
+
expect(isScrolling(view)).toBe(true);
|
|
252
|
+
expect(track().style.transform).toBe('translateY(-300px)');
|
|
253
|
+
});
|
|
254
|
+
test('should stop scrolling when focus leaves', function () {
|
|
255
|
+
var view = setup({
|
|
256
|
+
contentHeight: 300,
|
|
257
|
+
lineHeight: 30,
|
|
258
|
+
marqueeDelay: 0,
|
|
259
|
+
marqueeSpacing: '0%',
|
|
260
|
+
maxLines: 3
|
|
261
|
+
});
|
|
262
|
+
_react.fireEvent.focus(view);
|
|
263
|
+
(0, _react.act)(function () {
|
|
264
|
+
jest.advanceTimersByTime(0);
|
|
265
|
+
});
|
|
266
|
+
_react.fireEvent.blur(view);
|
|
267
|
+
expect(isScrolling(view)).toBe(false);
|
|
268
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(1);
|
|
269
|
+
});
|
|
270
|
+
test('should not scroll when the text fits in maxLines', function () {
|
|
271
|
+
var view = setup({
|
|
272
|
+
contentHeight: 20,
|
|
273
|
+
lineHeight: 30,
|
|
274
|
+
marqueeDelay: 0,
|
|
275
|
+
maxLines: 3
|
|
276
|
+
});
|
|
277
|
+
_react.fireEvent.focus(view);
|
|
278
|
+
(0, _react.act)(function () {
|
|
279
|
+
jest.advanceTimersByTime(1000);
|
|
280
|
+
});
|
|
281
|
+
expect(isScrolling(view)).toBe(false);
|
|
282
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(1);
|
|
283
|
+
});
|
|
284
|
+
test('should measure clip height from line boxes', function () {
|
|
285
|
+
var view = setup({
|
|
286
|
+
contentHeight: 10,
|
|
287
|
+
lineHeight: 30,
|
|
288
|
+
lineRects: [{
|
|
289
|
+
bottom: 0,
|
|
290
|
+
height: 0,
|
|
291
|
+
left: 0,
|
|
292
|
+
right: 0,
|
|
293
|
+
top: 0,
|
|
294
|
+
width: 0
|
|
295
|
+
}, {
|
|
296
|
+
bottom: 30,
|
|
297
|
+
height: 30,
|
|
298
|
+
left: 0,
|
|
299
|
+
right: 100,
|
|
300
|
+
top: 0,
|
|
301
|
+
width: 100
|
|
302
|
+
}, {
|
|
303
|
+
bottom: 40,
|
|
304
|
+
height: 40,
|
|
305
|
+
left: 0,
|
|
306
|
+
right: 20,
|
|
307
|
+
top: 0,
|
|
308
|
+
width: 20
|
|
309
|
+
}, {
|
|
310
|
+
bottom: 60,
|
|
311
|
+
height: 30,
|
|
312
|
+
left: 0,
|
|
313
|
+
right: 100,
|
|
314
|
+
top: 30,
|
|
315
|
+
width: 100
|
|
316
|
+
}, {
|
|
317
|
+
bottom: 90,
|
|
318
|
+
height: 30,
|
|
319
|
+
left: 0,
|
|
320
|
+
right: 100,
|
|
321
|
+
top: 60,
|
|
322
|
+
width: 100
|
|
323
|
+
}, {
|
|
324
|
+
bottom: 120,
|
|
325
|
+
height: 30,
|
|
326
|
+
left: 0,
|
|
327
|
+
right: 100,
|
|
328
|
+
top: 90,
|
|
329
|
+
width: 100
|
|
330
|
+
}],
|
|
331
|
+
marqueeDelay: 0,
|
|
332
|
+
marqueeSpacing: '0%',
|
|
333
|
+
marqueeSpeed: 30,
|
|
334
|
+
maxLines: 3
|
|
335
|
+
});
|
|
336
|
+
_react.fireEvent.focus(view);
|
|
337
|
+
(0, _react.act)(function () {
|
|
338
|
+
jest.advanceTimersByTime(0);
|
|
339
|
+
});
|
|
340
|
+
var track = view.querySelector('[data-vertical-marquee-track]');
|
|
341
|
+
expect(marqueeNode(view).style.maxHeight).toBe('90px');
|
|
342
|
+
expect(track.style.transform).toBe('translateY(-10px)');
|
|
343
|
+
});
|
|
344
|
+
test('should scroll the block height when it is taller than the glyph boxes', function () {
|
|
345
|
+
var view = setup({
|
|
346
|
+
contentHeight: 200,
|
|
347
|
+
lineHeight: 30,
|
|
348
|
+
lineRects: [{
|
|
349
|
+
bottom: 30,
|
|
350
|
+
height: 30,
|
|
351
|
+
left: 0,
|
|
352
|
+
right: 100,
|
|
353
|
+
top: 0,
|
|
354
|
+
width: 100
|
|
355
|
+
}, {
|
|
356
|
+
bottom: 60,
|
|
357
|
+
height: 30,
|
|
358
|
+
left: 0,
|
|
359
|
+
right: 100,
|
|
360
|
+
top: 30,
|
|
361
|
+
width: 100
|
|
362
|
+
}, {
|
|
363
|
+
bottom: 90,
|
|
364
|
+
height: 30,
|
|
365
|
+
left: 0,
|
|
366
|
+
right: 100,
|
|
367
|
+
top: 60,
|
|
368
|
+
width: 100
|
|
369
|
+
}, {
|
|
370
|
+
bottom: 120,
|
|
371
|
+
height: 30,
|
|
372
|
+
left: 0,
|
|
373
|
+
right: 100,
|
|
374
|
+
top: 90,
|
|
375
|
+
width: 100
|
|
376
|
+
}],
|
|
377
|
+
marqueeDelay: 0,
|
|
378
|
+
marqueeSpacing: '0%',
|
|
379
|
+
marqueeSpeed: 30,
|
|
380
|
+
maxLines: 3
|
|
381
|
+
});
|
|
382
|
+
_react.fireEvent.focus(view);
|
|
383
|
+
(0, _react.act)(function () {
|
|
384
|
+
jest.advanceTimersByTime(0);
|
|
385
|
+
});
|
|
386
|
+
expect(marqueeNode(view).style.maxHeight).toBe('90px');
|
|
387
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-200px)');
|
|
388
|
+
});
|
|
389
|
+
test('should scroll the block height when the glyph boxes overhang it', function () {
|
|
390
|
+
var view = setup({
|
|
391
|
+
contentHeight: 100,
|
|
392
|
+
lineHeight: 25,
|
|
393
|
+
lineRects: [{
|
|
394
|
+
bottom: 30,
|
|
395
|
+
height: 30,
|
|
396
|
+
left: 0,
|
|
397
|
+
right: 100,
|
|
398
|
+
top: 0,
|
|
399
|
+
width: 100
|
|
400
|
+
}, {
|
|
401
|
+
bottom: 55,
|
|
402
|
+
height: 30,
|
|
403
|
+
left: 0,
|
|
404
|
+
right: 100,
|
|
405
|
+
top: 25,
|
|
406
|
+
width: 100
|
|
407
|
+
}, {
|
|
408
|
+
bottom: 80,
|
|
409
|
+
height: 30,
|
|
410
|
+
left: 0,
|
|
411
|
+
right: 100,
|
|
412
|
+
top: 50,
|
|
413
|
+
width: 100
|
|
414
|
+
}, {
|
|
415
|
+
bottom: 105,
|
|
416
|
+
height: 30,
|
|
417
|
+
left: 0,
|
|
418
|
+
right: 100,
|
|
419
|
+
top: 75,
|
|
420
|
+
width: 100
|
|
421
|
+
}],
|
|
422
|
+
marqueeDelay: 0,
|
|
423
|
+
marqueeSpacing: '0%',
|
|
424
|
+
marqueeSpeed: 30,
|
|
425
|
+
maxLines: 3
|
|
426
|
+
});
|
|
427
|
+
_react.fireEvent.focus(view);
|
|
428
|
+
(0, _react.act)(function () {
|
|
429
|
+
jest.advanceTimersByTime(0);
|
|
430
|
+
});
|
|
431
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-100px)');
|
|
432
|
+
});
|
|
433
|
+
test('should size the clip from line tops so the last visible line is not cut off', function () {
|
|
434
|
+
var view = setup({
|
|
435
|
+
contentHeight: 200,
|
|
436
|
+
lineHeight: 30,
|
|
437
|
+
lineRects: [{
|
|
438
|
+
bottom: 20,
|
|
439
|
+
height: 20,
|
|
440
|
+
left: 0,
|
|
441
|
+
right: 100,
|
|
442
|
+
top: 0,
|
|
443
|
+
width: 100
|
|
444
|
+
}, {
|
|
445
|
+
bottom: 50,
|
|
446
|
+
height: 20,
|
|
447
|
+
left: 0,
|
|
448
|
+
right: 100,
|
|
449
|
+
top: 30,
|
|
450
|
+
width: 100
|
|
451
|
+
}, {
|
|
452
|
+
bottom: 80,
|
|
453
|
+
height: 20,
|
|
454
|
+
left: 0,
|
|
455
|
+
right: 100,
|
|
456
|
+
top: 60,
|
|
457
|
+
width: 100
|
|
458
|
+
}, {
|
|
459
|
+
bottom: 110,
|
|
460
|
+
height: 20,
|
|
461
|
+
left: 0,
|
|
462
|
+
right: 100,
|
|
463
|
+
top: 90,
|
|
464
|
+
width: 100
|
|
465
|
+
}],
|
|
466
|
+
marqueeDelay: 0,
|
|
467
|
+
marqueeSpacing: '0%',
|
|
468
|
+
marqueeSpeed: 30,
|
|
469
|
+
maxLines: 3
|
|
470
|
+
});
|
|
471
|
+
_react.fireEvent.focus(view);
|
|
472
|
+
(0, _react.act)(function () {
|
|
473
|
+
jest.advanceTimersByTime(0);
|
|
474
|
+
});
|
|
475
|
+
expect(marqueeNode(view).style.maxHeight).toBe('90px');
|
|
476
|
+
});
|
|
477
|
+
test('should not scroll line boxes that fit in maxLines', function () {
|
|
478
|
+
var view = setup({
|
|
479
|
+
contentHeight: 300,
|
|
480
|
+
lineHeight: 30,
|
|
481
|
+
lineRects: [{
|
|
482
|
+
bottom: 30,
|
|
483
|
+
height: 30,
|
|
484
|
+
left: 0,
|
|
485
|
+
right: 100,
|
|
486
|
+
top: 0,
|
|
487
|
+
width: 100
|
|
488
|
+
}, {
|
|
489
|
+
bottom: 60,
|
|
490
|
+
height: 30,
|
|
491
|
+
left: 0,
|
|
492
|
+
right: 100,
|
|
493
|
+
top: 30,
|
|
494
|
+
width: 100
|
|
495
|
+
}],
|
|
496
|
+
marqueeDelay: 0,
|
|
497
|
+
marqueeSpacing: '0%',
|
|
498
|
+
maxLines: 3
|
|
499
|
+
});
|
|
500
|
+
_react.fireEvent.focus(view);
|
|
501
|
+
(0, _react.act)(function () {
|
|
502
|
+
jest.advanceTimersByTime(0);
|
|
503
|
+
});
|
|
504
|
+
expect(isScrolling(view)).toBe(false);
|
|
505
|
+
expect(marqueeNode(view).style.maxHeight).toBe('300px');
|
|
506
|
+
});
|
|
507
|
+
test('should use font size when line-height is not a length', function () {
|
|
508
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
509
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
510
|
+
var style = originalStyle(node);
|
|
511
|
+
return new Proxy(style, {
|
|
512
|
+
get: function get(target, prop, receiver) {
|
|
513
|
+
if (prop === 'lineHeight') return 'normal';
|
|
514
|
+
if (prop === 'fontSize') return '30px';
|
|
515
|
+
var value = Reflect.get(target, prop, receiver);
|
|
516
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
jest.useFakeTimers();
|
|
521
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
522
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? 100 : 0;
|
|
523
|
+
return rect(height);
|
|
524
|
+
});
|
|
525
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
526
|
+
"data-testid": "vertical-marquee",
|
|
527
|
+
marqueeDelay: 0,
|
|
528
|
+
marqueeSpacing: "0%",
|
|
529
|
+
marqueeSpeed: 30,
|
|
530
|
+
maxLines: 1,
|
|
531
|
+
children: longText
|
|
532
|
+
}));
|
|
533
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
534
|
+
_react.fireEvent.focus(view);
|
|
535
|
+
(0, _react.act)(function () {
|
|
536
|
+
jest.advanceTimersByTime(0);
|
|
537
|
+
});
|
|
538
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-100px)');
|
|
539
|
+
});
|
|
540
|
+
test('should scale numeric spacing', function () {
|
|
541
|
+
var view = setup({
|
|
542
|
+
contentHeight: 300,
|
|
543
|
+
lineHeight: 30,
|
|
544
|
+
marqueeDelay: 0,
|
|
545
|
+
marqueeSpacing: 48,
|
|
546
|
+
maxLines: 3
|
|
547
|
+
});
|
|
548
|
+
_react.fireEvent.focus(view);
|
|
549
|
+
(0, _react.act)(function () {
|
|
550
|
+
jest.advanceTimersByTime(0);
|
|
551
|
+
});
|
|
552
|
+
expect(marqueeNode(view).style.getPropertyValue('--vertical-marquee-spacing')).toBe(String((0, _resolution.scale)(48)));
|
|
553
|
+
});
|
|
554
|
+
test('should ignore a spacing value that is not a number or percentage', function () {
|
|
555
|
+
var view = setup({
|
|
556
|
+
contentHeight: 300,
|
|
557
|
+
lineHeight: 30,
|
|
558
|
+
marqueeDelay: 0,
|
|
559
|
+
marqueeSpacing: 'wide',
|
|
560
|
+
maxLines: 3
|
|
561
|
+
});
|
|
562
|
+
_react.fireEvent.focus(view);
|
|
563
|
+
(0, _react.act)(function () {
|
|
564
|
+
jest.advanceTimersByTime(0);
|
|
565
|
+
});
|
|
566
|
+
expect(marqueeNode(view).style.getPropertyValue('--vertical-marquee-spacing')).toBe('0');
|
|
567
|
+
});
|
|
568
|
+
test('should not scroll when the user prefers reduced motion', function () {
|
|
569
|
+
var originalMatchMedia = window.matchMedia;
|
|
570
|
+
window.matchMedia = function () {
|
|
571
|
+
return {
|
|
572
|
+
matches: true
|
|
573
|
+
};
|
|
574
|
+
};
|
|
575
|
+
var view = setup({
|
|
576
|
+
contentHeight: 300,
|
|
577
|
+
lineHeight: 30,
|
|
578
|
+
marqueeDelay: 0,
|
|
579
|
+
marqueeSpacing: '0%',
|
|
580
|
+
maxLines: 3
|
|
581
|
+
});
|
|
582
|
+
_react.fireEvent.focus(view);
|
|
583
|
+
(0, _react.act)(function () {
|
|
584
|
+
jest.advanceTimersByTime(1000);
|
|
585
|
+
});
|
|
586
|
+
expect(isScrolling(view)).toBe(false);
|
|
587
|
+
window.matchMedia = originalMatchMedia;
|
|
588
|
+
});
|
|
589
|
+
test('should scroll on hover and stop on pointer hide', function () {
|
|
590
|
+
var onMouseEnter = jest.fn();
|
|
591
|
+
var onMouseLeave = jest.fn();
|
|
592
|
+
var view = setup({
|
|
593
|
+
contentHeight: 300,
|
|
594
|
+
lineHeight: 30,
|
|
595
|
+
marqueeDelay: 0,
|
|
596
|
+
marqueeOn: 'hover',
|
|
597
|
+
marqueeSpacing: '0%',
|
|
598
|
+
marqueeSpeed: 30,
|
|
599
|
+
maxLines: 3,
|
|
600
|
+
onMouseEnter: onMouseEnter,
|
|
601
|
+
onMouseLeave: onMouseLeave
|
|
602
|
+
});
|
|
603
|
+
_react.fireEvent.focus(view);
|
|
604
|
+
_react.fireEvent.mouseEnter(view);
|
|
605
|
+
(0, _react.act)(function () {
|
|
606
|
+
jest.advanceTimersByTime(0);
|
|
607
|
+
});
|
|
608
|
+
expect(onMouseEnter).toHaveBeenCalled();
|
|
609
|
+
expect(isScrolling(view)).toBe(true);
|
|
610
|
+
_react.fireEvent.keyDown(document, {
|
|
611
|
+
keyCode: 1
|
|
612
|
+
});
|
|
613
|
+
expect(isScrolling(view)).toBe(true);
|
|
614
|
+
_react.fireEvent.keyDown(document, {
|
|
615
|
+
keyCode: 1537
|
|
616
|
+
});
|
|
617
|
+
expect(isScrolling(view)).toBe(false);
|
|
618
|
+
_react.fireEvent.mouseEnter(view);
|
|
619
|
+
(0, _react.act)(function () {
|
|
620
|
+
jest.advanceTimersByTime(0);
|
|
621
|
+
});
|
|
622
|
+
_react.fireEvent.mouseLeave(view);
|
|
623
|
+
expect(onMouseLeave).toHaveBeenCalled();
|
|
624
|
+
expect(isScrolling(view)).toBe(false);
|
|
625
|
+
});
|
|
626
|
+
test('should start a disabled focus marquee on focus and stop it on blur', function () {
|
|
627
|
+
var onFocus = jest.fn();
|
|
628
|
+
var onBlur = jest.fn();
|
|
629
|
+
var view = setup({
|
|
630
|
+
contentHeight: 300,
|
|
631
|
+
disabled: true,
|
|
632
|
+
lineHeight: 30,
|
|
633
|
+
marqueeDelay: 0,
|
|
634
|
+
marqueeOn: 'focus',
|
|
635
|
+
marqueeSpacing: '0%',
|
|
636
|
+
marqueeSpeed: 30,
|
|
637
|
+
maxLines: 3,
|
|
638
|
+
onBlur: onBlur,
|
|
639
|
+
onFocus: onFocus
|
|
640
|
+
});
|
|
641
|
+
_react.fireEvent.mouseEnter(view);
|
|
642
|
+
(0, _react.act)(function () {
|
|
643
|
+
jest.advanceTimersByTime(0);
|
|
644
|
+
});
|
|
645
|
+
expect(isScrolling(view)).toBe(false);
|
|
646
|
+
_react.fireEvent.focus(view);
|
|
647
|
+
(0, _react.act)(function () {
|
|
648
|
+
jest.advanceTimersByTime(0);
|
|
649
|
+
});
|
|
650
|
+
expect(onFocus).toHaveBeenCalled();
|
|
651
|
+
expect(isScrolling(view)).toBe(true);
|
|
652
|
+
_react.fireEvent.blur(view);
|
|
653
|
+
expect(onBlur).toHaveBeenCalled();
|
|
654
|
+
expect(isScrolling(view)).toBe(false);
|
|
655
|
+
});
|
|
656
|
+
test('should start when marqueeOn is render and stop on unmount', function () {
|
|
657
|
+
jest.useFakeTimers();
|
|
658
|
+
mockBox({
|
|
659
|
+
contentHeight: 300,
|
|
660
|
+
lineHeight: 30
|
|
661
|
+
});
|
|
662
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
663
|
+
"data-testid": "vertical-marquee",
|
|
664
|
+
marqueeOn: "render",
|
|
665
|
+
marqueeOnRenderDelay: 500,
|
|
666
|
+
marqueeSpacing: "0%",
|
|
667
|
+
marqueeSpeed: 30,
|
|
668
|
+
maxLines: 3,
|
|
669
|
+
children: longText
|
|
670
|
+
})),
|
|
671
|
+
unmount = _render.unmount;
|
|
672
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
673
|
+
(0, _react.act)(function () {
|
|
674
|
+
jest.advanceTimersByTime(500);
|
|
675
|
+
});
|
|
676
|
+
expect(isScrolling(view)).toBe(true);
|
|
677
|
+
unmount();
|
|
678
|
+
});
|
|
679
|
+
test('should ignore a second focus and a mouse leave that does not control the marquee', function () {
|
|
680
|
+
var view = setup({
|
|
681
|
+
contentHeight: 300,
|
|
682
|
+
lineHeight: 30,
|
|
683
|
+
marqueeDelay: 0,
|
|
684
|
+
marqueeSpacing: '0%',
|
|
685
|
+
marqueeSpeed: 30,
|
|
686
|
+
maxLines: 3
|
|
687
|
+
});
|
|
688
|
+
_react.fireEvent.focus(view);
|
|
689
|
+
(0, _react.act)(function () {
|
|
690
|
+
jest.advanceTimersByTime(0);
|
|
691
|
+
});
|
|
692
|
+
_react.fireEvent.focus(view);
|
|
693
|
+
_react.fireEvent.mouseLeave(view);
|
|
694
|
+
_react.fireEvent.keyDown(document, {
|
|
695
|
+
keyCode: 1537
|
|
696
|
+
});
|
|
697
|
+
expect(isScrolling(view)).toBe(true);
|
|
698
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
699
|
+
});
|
|
700
|
+
test('should ignore a second hover while a hover session is running', function () {
|
|
701
|
+
var view = setup({
|
|
702
|
+
contentHeight: 300,
|
|
703
|
+
lineHeight: 30,
|
|
704
|
+
marqueeDelay: 0,
|
|
705
|
+
marqueeOn: 'hover',
|
|
706
|
+
marqueeSpacing: '0%',
|
|
707
|
+
marqueeSpeed: 30,
|
|
708
|
+
maxLines: 3
|
|
709
|
+
});
|
|
710
|
+
_react.fireEvent.mouseEnter(view);
|
|
711
|
+
(0, _react.act)(function () {
|
|
712
|
+
jest.advanceTimersByTime(0);
|
|
713
|
+
});
|
|
714
|
+
_react.fireEvent.mouseEnter(view);
|
|
715
|
+
expect(isScrolling(view)).toBe(true);
|
|
716
|
+
});
|
|
717
|
+
test('should fall back when the document cannot create a range', function () {
|
|
718
|
+
var originalCreateRange = document.createRange;
|
|
719
|
+
document.createRange = null;
|
|
720
|
+
var view = setup({
|
|
721
|
+
contentHeight: 300,
|
|
722
|
+
lineHeight: 30,
|
|
723
|
+
marqueeDelay: 0,
|
|
724
|
+
marqueeSpacing: '0%',
|
|
725
|
+
marqueeSpeed: 30,
|
|
726
|
+
maxLines: 3
|
|
727
|
+
});
|
|
728
|
+
document.createRange = originalCreateRange;
|
|
729
|
+
_react.fireEvent.focus(view);
|
|
730
|
+
(0, _react.act)(function () {
|
|
731
|
+
jest.advanceTimersByTime(0);
|
|
732
|
+
});
|
|
733
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
734
|
+
});
|
|
735
|
+
test('should ignore transitionend that is not the running transform', function () {
|
|
736
|
+
var view = setup({
|
|
737
|
+
contentHeight: 300,
|
|
738
|
+
lineHeight: 30,
|
|
739
|
+
marqueeDelay: 0,
|
|
740
|
+
marqueeSpacing: '0%',
|
|
741
|
+
marqueeSpeed: 30,
|
|
742
|
+
maxLines: 3
|
|
743
|
+
});
|
|
744
|
+
var track = function track() {
|
|
745
|
+
return view.querySelector('[data-vertical-marquee-track]');
|
|
746
|
+
};
|
|
747
|
+
_react.fireEvent.transitionEnd(track());
|
|
748
|
+
_react.fireEvent.focus(view);
|
|
749
|
+
(0, _react.act)(function () {
|
|
750
|
+
jest.advanceTimersByTime(0);
|
|
751
|
+
});
|
|
752
|
+
view.querySelector('[data-vertical-marquee-content]').dispatchEvent(new Event('transitionend', {
|
|
753
|
+
bubbles: true
|
|
754
|
+
}));
|
|
755
|
+
var ignored = new Event('transitionend', {
|
|
756
|
+
bubbles: true
|
|
757
|
+
});
|
|
758
|
+
Object.defineProperty(ignored, 'propertyName', {
|
|
759
|
+
value: 'opacity'
|
|
760
|
+
});
|
|
761
|
+
track().dispatchEvent(ignored);
|
|
762
|
+
expect(isScrolling(view)).toBe(true);
|
|
763
|
+
expect(track().style.transform).toBe('translateY(-300px)');
|
|
764
|
+
});
|
|
765
|
+
test('should restart with the new distance when children change during a scroll', function () {
|
|
766
|
+
jest.useFakeTimers();
|
|
767
|
+
var contentHeight = 300;
|
|
768
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
769
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
770
|
+
var style = originalStyle(node);
|
|
771
|
+
return new Proxy(style, {
|
|
772
|
+
get: function get(target, prop, receiver) {
|
|
773
|
+
if (prop === 'lineHeight' || prop === 'fontSize') return '30px';
|
|
774
|
+
var value = Reflect.get(target, prop, receiver);
|
|
775
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
780
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? contentHeight : 0;
|
|
781
|
+
return rect(height);
|
|
782
|
+
});
|
|
783
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
784
|
+
"data-testid": "vertical-marquee",
|
|
785
|
+
marqueeDelay: 0,
|
|
786
|
+
marqueeSpacing: "0%",
|
|
787
|
+
marqueeSpeed: 30,
|
|
788
|
+
maxLines: 3,
|
|
789
|
+
children: longText
|
|
790
|
+
})),
|
|
791
|
+
rerender = _render2.rerender;
|
|
792
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
793
|
+
var track = function track() {
|
|
794
|
+
return view.querySelector('[data-vertical-marquee-track]');
|
|
795
|
+
};
|
|
796
|
+
_react.fireEvent.focus(view);
|
|
797
|
+
(0, _react.act)(function () {
|
|
798
|
+
jest.advanceTimersByTime(0);
|
|
799
|
+
});
|
|
800
|
+
contentHeight = 500;
|
|
801
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsxs)(VerticalMarquee, {
|
|
802
|
+
"data-testid": "vertical-marquee",
|
|
803
|
+
marqueeDelay: 0,
|
|
804
|
+
marqueeSpacing: "0%",
|
|
805
|
+
marqueeSpeed: 30,
|
|
806
|
+
maxLines: 3,
|
|
807
|
+
children: [longText, " more"]
|
|
808
|
+
}));
|
|
809
|
+
(0, _react.act)(function () {
|
|
810
|
+
jest.advanceTimersByTime(0);
|
|
811
|
+
});
|
|
812
|
+
expect(isScrolling(view)).toBe(true);
|
|
813
|
+
expect(track().style.transform).toBe('translateY(-500px)');
|
|
814
|
+
});
|
|
815
|
+
test('should start after a later measurement shows overflow', function () {
|
|
816
|
+
jest.useFakeTimers();
|
|
817
|
+
var contentHeight = 20;
|
|
818
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
819
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
820
|
+
var style = originalStyle(node);
|
|
821
|
+
return new Proxy(style, {
|
|
822
|
+
get: function get(target, prop, receiver) {
|
|
823
|
+
if (prop === 'lineHeight' || prop === 'fontSize') return '30px';
|
|
824
|
+
var value = Reflect.get(target, prop, receiver);
|
|
825
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
830
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? contentHeight : 0;
|
|
831
|
+
return rect(height);
|
|
832
|
+
});
|
|
833
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
834
|
+
"data-testid": "vertical-marquee",
|
|
835
|
+
marqueeDelay: 0,
|
|
836
|
+
marqueeSpacing: "0%",
|
|
837
|
+
marqueeSpeed: 30,
|
|
838
|
+
maxLines: 3,
|
|
839
|
+
children: longText
|
|
840
|
+
})),
|
|
841
|
+
rerender = _render3.rerender;
|
|
842
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
843
|
+
_react.fireEvent.focus(view);
|
|
844
|
+
(0, _react.act)(function () {
|
|
845
|
+
jest.advanceTimersByTime(0);
|
|
846
|
+
});
|
|
847
|
+
expect(isScrolling(view)).toBe(false);
|
|
848
|
+
contentHeight = 300;
|
|
849
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsxs)(VerticalMarquee, {
|
|
850
|
+
"data-testid": "vertical-marquee",
|
|
851
|
+
marqueeDelay: 0,
|
|
852
|
+
marqueeSpacing: "0%",
|
|
853
|
+
marqueeSpeed: 30,
|
|
854
|
+
maxLines: 3,
|
|
855
|
+
children: [longText, " more"]
|
|
856
|
+
}));
|
|
857
|
+
(0, _react.act)(function () {
|
|
858
|
+
jest.advanceTimersByTime(0);
|
|
859
|
+
});
|
|
860
|
+
expect(isScrolling(view)).toBe(true);
|
|
861
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
862
|
+
});
|
|
863
|
+
test('should scroll on a later focus when an earlier measurement fit', function () {
|
|
864
|
+
jest.useFakeTimers();
|
|
865
|
+
var contentHeight = 20;
|
|
866
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
867
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
868
|
+
var style = originalStyle(node);
|
|
869
|
+
return new Proxy(style, {
|
|
870
|
+
get: function get(target, prop, receiver) {
|
|
871
|
+
if (prop === 'lineHeight' || prop === 'fontSize') return '30px';
|
|
872
|
+
var value = Reflect.get(target, prop, receiver);
|
|
873
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
878
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? contentHeight : 0;
|
|
879
|
+
return rect(height);
|
|
880
|
+
});
|
|
881
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
882
|
+
"data-testid": "vertical-marquee",
|
|
883
|
+
marqueeDelay: 0,
|
|
884
|
+
marqueeSpacing: "0%",
|
|
885
|
+
marqueeSpeed: 30,
|
|
886
|
+
maxLines: 3,
|
|
887
|
+
children: longText
|
|
888
|
+
}));
|
|
889
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
890
|
+
_react.fireEvent.focus(view);
|
|
891
|
+
(0, _react.act)(function () {
|
|
892
|
+
jest.advanceTimersByTime(0);
|
|
893
|
+
});
|
|
894
|
+
expect(isScrolling(view)).toBe(false);
|
|
895
|
+
contentHeight = 300;
|
|
896
|
+
_react.fireEvent.blur(view);
|
|
897
|
+
_react.fireEvent.focus(view);
|
|
898
|
+
(0, _react.act)(function () {
|
|
899
|
+
jest.advanceTimersByTime(0);
|
|
900
|
+
});
|
|
901
|
+
expect(isScrolling(view)).toBe(true);
|
|
902
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
903
|
+
});
|
|
904
|
+
test('should stop a running session when the text no longer overflows', function () {
|
|
905
|
+
jest.useFakeTimers();
|
|
906
|
+
var contentHeight = 300;
|
|
907
|
+
var originalStyle = window.getComputedStyle.bind(window);
|
|
908
|
+
jest.spyOn(window, 'getComputedStyle').mockImplementation(function (node) {
|
|
909
|
+
var style = originalStyle(node);
|
|
910
|
+
return new Proxy(style, {
|
|
911
|
+
get: function get(target, prop, receiver) {
|
|
912
|
+
if (prop === 'lineHeight' || prop === 'fontSize') return '30px';
|
|
913
|
+
var value = Reflect.get(target, prop, receiver);
|
|
914
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
919
|
+
var height = this.hasAttribute('data-vertical-marquee-measurer') ? contentHeight : 0;
|
|
920
|
+
return rect(height);
|
|
921
|
+
});
|
|
922
|
+
var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
923
|
+
"data-testid": "vertical-marquee",
|
|
924
|
+
marqueeDelay: 1000,
|
|
925
|
+
marqueeSpacing: "0%",
|
|
926
|
+
marqueeSpeed: 0,
|
|
927
|
+
maxLines: 3,
|
|
928
|
+
children: longText
|
|
929
|
+
})),
|
|
930
|
+
rerender = _render4.rerender;
|
|
931
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
932
|
+
_react.fireEvent.focus(view);
|
|
933
|
+
contentHeight = 20;
|
|
934
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsxs)(VerticalMarquee, {
|
|
935
|
+
"data-testid": "vertical-marquee",
|
|
936
|
+
marqueeDelay: 1000,
|
|
937
|
+
marqueeSpacing: "0%",
|
|
938
|
+
marqueeSpeed: 0,
|
|
939
|
+
maxLines: 3,
|
|
940
|
+
children: [longText, " short"]
|
|
941
|
+
}));
|
|
942
|
+
expect(isScrolling(view)).toBe(false);
|
|
943
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(1);
|
|
944
|
+
});
|
|
945
|
+
test('should forward focus handlers while disabled and not resume a scroll', function () {
|
|
946
|
+
jest.useFakeTimers();
|
|
947
|
+
mockBox({
|
|
948
|
+
contentHeight: 300,
|
|
949
|
+
lineHeight: 30
|
|
950
|
+
});
|
|
951
|
+
var onBlur = jest.fn();
|
|
952
|
+
var onFocus = jest.fn();
|
|
953
|
+
var props = {
|
|
954
|
+
'data-testid': 'vertical-marquee',
|
|
955
|
+
marqueeDelay: 1000,
|
|
956
|
+
marqueeSpacing: '0%',
|
|
957
|
+
marqueeSpeed: 30,
|
|
958
|
+
maxLines: 3,
|
|
959
|
+
onBlur: onBlur,
|
|
960
|
+
onFocus: onFocus
|
|
961
|
+
};
|
|
962
|
+
var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, _objectSpread(_objectSpread({}, props), {}, {
|
|
963
|
+
children: longText
|
|
964
|
+
}))),
|
|
965
|
+
rerender = _render5.rerender;
|
|
966
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
967
|
+
_react.fireEvent.focus(view);
|
|
968
|
+
(0, _react.act)(function () {
|
|
969
|
+
jest.advanceTimersByTime(0);
|
|
970
|
+
});
|
|
971
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, _objectSpread(_objectSpread({}, props), {}, {
|
|
972
|
+
marqueeDisabled: true,
|
|
973
|
+
children: longText
|
|
974
|
+
})));
|
|
975
|
+
_react.fireEvent.focus(view);
|
|
976
|
+
_react.fireEvent.blur(view);
|
|
977
|
+
expect(onFocus).toHaveBeenCalledTimes(2);
|
|
978
|
+
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
979
|
+
expect(view.querySelector('[data-vertical-marquee-track]')).toBeNull();
|
|
980
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, _objectSpread(_objectSpread({}, props), {}, {
|
|
981
|
+
children: longText
|
|
982
|
+
})));
|
|
983
|
+
(0, _react.act)(function () {
|
|
984
|
+
jest.advanceTimersByTime(5000);
|
|
985
|
+
});
|
|
986
|
+
expect(isScrolling(view)).toBe(false);
|
|
987
|
+
expect(view.querySelectorAll('[data-vertical-marquee-content]')).toHaveLength(1);
|
|
988
|
+
});
|
|
989
|
+
test('should not scroll when speed is not positive', function () {
|
|
990
|
+
var view = setup({
|
|
991
|
+
contentHeight: 300,
|
|
992
|
+
lineHeight: 30,
|
|
993
|
+
marqueeDelay: 0,
|
|
994
|
+
marqueeSpacing: '0%',
|
|
995
|
+
marqueeSpeed: 0,
|
|
996
|
+
maxLines: 3
|
|
997
|
+
});
|
|
998
|
+
_react.fireEvent.focus(view);
|
|
999
|
+
(0, _react.act)(function () {
|
|
1000
|
+
jest.advanceTimersByTime(1000);
|
|
1001
|
+
});
|
|
1002
|
+
expect(isScrolling(view)).toBe(false);
|
|
1003
|
+
});
|
|
1004
|
+
test('should remeasure when fonts finish loading and a session is idle', function () {
|
|
1005
|
+
var listeners = {};
|
|
1006
|
+
document.fonts = {
|
|
1007
|
+
addEventListener: function addEventListener(name, fn) {
|
|
1008
|
+
listeners[name] = fn;
|
|
1009
|
+
},
|
|
1010
|
+
removeEventListener: function removeEventListener(name) {
|
|
1011
|
+
delete listeners[name];
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
var view = setup({
|
|
1015
|
+
contentHeight: 20,
|
|
1016
|
+
lineHeight: 30,
|
|
1017
|
+
marqueeDelay: 0,
|
|
1018
|
+
marqueeSpacing: '0%',
|
|
1019
|
+
maxLines: 3
|
|
1020
|
+
});
|
|
1021
|
+
expect(typeof listeners.loadingdone).toBe('function');
|
|
1022
|
+
(0, _react.act)(function () {
|
|
1023
|
+
listeners.loadingdone();
|
|
1024
|
+
});
|
|
1025
|
+
expect(isScrolling(view)).toBe(false);
|
|
1026
|
+
delete document.fonts;
|
|
1027
|
+
});
|
|
1028
|
+
test('should keep the distance when fonts finish loading during a scroll', function () {
|
|
1029
|
+
var listeners = {};
|
|
1030
|
+
document.fonts = {
|
|
1031
|
+
addEventListener: function addEventListener(name, fn) {
|
|
1032
|
+
listeners[name] = fn;
|
|
1033
|
+
},
|
|
1034
|
+
removeEventListener: function removeEventListener() {}
|
|
1035
|
+
};
|
|
1036
|
+
var view = setup({
|
|
1037
|
+
contentHeight: 300,
|
|
1038
|
+
lineHeight: 30,
|
|
1039
|
+
marqueeDelay: 0,
|
|
1040
|
+
marqueeSpacing: '0%',
|
|
1041
|
+
marqueeSpeed: 30,
|
|
1042
|
+
maxLines: 3
|
|
1043
|
+
});
|
|
1044
|
+
_react.fireEvent.focus(view);
|
|
1045
|
+
(0, _react.act)(function () {
|
|
1046
|
+
jest.advanceTimersByTime(0);
|
|
1047
|
+
});
|
|
1048
|
+
(0, _react.act)(function () {
|
|
1049
|
+
listeners.loadingdone();
|
|
1050
|
+
});
|
|
1051
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
1052
|
+
delete document.fonts;
|
|
1053
|
+
});
|
|
1054
|
+
test('should remeasure on resize when idle and keep the distance while scrolling', function () {
|
|
1055
|
+
var onResize;
|
|
1056
|
+
global.ResizeObserver = /*#__PURE__*/function () {
|
|
1057
|
+
function _class2(callback) {
|
|
1058
|
+
_classCallCheck(this, _class2);
|
|
1059
|
+
onResize = callback;
|
|
1060
|
+
}
|
|
1061
|
+
return _createClass(_class2, [{
|
|
1062
|
+
key: "observe",
|
|
1063
|
+
value: function observe() {}
|
|
1064
|
+
}, {
|
|
1065
|
+
key: "disconnect",
|
|
1066
|
+
value: function disconnect() {}
|
|
1067
|
+
}]);
|
|
1068
|
+
}();
|
|
1069
|
+
var view = setup({
|
|
1070
|
+
contentHeight: 300,
|
|
1071
|
+
lineHeight: 30,
|
|
1072
|
+
marqueeDelay: 0,
|
|
1073
|
+
marqueeSpacing: '0%',
|
|
1074
|
+
marqueeSpeed: 30,
|
|
1075
|
+
maxLines: 3
|
|
1076
|
+
});
|
|
1077
|
+
(0, _react.act)(function () {
|
|
1078
|
+
onResize();
|
|
1079
|
+
});
|
|
1080
|
+
_react.fireEvent.focus(view);
|
|
1081
|
+
(0, _react.act)(function () {
|
|
1082
|
+
jest.advanceTimersByTime(0);
|
|
1083
|
+
});
|
|
1084
|
+
(0, _react.act)(function () {
|
|
1085
|
+
onResize();
|
|
1086
|
+
});
|
|
1087
|
+
expect(view.querySelector('[data-vertical-marquee-track]').style.transform).toBe('translateY(-300px)');
|
|
1088
|
+
});
|
|
1089
|
+
test('should remeasure when the text size changes and ignore a height-only resize', function () {
|
|
1090
|
+
var onResize;
|
|
1091
|
+
global.ResizeObserver = /*#__PURE__*/function () {
|
|
1092
|
+
function _class3(callback) {
|
|
1093
|
+
_classCallCheck(this, _class3);
|
|
1094
|
+
onResize = callback;
|
|
1095
|
+
}
|
|
1096
|
+
return _createClass(_class3, [{
|
|
1097
|
+
key: "observe",
|
|
1098
|
+
value: function observe() {}
|
|
1099
|
+
}, {
|
|
1100
|
+
key: "disconnect",
|
|
1101
|
+
value: function disconnect() {}
|
|
1102
|
+
}]);
|
|
1103
|
+
}();
|
|
1104
|
+
var metrics = {
|
|
1105
|
+
contentHeight: 300,
|
|
1106
|
+
lineHeight: 30
|
|
1107
|
+
};
|
|
1108
|
+
jest.useFakeTimers();
|
|
1109
|
+
mockBox(metrics);
|
|
1110
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
1111
|
+
"data-testid": "vertical-marquee",
|
|
1112
|
+
marqueeDelay: 0,
|
|
1113
|
+
marqueeResetDelay: 0,
|
|
1114
|
+
marqueeSpacing: "0%",
|
|
1115
|
+
marqueeSpeed: 30,
|
|
1116
|
+
maxLines: 3,
|
|
1117
|
+
children: longText
|
|
1118
|
+
}));
|
|
1119
|
+
var view = _react.screen.getByTestId('vertical-marquee');
|
|
1120
|
+
var track = function track() {
|
|
1121
|
+
return view.querySelector('[data-vertical-marquee-track]');
|
|
1122
|
+
};
|
|
1123
|
+
_react.fireEvent.focus(view);
|
|
1124
|
+
(0, _react.act)(function () {
|
|
1125
|
+
jest.advanceTimersByTime(0);
|
|
1126
|
+
});
|
|
1127
|
+
expect(track().style.transform).toBe('translateY(-300px)');
|
|
1128
|
+
metrics.contentHeight = 500;
|
|
1129
|
+
metrics.lineHeight = 50;
|
|
1130
|
+
(0, _react.act)(function () {
|
|
1131
|
+
onResize();
|
|
1132
|
+
});
|
|
1133
|
+
(0, _react.act)(function () {
|
|
1134
|
+
jest.advanceTimersByTime(40);
|
|
1135
|
+
});
|
|
1136
|
+
expect(track().style.transform).toBe('translateY(-500px)');
|
|
1137
|
+
metrics.contentHeight = 800;
|
|
1138
|
+
(0, _react.act)(function () {
|
|
1139
|
+
onResize();
|
|
1140
|
+
});
|
|
1141
|
+
(0, _react.act)(function () {
|
|
1142
|
+
jest.advanceTimersByTime(40);
|
|
1143
|
+
});
|
|
1144
|
+
expect(track().style.transform).toBe('translateY(-500px)');
|
|
1145
|
+
});
|
|
1146
|
+
test('should use a percentage of the clip as spacing', function () {
|
|
1147
|
+
var view = setup({
|
|
1148
|
+
contentHeight: 300,
|
|
1149
|
+
lineHeight: 30,
|
|
1150
|
+
marqueeDelay: 0,
|
|
1151
|
+
marqueeSpacing: '50%',
|
|
1152
|
+
maxLines: 3
|
|
1153
|
+
});
|
|
1154
|
+
_react.fireEvent.focus(view);
|
|
1155
|
+
(0, _react.act)(function () {
|
|
1156
|
+
jest.advanceTimersByTime(0);
|
|
1157
|
+
});
|
|
1158
|
+
expect(marqueeNode(view).style.getPropertyValue('--vertical-marquee-spacing')).not.toBe('0');
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
describe('mergeCss', function () {
|
|
1163
|
+
test('should keep whichever map is provided when the other is missing', function () {
|
|
1164
|
+
var configCss = {
|
|
1165
|
+
text: 'theme-text'
|
|
1166
|
+
};
|
|
1167
|
+
var instanceCss = {
|
|
1168
|
+
text: 'app-text'
|
|
1169
|
+
};
|
|
1170
|
+
expect((0, _utils.mergeCss)(null, null)).toBeNull();
|
|
1171
|
+
expect((0, _utils.mergeCss)(null, instanceCss)).toBe(instanceCss);
|
|
1172
|
+
expect((0, _utils.mergeCss)(configCss, null)).toBe(configCss);
|
|
1173
|
+
});
|
|
1174
|
+
test('should forward the css prop to the wrapped component', function () {
|
|
1175
|
+
var Host = function Host(_ref3) {
|
|
1176
|
+
var css = _ref3.css,
|
|
1177
|
+
children = _ref3.children;
|
|
1178
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
1179
|
+
"data-testid": "host",
|
|
1180
|
+
"data-button": css && css.button,
|
|
1181
|
+
children: children
|
|
1182
|
+
});
|
|
1183
|
+
};
|
|
1184
|
+
var Decorated = (0, _index.MarqueeDecorator)({
|
|
1185
|
+
component: _index.MarqueeBase,
|
|
1186
|
+
css: {
|
|
1187
|
+
text: 'theme-text'
|
|
1188
|
+
}
|
|
1189
|
+
}, Host);
|
|
1190
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Decorated, {
|
|
1191
|
+
css: {
|
|
1192
|
+
button: 'Dropdown_Dropdown_button',
|
|
1193
|
+
text: 'app-text'
|
|
1194
|
+
},
|
|
1195
|
+
children: "Label"
|
|
1196
|
+
}));
|
|
1197
|
+
expect(_react.screen.getByTestId('host')).toHaveAttribute('data-button', 'Dropdown_Dropdown_button');
|
|
1198
|
+
});
|
|
1199
|
+
test('should forward the css prop to the wrapped component when marqueeDisabled is true', function () {
|
|
1200
|
+
var Host = function Host(_ref4) {
|
|
1201
|
+
var css = _ref4.css,
|
|
1202
|
+
children = _ref4.children;
|
|
1203
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
1204
|
+
"data-testid": "host",
|
|
1205
|
+
"data-button": css && css.button,
|
|
1206
|
+
children: children
|
|
1207
|
+
});
|
|
1208
|
+
};
|
|
1209
|
+
var Decorated = (0, _index.MarqueeDecorator)({
|
|
1210
|
+
component: _index.MarqueeBase
|
|
1211
|
+
}, Host);
|
|
1212
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Decorated, {
|
|
1213
|
+
css: {
|
|
1214
|
+
button: 'Chip_button'
|
|
1215
|
+
},
|
|
1216
|
+
marqueeDisabled: true,
|
|
1217
|
+
children: "Label"
|
|
1218
|
+
}));
|
|
1219
|
+
expect(_react.screen.getByTestId('host')).toHaveAttribute('data-button', 'Chip_button');
|
|
1220
|
+
});
|
|
1221
|
+
test('should not set a css attribute when the marquee wraps a DOM element', function () {
|
|
1222
|
+
var css = {
|
|
1223
|
+
text: 'app-text'
|
|
1224
|
+
};
|
|
1225
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
1226
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Marquee, {
|
|
1227
|
+
css: css,
|
|
1228
|
+
"data-testid": "horizontal",
|
|
1229
|
+
children: "Label"
|
|
1230
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(VerticalMarquee, {
|
|
1231
|
+
css: css,
|
|
1232
|
+
"data-testid": "vertical",
|
|
1233
|
+
children: "Label"
|
|
1234
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Marquee, {
|
|
1235
|
+
css: css,
|
|
1236
|
+
"data-testid": "disabled",
|
|
1237
|
+
marqueeDisabled: true,
|
|
1238
|
+
children: "Label"
|
|
1239
|
+
})]
|
|
1240
|
+
}));
|
|
1241
|
+
expect(_react.screen.getByTestId('horizontal')).not.toHaveAttribute('css');
|
|
1242
|
+
expect(_react.screen.getByTestId('vertical')).not.toHaveAttribute('css');
|
|
1243
|
+
expect(_react.screen.getByTestId('disabled')).not.toHaveAttribute('css');
|
|
1244
|
+
});
|
|
1245
|
+
test('should append an instance class and add a class the config does not have', function () {
|
|
1246
|
+
expect((0, _utils.mergeCss)({
|
|
1247
|
+
text: 'theme-text'
|
|
1248
|
+
}, {
|
|
1249
|
+
text: 'app-text',
|
|
1250
|
+
content: 'app-content'
|
|
1251
|
+
})).toEqual({
|
|
1252
|
+
text: 'theme-text app-text',
|
|
1253
|
+
content: 'app-content'
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
describe('orientation config', function () {
|
|
1258
|
+
var Host = function Host(_ref5) {
|
|
1259
|
+
var children = _ref5.children,
|
|
1260
|
+
marqueeMaxLines = _ref5.marqueeMaxLines,
|
|
1261
|
+
orientation = _ref5.orientation;
|
|
1262
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
1263
|
+
"data-max-lines": marqueeMaxLines,
|
|
1264
|
+
"data-orientation": orientation,
|
|
1265
|
+
"data-testid": "host",
|
|
1266
|
+
children: children
|
|
1267
|
+
});
|
|
1268
|
+
};
|
|
1269
|
+
test('should pass the orientation prop to the wrapped component and keep the marquee horizontal', function () {
|
|
1270
|
+
var Decorated = (0, _index.MarqueeDecorator)({
|
|
1271
|
+
component: _index.MarqueeBase
|
|
1272
|
+
}, Host);
|
|
1273
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Decorated, {
|
|
1274
|
+
orientation: "vertical",
|
|
1275
|
+
children: "Label"
|
|
1276
|
+
}));
|
|
1277
|
+
var host = _react.screen.getByTestId('host');
|
|
1278
|
+
expect(host).toHaveAttribute('data-orientation', 'vertical');
|
|
1279
|
+
expect(host.querySelector('[data-vertical-marquee]')).toBeNull();
|
|
1280
|
+
});
|
|
1281
|
+
test('should pass the orientation prop to the wrapped component when marqueeDisabled is true', function () {
|
|
1282
|
+
var Decorated = (0, _index.MarqueeDecorator)({
|
|
1283
|
+
component: _index.MarqueeBase
|
|
1284
|
+
}, Host);
|
|
1285
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Decorated, {
|
|
1286
|
+
marqueeDisabled: true,
|
|
1287
|
+
orientation: "horizontal",
|
|
1288
|
+
children: "Label"
|
|
1289
|
+
}));
|
|
1290
|
+
expect(_react.screen.getByTestId('host')).toHaveAttribute('data-orientation', 'horizontal');
|
|
1291
|
+
});
|
|
1292
|
+
test('should not pass marqueeMaxLines to the wrapped component', function () {
|
|
1293
|
+
var Decorated = (0, _index.MarqueeDecorator)({
|
|
1294
|
+
component: _index.MarqueeBase,
|
|
1295
|
+
orientation: 'vertical'
|
|
1296
|
+
}, Host);
|
|
1297
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Decorated, {
|
|
1298
|
+
marqueeMaxLines: 4,
|
|
1299
|
+
children: "Label"
|
|
1300
|
+
}));
|
|
1301
|
+
var host = _react.screen.getByTestId('host');
|
|
1302
|
+
expect(host).not.toHaveAttribute('data-max-lines');
|
|
1303
|
+
expect(host.querySelector('[data-vertical-marquee]').style.getPropertyValue('--vertical-marquee-lines')).toBe('4');
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1306
|
+
describe('verticalMeasure', function () {
|
|
1307
|
+
test('should skip a clone when either node is missing', function () {
|
|
1308
|
+
expect(function () {
|
|
1309
|
+
return (0, _verticalMeasure.cloneContentInto)(null, null);
|
|
1310
|
+
}).not.toThrow();
|
|
1311
|
+
});
|
|
1312
|
+
test('should report no reduced motion when matchMedia is missing', function () {
|
|
1313
|
+
var original = window.matchMedia;
|
|
1314
|
+
window.matchMedia = null;
|
|
1315
|
+
expect((0, _verticalMeasure.prefersReducedMotion)()).toBe(false);
|
|
1316
|
+
window.matchMedia = original;
|
|
1317
|
+
});
|
|
1318
|
+
test('should clip from the line height when a single box overflows', function () {
|
|
1319
|
+
var node = document.createElement('div');
|
|
1320
|
+
jest.spyOn(node, 'getBoundingClientRect').mockReturnValue(rect(40));
|
|
1321
|
+
jest.spyOn(document, 'createRange').mockImplementation(function () {
|
|
1322
|
+
return {
|
|
1323
|
+
getClientRects: function getClientRects() {
|
|
1324
|
+
return [{
|
|
1325
|
+
bottom: 20,
|
|
1326
|
+
height: 20,
|
|
1327
|
+
left: 0,
|
|
1328
|
+
right: 10,
|
|
1329
|
+
top: 0,
|
|
1330
|
+
width: 10
|
|
1331
|
+
}];
|
|
1332
|
+
},
|
|
1333
|
+
selectNodeContents: function selectNodeContents() {}
|
|
1334
|
+
};
|
|
1335
|
+
});
|
|
1336
|
+
var metrics = (0, _verticalMeasure.measureNode)(node, 0);
|
|
1337
|
+
expect(metrics.overflows).toBe(true);
|
|
1338
|
+
expect(metrics.clipHeight).toBe(0);
|
|
1339
|
+
jest.restoreAllMocks();
|
|
1340
|
+
});
|
|
1341
|
+
test('should fall back when the range cannot return client rects', function () {
|
|
1342
|
+
var node = document.createElement('div');
|
|
1343
|
+
jest.spyOn(node, 'getBoundingClientRect').mockReturnValue(rect(0));
|
|
1344
|
+
jest.spyOn(document, 'createRange').mockImplementation(function () {
|
|
1345
|
+
return {
|
|
1346
|
+
selectNodeContents: function selectNodeContents() {}
|
|
1347
|
+
};
|
|
1348
|
+
});
|
|
1349
|
+
jest.spyOn(window, 'getComputedStyle').mockReturnValue({
|
|
1350
|
+
fontSize: '0',
|
|
1351
|
+
lineHeight: 'normal'
|
|
1352
|
+
});
|
|
1353
|
+
var metrics = (0, _verticalMeasure.measureNode)(node, 3);
|
|
1354
|
+
expect(metrics.measured).toBe(false);
|
|
1355
|
+
expect(metrics.overflows).toBe(false);
|
|
1356
|
+
jest.restoreAllMocks();
|
|
1357
|
+
});
|
|
1358
|
+
});
|