@instructure/ui-dom-utils 8.47.0 → 8.47.1-snapshot-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/CHANGELOG.md +8 -0
- package/es/__new-tests__/addEventListener.test.js +42 -0
- package/es/__new-tests__/addInputModeListener.test.js +52 -0
- package/es/__new-tests__/addPositionChangeListener.test.js +64 -0
- package/es/__new-tests__/addResizeListener.test.js +64 -0
- package/es/__new-tests__/findTabbable.test.js +66 -0
- package/es/__new-tests__/getClassList.test.js +46 -0
- package/es/__new-tests__/getFontSize.test.js +40 -0
- package/es/__new-tests__/getOffsetParents.test.js +107 -0
- package/es/__new-tests__/getScrollParents.test.js +87 -0
- package/es/__new-tests__/isCustomElement.test.js +41 -0
- package/es/__new-tests__/isVisible.test.js +111 -0
- package/es/__new-tests__/requestAnimationFrame.test.js +36 -0
- package/es/__new-tests__/transformSelection.test.js +67 -0
- package/lib/__new-tests__/addEventListener.test.js +44 -0
- package/lib/__new-tests__/addInputModeListener.test.js +54 -0
- package/lib/__new-tests__/addPositionChangeListener.test.js +66 -0
- package/lib/__new-tests__/addResizeListener.test.js +66 -0
- package/lib/__new-tests__/findTabbable.test.js +68 -0
- package/lib/__new-tests__/getClassList.test.js +48 -0
- package/lib/__new-tests__/getFontSize.test.js +43 -0
- package/lib/__new-tests__/getOffsetParents.test.js +109 -0
- package/lib/__new-tests__/getScrollParents.test.js +89 -0
- package/lib/__new-tests__/isCustomElement.test.js +43 -0
- package/lib/__new-tests__/isVisible.test.js +113 -0
- package/lib/__new-tests__/requestAnimationFrame.test.js +38 -0
- package/lib/__new-tests__/transformSelection.test.js +69 -0
- package/package.json +6 -5
- package/src/__new-tests__/addEventListener.test.tsx +46 -0
- package/src/__new-tests__/addInputModeListener.test.tsx +60 -0
- package/src/__new-tests__/addPositionChangeListener.test.tsx +65 -0
- package/src/__new-tests__/addResizeListener.test.tsx +65 -0
- package/src/__new-tests__/findTabbable.test.tsx +71 -0
- package/src/__new-tests__/getClassList.test.tsx +47 -0
- package/src/__new-tests__/getFontSize.test.tsx +37 -0
- package/src/__new-tests__/getOffsetParents.test.tsx +99 -0
- package/src/__new-tests__/getScrollParents.test.tsx +84 -0
- package/src/__new-tests__/isCustomElement.test.tsx +45 -0
- package/src/__new-tests__/isVisible.test.tsx +114 -0
- package/src/__new-tests__/requestAnimationFrame.test.tsx +38 -0
- package/src/__new-tests__/transformSelection.test.tsx +80 -0
- package/tsconfig.build.json +3 -12
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/__new-tests__/addEventListener.test.d.ts +2 -0
- package/types/__new-tests__/addEventListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addInputModeListener.test.d.ts +2 -0
- package/types/__new-tests__/addInputModeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addPositionChangeListener.test.d.ts +2 -0
- package/types/__new-tests__/addPositionChangeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addResizeListener.test.d.ts +2 -0
- package/types/__new-tests__/addResizeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/findTabbable.test.d.ts +2 -0
- package/types/__new-tests__/findTabbable.test.d.ts.map +1 -0
- package/types/__new-tests__/getClassList.test.d.ts +2 -0
- package/types/__new-tests__/getClassList.test.d.ts.map +1 -0
- package/types/__new-tests__/getFontSize.test.d.ts +2 -0
- package/types/__new-tests__/getFontSize.test.d.ts.map +1 -0
- package/types/__new-tests__/getOffsetParents.test.d.ts +2 -0
- package/types/__new-tests__/getOffsetParents.test.d.ts.map +1 -0
- package/types/__new-tests__/getScrollParents.test.d.ts +2 -0
- package/types/__new-tests__/getScrollParents.test.d.ts.map +1 -0
- package/types/__new-tests__/isCustomElement.test.d.ts +2 -0
- package/types/__new-tests__/isCustomElement.test.d.ts.map +1 -0
- package/types/__new-tests__/isVisible.test.d.ts +2 -0
- package/types/__new-tests__/isVisible.test.d.ts.map +1 -0
- package/types/__new-tests__/requestAnimationFrame.test.d.ts +2 -0
- package/types/__new-tests__/requestAnimationFrame.test.d.ts.map +1 -0
- package/types/__new-tests__/transformSelection.test.d.ts +2 -0
- package/types/__new-tests__/transformSelection.test.d.ts.map +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _getScrollParents = require("../getScrollParents");
|
|
8
|
+
var _div;
|
|
9
|
+
/*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
* in the Software without restriction, including without limitation the rights
|
|
17
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
* furnished to do so, subject to the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
* copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
* SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
describe('getScrollParents', () => {
|
|
33
|
+
const node = /*#__PURE__*/_react.default.createElement("div", null, _div || (_div = /*#__PURE__*/_react.default.createElement("div", {
|
|
34
|
+
id: "item-1"
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
36
|
+
id: "item-2"
|
|
37
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
38
|
+
id: "item-3"
|
|
39
|
+
}, "Test"), /*#__PURE__*/_react.default.createElement("span", {
|
|
40
|
+
id: "sibling-1"
|
|
41
|
+
}, "Test"), /*#__PURE__*/_react.default.createElement("span", {
|
|
42
|
+
id: "sibling-2"
|
|
43
|
+
}, "Test"), /*#__PURE__*/_react.default.createElement("span", {
|
|
44
|
+
id: "sibling-3"
|
|
45
|
+
}, "Test")))), /*#__PURE__*/_react.default.createElement("div", {
|
|
46
|
+
id: "ht",
|
|
47
|
+
style: {
|
|
48
|
+
height: '50px'
|
|
49
|
+
}
|
|
50
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
51
|
+
id: "scroll-parent",
|
|
52
|
+
style: {
|
|
53
|
+
height: '200px',
|
|
54
|
+
overflow: 'scroll'
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
57
|
+
id: "scroll-child",
|
|
58
|
+
style: {
|
|
59
|
+
height: '500px'
|
|
60
|
+
}
|
|
61
|
+
}, "Test"))), /*#__PURE__*/_react.default.createElement("div", {
|
|
62
|
+
id: "scroll-parent-rel",
|
|
63
|
+
style: {
|
|
64
|
+
height: '200px',
|
|
65
|
+
overflow: 'scroll',
|
|
66
|
+
position: 'relative'
|
|
67
|
+
}
|
|
68
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
69
|
+
style: {
|
|
70
|
+
height: '200px',
|
|
71
|
+
overflow: 'scroll'
|
|
72
|
+
}
|
|
73
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
74
|
+
id: "scroll-child-rel",
|
|
75
|
+
style: {
|
|
76
|
+
height: '500px',
|
|
77
|
+
position: 'absolute'
|
|
78
|
+
}
|
|
79
|
+
}, "Test"))), /*#__PURE__*/_react.default.createElement("div", {
|
|
80
|
+
style: {
|
|
81
|
+
height: '200px',
|
|
82
|
+
overflow: 'scroll'
|
|
83
|
+
}
|
|
84
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
+
id: "scroll-child-fixed",
|
|
86
|
+
style: {
|
|
87
|
+
height: '500px',
|
|
88
|
+
position: 'fixed'
|
|
89
|
+
}
|
|
90
|
+
}, "Test")));
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
(0, _react2.render)(node);
|
|
93
|
+
});
|
|
94
|
+
it('should find scroll parent for inline elements', () => {
|
|
95
|
+
const child = document.getElementById('scroll-child');
|
|
96
|
+
const parent = document.getElementById('scroll-parent');
|
|
97
|
+
expect((0, _getScrollParents.getScrollParents)(child)[0]).toBe(parent);
|
|
98
|
+
});
|
|
99
|
+
it('should ignore static parents when absolute', () => {
|
|
100
|
+
const child = document.getElementById('scroll-child-rel');
|
|
101
|
+
const parent = document.getElementById('scroll-parent-rel');
|
|
102
|
+
expect((0, _getScrollParents.getScrollParents)(child)[0]).toBe(parent);
|
|
103
|
+
});
|
|
104
|
+
it('should handle fixed', () => {
|
|
105
|
+
const child = document.getElementById('scroll-child-fixed');
|
|
106
|
+
const scrollParent = (0, _getScrollParents.getScrollParents)(child)[0];
|
|
107
|
+
expect(scrollParent).toBe(document);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _getOffsetParents = require("../getOffsetParents");
|
|
8
|
+
var _div, _div2;
|
|
9
|
+
/*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
* in the Software without restriction, including without limitation the rights
|
|
17
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
* furnished to do so, subject to the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
* copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
* SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
describe('getOffsetParents', () => {
|
|
33
|
+
// At rendering, we receive the node_wrapper and the body as extra offsetParents
|
|
34
|
+
const node = /*#__PURE__*/_react.default.createElement("div", {
|
|
35
|
+
"data-testid": "node"
|
|
36
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
37
|
+
"data-testid": "child_1_wrapper_parent",
|
|
38
|
+
style: {
|
|
39
|
+
transform: '200px',
|
|
40
|
+
position: 'relative'
|
|
41
|
+
}
|
|
42
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
43
|
+
"data-testid": "child_1_wrapper"
|
|
44
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
45
|
+
"data-testid": "child-1",
|
|
46
|
+
style: {
|
|
47
|
+
height: '500px'
|
|
48
|
+
}
|
|
49
|
+
}, "Test"))), /*#__PURE__*/_react.default.createElement("div", {
|
|
50
|
+
"data-testid": "child_2_wrapper_parent",
|
|
51
|
+
style: {
|
|
52
|
+
transform: '200px',
|
|
53
|
+
position: 'absolute'
|
|
54
|
+
}
|
|
55
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
56
|
+
"data-testid": "child_2_wrapper",
|
|
57
|
+
style: {
|
|
58
|
+
position: 'absolute'
|
|
59
|
+
}
|
|
60
|
+
}, _div || (_div = /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
+
"data-testid": "child-2"
|
|
62
|
+
}, "Test")))), _div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", {
|
|
63
|
+
"data-testid": "child_3_wrapper"
|
|
64
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
65
|
+
"data-testid": "child-3"
|
|
66
|
+
}, "Test"))));
|
|
67
|
+
it('should find offset parent for inline elements', () => {
|
|
68
|
+
const _render = (0, _react2.render)(node),
|
|
69
|
+
getByTestId = _render.getByTestId;
|
|
70
|
+
const child = getByTestId('child-1');
|
|
71
|
+
const parent = getByTestId('child_1_wrapper_parent');
|
|
72
|
+
const offsetParents = (0, _getOffsetParents.getOffsetParents)(child);
|
|
73
|
+
expect(offsetParents[1]).toBe(parent);
|
|
74
|
+
});
|
|
75
|
+
it('should ignore static parents when absolute', () => {
|
|
76
|
+
const _render2 = (0, _react2.render)(node),
|
|
77
|
+
getByTestId = _render2.getByTestId;
|
|
78
|
+
const child = getByTestId('child-2');
|
|
79
|
+
const offsetParents = (0, _getOffsetParents.getOffsetParents)(child);
|
|
80
|
+
expect(offsetParents.length).toBe(5);
|
|
81
|
+
});
|
|
82
|
+
it('should handle fixed', () => {
|
|
83
|
+
const _render3 = (0, _react2.render)(node),
|
|
84
|
+
getByTestId = _render3.getByTestId;
|
|
85
|
+
const child = getByTestId('child-3');
|
|
86
|
+
const offsetParents = (0, _getOffsetParents.getOffsetParents)(child);
|
|
87
|
+
expect(offsetParents.length).toBe(4);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
var _isDefinedCustomElement = require("../isDefinedCustomElement");
|
|
5
|
+
/*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
* in the Software without restriction, including without limitation the rights
|
|
13
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
* copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
* SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
class TestElement extends HTMLElement {}
|
|
30
|
+
describe('isDefinedCustomElement', () => {
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
customElements.define('test-element', TestElement);
|
|
33
|
+
});
|
|
34
|
+
it('should return true for defined elements', () => {
|
|
35
|
+
const el = document.createElement('test-element');
|
|
36
|
+
expect((0, _isDefinedCustomElement.isDefinedCustomElement)(el)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('should return false for not defined elements', () => {
|
|
39
|
+
// it is possible to create a custom element that is not defined
|
|
40
|
+
const el = document.createElement('my-element');
|
|
41
|
+
expect((0, _isDefinedCustomElement.isDefinedCustomElement)(el)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _isVisible = require("../isVisible");
|
|
8
|
+
var _div;
|
|
9
|
+
/*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
* in the Software without restriction, including without limitation the rights
|
|
17
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
* furnished to do so, subject to the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
* copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
* SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
describe('isVisible', () => {
|
|
33
|
+
it('should recognize visible elements', () => {
|
|
34
|
+
(0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", {
|
|
35
|
+
"data-testid": "test"
|
|
36
|
+
}, "Hello world!")));
|
|
37
|
+
const element = _react2.screen.getByTestId('test');
|
|
38
|
+
expect((0, _isVisible.isVisible)(element)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('should recognize elements with display: none', () => {
|
|
41
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", {
|
|
42
|
+
"data-testid": "test"
|
|
43
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
44
|
+
style: {
|
|
45
|
+
display: 'none'
|
|
46
|
+
}
|
|
47
|
+
}, "Hello world!")));
|
|
48
|
+
const element = _react2.screen.getByTestId('test').firstChild;
|
|
49
|
+
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
it('should recognize elements hidden with clip', () => {
|
|
52
|
+
const style = {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
overflow: 'hidden',
|
|
55
|
+
clip: 'rect(0,0,0,0)'
|
|
56
|
+
};
|
|
57
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", {
|
|
58
|
+
"data-testid": "test"
|
|
59
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
60
|
+
style: style
|
|
61
|
+
}, "Hello world!")));
|
|
62
|
+
const element = _react2.screen.getByTestId('test').firstChild;
|
|
63
|
+
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it('should recognize clipped elements that are not hidden', () => {
|
|
66
|
+
const style = {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
clip: 'rect(0,0,10px,0)'
|
|
70
|
+
};
|
|
71
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", {
|
|
72
|
+
"data-testid": "test"
|
|
73
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
74
|
+
style: style
|
|
75
|
+
}, "Hello world!")));
|
|
76
|
+
const element = _react2.screen.getByTestId('test').firstChild;
|
|
77
|
+
expect((0, _isVisible.isVisible)(element)).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('should recursively check parent visibility', () => {
|
|
80
|
+
const style = {
|
|
81
|
+
visibility: 'hidden'
|
|
82
|
+
};
|
|
83
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", {
|
|
84
|
+
"data-testid": "test",
|
|
85
|
+
style: style
|
|
86
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement("span", {
|
|
87
|
+
"data-testid": "test-2",
|
|
88
|
+
style: {
|
|
89
|
+
visibility: 'visible'
|
|
90
|
+
}
|
|
91
|
+
}, "Hello world!"))));
|
|
92
|
+
const element = _react2.screen.getByTestId('test-2');
|
|
93
|
+
expect((0, _isVisible.isVisible)(element, false)).toBe(true);
|
|
94
|
+
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
it('should not recursively check text nodes', () => {
|
|
97
|
+
const style = {
|
|
98
|
+
visibility: 'hidden'
|
|
99
|
+
};
|
|
100
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
+
"data-testid": "test",
|
|
102
|
+
style: style
|
|
103
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement("span", {
|
|
104
|
+
"data-testid": "test-2",
|
|
105
|
+
style: {
|
|
106
|
+
visibility: 'visible'
|
|
107
|
+
}
|
|
108
|
+
}, "Hello world!"))));
|
|
109
|
+
const element = _react2.screen.getByTestId('test-2').firstChild;
|
|
110
|
+
expect((0, _isVisible.isVisible)(element, false)).toBe(true);
|
|
111
|
+
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _requestAnimationFrame = require("../requestAnimationFrame");
|
|
5
|
+
/*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
* in the Software without restriction, including without limitation the rights
|
|
13
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
* copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
* SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
describe('requestAnimationFrame', () => {
|
|
30
|
+
it('should provide a cancel method', async () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const raf = (0, _requestAnimationFrame.requestAnimationFrame)(callback);
|
|
33
|
+
await (0, _react.waitFor)(() => {
|
|
34
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(typeof raf.cancel).toBe('function');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _transformSelection = require("../transformSelection");
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
describe('transformSelection', () => {
|
|
29
|
+
it('should work with transformCursor', () => {
|
|
30
|
+
const paramObj = {
|
|
31
|
+
selectionStart: 2,
|
|
32
|
+
selectionEnd: 3,
|
|
33
|
+
selectionDirection: 'none',
|
|
34
|
+
value: '1x2345'
|
|
35
|
+
};
|
|
36
|
+
const result = (0, _transformSelection.transformSelection)(paramObj, '12345');
|
|
37
|
+
expect(result).toEqual({
|
|
38
|
+
selectionStart: 1,
|
|
39
|
+
selectionEnd: 2,
|
|
40
|
+
selectionDirection: 'none'
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('transformCursor', () => {
|
|
45
|
+
it('should retain cursor at the end', () => {
|
|
46
|
+
const dirtyValue = '12_xxxx_';
|
|
47
|
+
const cleanedValue = '12';
|
|
48
|
+
const cursorIndex = dirtyValue.length;
|
|
49
|
+
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(cleanedValue.length);
|
|
50
|
+
});
|
|
51
|
+
it('should retain cursor at the start', () => {
|
|
52
|
+
const dirtyValue = '12_xxxx_67';
|
|
53
|
+
const cleanedValue = '1267';
|
|
54
|
+
const cursorIndex = 0;
|
|
55
|
+
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
it('should retain cursor between cleaned values', () => {
|
|
58
|
+
const dirtyValue = '12_xxxx_67';
|
|
59
|
+
const cleanedValue = '1267';
|
|
60
|
+
const cursorIndex = 6;
|
|
61
|
+
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(2);
|
|
62
|
+
});
|
|
63
|
+
it('should retain cursor after cleaned values', () => {
|
|
64
|
+
const dirtyValue = '12_xxxx_67';
|
|
65
|
+
const cleanedValue = '1267';
|
|
66
|
+
const cursorIndex = dirtyValue.length - 1;
|
|
67
|
+
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(3);
|
|
68
|
+
});
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-dom-utils",
|
|
3
|
-
"version": "8.47.0",
|
|
3
|
+
"version": "8.47.1-snapshot-0",
|
|
4
4
|
"description": "A DOM utility library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@instructure/ui-babel-preset": "8.47.0",
|
|
26
|
-
"@
|
|
25
|
+
"@instructure/ui-babel-preset": "8.47.1-snapshot-0",
|
|
26
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
27
|
+
"@testing-library/react": "^14.0.0"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"@babel/runtime": "^7.23.2",
|
|
30
|
-
"@instructure/console": "8.47.0",
|
|
31
|
-
"@instructure/shared-types": "8.47.0"
|
|
31
|
+
"@instructure/console": "8.47.1-snapshot-0",
|
|
32
|
+
"@instructure/shared-types": "8.47.1-snapshot-0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"react": ">=16.8 <=18",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { fireEvent, render } from '@testing-library/react'
|
|
27
|
+
import '@testing-library/jest-dom'
|
|
28
|
+
import { addEventListener } from '../addEventListener'
|
|
29
|
+
|
|
30
|
+
describe('addEventListener', () => {
|
|
31
|
+
it('should add an event listener and provide a remove method', () => {
|
|
32
|
+
const callback = jest.fn()
|
|
33
|
+
|
|
34
|
+
const { container } = render(<div />)
|
|
35
|
+
const node = container.firstChild as HTMLDivElement
|
|
36
|
+
|
|
37
|
+
const listener = addEventListener(node, 'click', callback)
|
|
38
|
+
|
|
39
|
+
fireEvent.click(node)
|
|
40
|
+
|
|
41
|
+
expect(callback).toHaveBeenCalledTimes(1)
|
|
42
|
+
expect(typeof listener.remove).toBe('function')
|
|
43
|
+
|
|
44
|
+
listener.remove()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, fireEvent, screen } from '@testing-library/react'
|
|
27
|
+
import '@testing-library/jest-dom'
|
|
28
|
+
import { addInputModeListener } from '../addInputModeListener'
|
|
29
|
+
|
|
30
|
+
describe('addInputModeListener', () => {
|
|
31
|
+
it('should handle input mode changes', () => {
|
|
32
|
+
const handleInputModeChange = jest.fn()
|
|
33
|
+
|
|
34
|
+
render(
|
|
35
|
+
<div>
|
|
36
|
+
<button id="button-1">hello</button>
|
|
37
|
+
<button>world</button>
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const inputModeListener = addInputModeListener({
|
|
42
|
+
onInputModeChange: handleInputModeChange
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const button = screen.getByRole('button', { name: 'hello' })
|
|
46
|
+
|
|
47
|
+
fireEvent.mouseUp(button)
|
|
48
|
+
expect(inputModeListener.isKeyboardMode()).toBe(false)
|
|
49
|
+
|
|
50
|
+
fireEvent.keyDown(button)
|
|
51
|
+
expect(inputModeListener.isKeyboardMode()).toBe(true)
|
|
52
|
+
expect(handleInputModeChange).toHaveBeenCalledTimes(2)
|
|
53
|
+
|
|
54
|
+
inputModeListener.remove()
|
|
55
|
+
|
|
56
|
+
fireEvent.mouseUp(button)
|
|
57
|
+
expect(inputModeListener.isKeyboardMode()).toBe(true)
|
|
58
|
+
expect(handleInputModeChange).toHaveBeenCalledTimes(2)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, waitFor } from '@testing-library/react'
|
|
27
|
+
import '@testing-library/jest-dom'
|
|
28
|
+
import { addPositionChangeListener } from '../addPositionChangeListener'
|
|
29
|
+
|
|
30
|
+
const mockRect = {
|
|
31
|
+
top: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
bottom: 0,
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
toJSON: jest.fn()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('addPositionChangeListener', () => {
|
|
43
|
+
it('should provide a remove method', async () => {
|
|
44
|
+
const callback = jest.fn()
|
|
45
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => mockRect as DOMRect)
|
|
46
|
+
|
|
47
|
+
const { container } = render(<div />)
|
|
48
|
+
const node = container.firstChild as HTMLDivElement
|
|
49
|
+
|
|
50
|
+
const listener = addPositionChangeListener(node, callback)
|
|
51
|
+
|
|
52
|
+
// Manually trigger a position change (since JSDOM won't)
|
|
53
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => {
|
|
54
|
+
return { ...mockRect, top: 200 } as DOMRect
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
await waitFor(() => {
|
|
58
|
+
expect(callback).toHaveBeenCalledTimes(1)
|
|
59
|
+
expect(typeof listener.remove).toBe('function')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
listener.remove()
|
|
63
|
+
jest.restoreAllMocks()
|
|
64
|
+
})
|
|
65
|
+
})
|