@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/__new-tests__/addEventListener.test.js +42 -0
  3. package/es/__new-tests__/addInputModeListener.test.js +52 -0
  4. package/es/__new-tests__/addPositionChangeListener.test.js +64 -0
  5. package/es/__new-tests__/addResizeListener.test.js +64 -0
  6. package/es/__new-tests__/findTabbable.test.js +66 -0
  7. package/es/__new-tests__/getClassList.test.js +46 -0
  8. package/es/__new-tests__/getFontSize.test.js +40 -0
  9. package/es/__new-tests__/getOffsetParents.test.js +107 -0
  10. package/es/__new-tests__/getScrollParents.test.js +87 -0
  11. package/es/__new-tests__/isCustomElement.test.js +41 -0
  12. package/es/__new-tests__/isVisible.test.js +111 -0
  13. package/es/__new-tests__/requestAnimationFrame.test.js +36 -0
  14. package/es/__new-tests__/transformSelection.test.js +67 -0
  15. package/lib/__new-tests__/addEventListener.test.js +44 -0
  16. package/lib/__new-tests__/addInputModeListener.test.js +54 -0
  17. package/lib/__new-tests__/addPositionChangeListener.test.js +66 -0
  18. package/lib/__new-tests__/addResizeListener.test.js +66 -0
  19. package/lib/__new-tests__/findTabbable.test.js +68 -0
  20. package/lib/__new-tests__/getClassList.test.js +48 -0
  21. package/lib/__new-tests__/getFontSize.test.js +43 -0
  22. package/lib/__new-tests__/getOffsetParents.test.js +109 -0
  23. package/lib/__new-tests__/getScrollParents.test.js +89 -0
  24. package/lib/__new-tests__/isCustomElement.test.js +43 -0
  25. package/lib/__new-tests__/isVisible.test.js +113 -0
  26. package/lib/__new-tests__/requestAnimationFrame.test.js +38 -0
  27. package/lib/__new-tests__/transformSelection.test.js +69 -0
  28. package/package.json +6 -5
  29. package/src/__new-tests__/addEventListener.test.tsx +46 -0
  30. package/src/__new-tests__/addInputModeListener.test.tsx +60 -0
  31. package/src/__new-tests__/addPositionChangeListener.test.tsx +65 -0
  32. package/src/__new-tests__/addResizeListener.test.tsx +65 -0
  33. package/src/__new-tests__/findTabbable.test.tsx +71 -0
  34. package/src/__new-tests__/getClassList.test.tsx +47 -0
  35. package/src/__new-tests__/getFontSize.test.tsx +37 -0
  36. package/src/__new-tests__/getOffsetParents.test.tsx +99 -0
  37. package/src/__new-tests__/getScrollParents.test.tsx +84 -0
  38. package/src/__new-tests__/isCustomElement.test.tsx +45 -0
  39. package/src/__new-tests__/isVisible.test.tsx +114 -0
  40. package/src/__new-tests__/requestAnimationFrame.test.tsx +38 -0
  41. package/src/__new-tests__/transformSelection.test.tsx +80 -0
  42. package/tsconfig.build.json +3 -12
  43. package/tsconfig.build.tsbuildinfo +1 -1
  44. package/types/__new-tests__/addEventListener.test.d.ts +2 -0
  45. package/types/__new-tests__/addEventListener.test.d.ts.map +1 -0
  46. package/types/__new-tests__/addInputModeListener.test.d.ts +2 -0
  47. package/types/__new-tests__/addInputModeListener.test.d.ts.map +1 -0
  48. package/types/__new-tests__/addPositionChangeListener.test.d.ts +2 -0
  49. package/types/__new-tests__/addPositionChangeListener.test.d.ts.map +1 -0
  50. package/types/__new-tests__/addResizeListener.test.d.ts +2 -0
  51. package/types/__new-tests__/addResizeListener.test.d.ts.map +1 -0
  52. package/types/__new-tests__/findTabbable.test.d.ts +2 -0
  53. package/types/__new-tests__/findTabbable.test.d.ts.map +1 -0
  54. package/types/__new-tests__/getClassList.test.d.ts +2 -0
  55. package/types/__new-tests__/getClassList.test.d.ts.map +1 -0
  56. package/types/__new-tests__/getFontSize.test.d.ts +2 -0
  57. package/types/__new-tests__/getFontSize.test.d.ts.map +1 -0
  58. package/types/__new-tests__/getOffsetParents.test.d.ts +2 -0
  59. package/types/__new-tests__/getOffsetParents.test.d.ts.map +1 -0
  60. package/types/__new-tests__/getScrollParents.test.d.ts +2 -0
  61. package/types/__new-tests__/getScrollParents.test.d.ts.map +1 -0
  62. package/types/__new-tests__/isCustomElement.test.d.ts +2 -0
  63. package/types/__new-tests__/isCustomElement.test.d.ts.map +1 -0
  64. package/types/__new-tests__/isVisible.test.d.ts +2 -0
  65. package/types/__new-tests__/isVisible.test.d.ts.map +1 -0
  66. package/types/__new-tests__/requestAnimationFrame.test.d.ts +2 -0
  67. package/types/__new-tests__/requestAnimationFrame.test.d.ts.map +1 -0
  68. package/types/__new-tests__/transformSelection.test.d.ts +2 -0
  69. package/types/__new-tests__/transformSelection.test.d.ts.map +1 -0
@@ -0,0 +1,111 @@
1
+ var _div;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render, screen } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { isVisible } from '../isVisible';
30
+ describe('isVisible', () => {
31
+ it('should recognize visible elements', () => {
32
+ render(_div || (_div = /*#__PURE__*/React.createElement("div", {
33
+ "data-testid": "test"
34
+ }, "Hello world!")));
35
+ const element = screen.getByTestId('test');
36
+ expect(isVisible(element)).toBe(true);
37
+ });
38
+ it('should recognize elements with display: none', () => {
39
+ render( /*#__PURE__*/React.createElement("div", {
40
+ "data-testid": "test"
41
+ }, /*#__PURE__*/React.createElement("span", {
42
+ style: {
43
+ display: 'none'
44
+ }
45
+ }, "Hello world!")));
46
+ const element = screen.getByTestId('test').firstChild;
47
+ expect(isVisible(element)).toBe(false);
48
+ });
49
+ it('should recognize elements hidden with clip', () => {
50
+ const style = {
51
+ position: 'absolute',
52
+ overflow: 'hidden',
53
+ clip: 'rect(0,0,0,0)'
54
+ };
55
+ render( /*#__PURE__*/React.createElement("div", {
56
+ "data-testid": "test"
57
+ }, /*#__PURE__*/React.createElement("span", {
58
+ style: style
59
+ }, "Hello world!")));
60
+ const element = screen.getByTestId('test').firstChild;
61
+ expect(isVisible(element)).toBe(false);
62
+ });
63
+ it('should recognize clipped elements that are not hidden', () => {
64
+ const style = {
65
+ position: 'absolute',
66
+ overflow: 'hidden',
67
+ clip: 'rect(0,0,10px,0)'
68
+ };
69
+ render( /*#__PURE__*/React.createElement("div", {
70
+ "data-testid": "test"
71
+ }, /*#__PURE__*/React.createElement("span", {
72
+ style: style
73
+ }, "Hello world!")));
74
+ const element = screen.getByTestId('test').firstChild;
75
+ expect(isVisible(element)).toBe(true);
76
+ });
77
+ it('should recursively check parent visibility', () => {
78
+ const style = {
79
+ visibility: 'hidden'
80
+ };
81
+ render( /*#__PURE__*/React.createElement("div", {
82
+ "data-testid": "test",
83
+ style: style
84
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", {
85
+ "data-testid": "test-2",
86
+ style: {
87
+ visibility: 'visible'
88
+ }
89
+ }, "Hello world!"))));
90
+ const element = screen.getByTestId('test-2');
91
+ expect(isVisible(element, false)).toBe(true);
92
+ expect(isVisible(element)).toBe(false);
93
+ });
94
+ it('should not recursively check text nodes', () => {
95
+ const style = {
96
+ visibility: 'hidden'
97
+ };
98
+ render( /*#__PURE__*/React.createElement("div", {
99
+ "data-testid": "test",
100
+ style: style
101
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", {
102
+ "data-testid": "test-2",
103
+ style: {
104
+ visibility: 'visible'
105
+ }
106
+ }, "Hello world!"))));
107
+ const element = screen.getByTestId('test-2').firstChild;
108
+ expect(isVisible(element, false)).toBe(true);
109
+ expect(isVisible(element)).toBe(false);
110
+ });
111
+ });
@@ -0,0 +1,36 @@
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 { waitFor } from '@testing-library/react';
26
+ import { requestAnimationFrame } from '../requestAnimationFrame';
27
+ describe('requestAnimationFrame', () => {
28
+ it('should provide a cancel method', async () => {
29
+ const callback = jest.fn();
30
+ const raf = requestAnimationFrame(callback);
31
+ await waitFor(() => {
32
+ expect(callback).toHaveBeenCalledTimes(1);
33
+ expect(typeof raf.cancel).toBe('function');
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,67 @@
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 { transformSelection, transformCursor } from '../transformSelection';
26
+ describe('transformSelection', () => {
27
+ it('should work with transformCursor', () => {
28
+ const paramObj = {
29
+ selectionStart: 2,
30
+ selectionEnd: 3,
31
+ selectionDirection: 'none',
32
+ value: '1x2345'
33
+ };
34
+ const result = transformSelection(paramObj, '12345');
35
+ expect(result).toEqual({
36
+ selectionStart: 1,
37
+ selectionEnd: 2,
38
+ selectionDirection: 'none'
39
+ });
40
+ });
41
+ });
42
+ describe('transformCursor', () => {
43
+ it('should retain cursor at the end', () => {
44
+ const dirtyValue = '12_xxxx_';
45
+ const cleanedValue = '12';
46
+ const cursorIndex = dirtyValue.length;
47
+ expect(transformCursor(cursorIndex, dirtyValue, cleanedValue)).toBe(cleanedValue.length);
48
+ });
49
+ it('should retain cursor at the start', () => {
50
+ const dirtyValue = '12_xxxx_67';
51
+ const cleanedValue = '1267';
52
+ const cursorIndex = 0;
53
+ expect(transformCursor(cursorIndex, dirtyValue, cleanedValue)).toBe(0);
54
+ });
55
+ it('should retain cursor between cleaned values', () => {
56
+ const dirtyValue = '12_xxxx_67';
57
+ const cleanedValue = '1267';
58
+ const cursorIndex = 6;
59
+ expect(transformCursor(cursorIndex, dirtyValue, cleanedValue)).toBe(2);
60
+ });
61
+ it('should retain cursor after cleaned values', () => {
62
+ const dirtyValue = '12_xxxx_67';
63
+ const cleanedValue = '1267';
64
+ const cursorIndex = dirtyValue.length - 1;
65
+ expect(transformCursor(cursorIndex, dirtyValue, cleanedValue)).toBe(3);
66
+ });
67
+ });
@@ -0,0 +1,44 @@
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 _addEventListener = require("../addEventListener");
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('addEventListener', () => {
33
+ it('should add an event listener and provide a remove method', () => {
34
+ const callback = jest.fn();
35
+ const _render = (0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null))),
36
+ container = _render.container;
37
+ const node = container.firstChild;
38
+ const listener = (0, _addEventListener.addEventListener)(node, 'click', callback);
39
+ _react2.fireEvent.click(node);
40
+ expect(callback).toHaveBeenCalledTimes(1);
41
+ expect(typeof listener.remove).toBe('function');
42
+ listener.remove();
43
+ });
44
+ });
@@ -0,0 +1,54 @@
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 _addInputModeListener = require("../addInputModeListener");
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('addInputModeListener', () => {
33
+ it('should handle input mode changes', () => {
34
+ const handleInputModeChange = jest.fn();
35
+ (0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("button", {
36
+ id: "button-1"
37
+ }, "hello"), /*#__PURE__*/_react.default.createElement("button", null, "world"))));
38
+ const inputModeListener = (0, _addInputModeListener.addInputModeListener)({
39
+ onInputModeChange: handleInputModeChange
40
+ });
41
+ const button = _react2.screen.getByRole('button', {
42
+ name: 'hello'
43
+ });
44
+ _react2.fireEvent.mouseUp(button);
45
+ expect(inputModeListener.isKeyboardMode()).toBe(false);
46
+ _react2.fireEvent.keyDown(button);
47
+ expect(inputModeListener.isKeyboardMode()).toBe(true);
48
+ expect(handleInputModeChange).toHaveBeenCalledTimes(2);
49
+ inputModeListener.remove();
50
+ _react2.fireEvent.mouseUp(button);
51
+ expect(inputModeListener.isKeyboardMode()).toBe(true);
52
+ expect(handleInputModeChange).toHaveBeenCalledTimes(2);
53
+ });
54
+ });
@@ -0,0 +1,66 @@
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 _addPositionChangeListener = require("../addPositionChangeListener");
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
+ const mockRect = {
33
+ top: 0,
34
+ left: 0,
35
+ right: 0,
36
+ bottom: 0,
37
+ width: 0,
38
+ height: 0,
39
+ x: 0,
40
+ y: 0,
41
+ toJSON: jest.fn()
42
+ };
43
+ describe('addPositionChangeListener', () => {
44
+ it('should provide a remove method', async () => {
45
+ const callback = jest.fn();
46
+ Element.prototype.getBoundingClientRect = jest.fn(() => mockRect);
47
+ const _render = (0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null))),
48
+ container = _render.container;
49
+ const node = container.firstChild;
50
+ const listener = (0, _addPositionChangeListener.addPositionChangeListener)(node, callback);
51
+
52
+ // Manually trigger a position change (since JSDOM won't)
53
+ Element.prototype.getBoundingClientRect = jest.fn(() => {
54
+ return {
55
+ ...mockRect,
56
+ top: 200
57
+ };
58
+ });
59
+ await (0, _react2.waitFor)(() => {
60
+ expect(callback).toHaveBeenCalledTimes(1);
61
+ expect(typeof listener.remove).toBe('function');
62
+ });
63
+ listener.remove();
64
+ jest.restoreAllMocks();
65
+ });
66
+ });
@@ -0,0 +1,66 @@
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 _addResizeListener = require("../addResizeListener");
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
+ const mockRect = {
33
+ top: 0,
34
+ left: 0,
35
+ right: 0,
36
+ bottom: 0,
37
+ width: 0,
38
+ height: 0,
39
+ x: 0,
40
+ y: 0,
41
+ toJSON: jest.fn()
42
+ };
43
+ describe('addResizeListener', () => {
44
+ it('should provide a remove method', async () => {
45
+ const callback = jest.fn();
46
+ Element.prototype.getBoundingClientRect = jest.fn(() => mockRect);
47
+ const _render = (0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null))),
48
+ container = _render.container;
49
+ const node = container.firstChild;
50
+ const listener = (0, _addResizeListener.addResizeListener)(node, callback);
51
+
52
+ // Manually trigger a size change (since JSDOM won't)
53
+ Element.prototype.getBoundingClientRect = jest.fn(() => {
54
+ return {
55
+ ...mockRect,
56
+ width: 200
57
+ };
58
+ });
59
+ await (0, _react2.waitFor)(() => {
60
+ expect(callback).toHaveBeenCalledTimes(1);
61
+ expect(typeof listener.remove).toBe('function');
62
+ });
63
+ listener.remove();
64
+ jest.restoreAllMocks();
65
+ });
66
+ });
@@ -0,0 +1,68 @@
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 _findTabbable = require("../findTabbable");
8
+ var _a, _div, _div2, _input, _button, _button2;
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('findTabbable', () => {
33
+ describe('tabbable content', () => {
34
+ it('should find tabbable descendants', () => {
35
+ /* eslint-disable jsx-a11y/tabindex-no-positive */
36
+ /* eslint-disable jsx-a11y/no-noninteractive-tabindex */
37
+ const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, _a || (_a = /*#__PURE__*/_react.default.createElement("a", {
38
+ href: "https://instructure-test"
39
+ }, "Tabbable")), _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, "Not Tabbable")), _div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", {
40
+ tabIndex: 1
41
+ }, "Tabbable")), _input || (_input = /*#__PURE__*/_react.default.createElement("input", {
42
+ type: "text",
43
+ value: "Tabbable",
44
+ readOnly: true
45
+ })), /*#__PURE__*/_react.default.createElement("div", null, _button || (_button = /*#__PURE__*/_react.default.createElement("button", null, "Tabbable")), /*#__PURE__*/_react.default.createElement("button", {
46
+ style: {
47
+ display: 'none'
48
+ }
49
+ }, "Not Tabbable")))),
50
+ container = _render.container;
51
+ const node = container.firstChild;
52
+ expect((0, _findTabbable.findTabbable)(node).length).toBe(4);
53
+ });
54
+ });
55
+ describe('tabbable root', () => {
56
+ it('should search the root node when shouldSearchRootNode is set', () => {
57
+ const shouldSearchRootNode = true;
58
+ const _render2 = (0, _react2.render)(_button2 || (_button2 = /*#__PURE__*/_react.default.createElement("button", null, /*#__PURE__*/_react.default.createElement("span", null, "hello")))),
59
+ container = _render2.container;
60
+ const node = container.firstChild;
61
+ expect((0, _findTabbable.findTabbable)(node).length).toBe(0);
62
+ expect((0, _findTabbable.findTabbable)(node, shouldSearchRootNode).length).toBe(1);
63
+ });
64
+ });
65
+ it('should gracefully handle null', () => {
66
+ expect((0, _findTabbable.findTabbable)(null).length).toBe(0);
67
+ });
68
+ });
@@ -0,0 +1,48 @@
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 _getClassList = require("../getClassList");
8
+ var _span;
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('getClassList', () => {
33
+ it('should provide classlist methods', () => {
34
+ const _render = (0, _react2.render)(_span || (_span = /*#__PURE__*/_react.default.createElement("span", {
35
+ className: "foo bar baz"
36
+ }, "Test"))),
37
+ container = _render.container;
38
+ const node = container.firstChild;
39
+ const classes = (0, _getClassList.getClassList)(node);
40
+ expect(classes.toArray().length).toBe(3);
41
+ expect(classes.contains('foo')).toBeTruthy();
42
+ expect(classes.contains('lorem')).toBeFalsy();
43
+ classes.add('lorem');
44
+ expect(classes.contains('lorem')).toBeTruthy();
45
+ classes.remove('lorem');
46
+ expect(classes.contains('lorem')).toBeFalsy();
47
+ });
48
+ });
@@ -0,0 +1,43 @@
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 _getFontSize = require("../getFontSize");
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ describe('getFontSize', () => {
33
+ it('should return font size as a number', () => {
34
+ const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("span", {
35
+ style: {
36
+ fontSize: '17px'
37
+ }
38
+ }, "Test")),
39
+ container = _render.container;
40
+ const node = container.firstChild;
41
+ expect((0, _getFontSize.getFontSize)(node)).toBe(17);
42
+ });
43
+ });