@instructure/ui-react-utils 8.53.2 → 8.53.3-pr-snapshot-8

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 (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/__new-tests__/ComponentIdentifier.test.js +77 -0
  3. package/es/__new-tests__/DeterministicIdContext.test.js +89 -0
  4. package/es/__new-tests__/callRenderProp.test.js +121 -0
  5. package/es/__new-tests__/deprecated.test.js +223 -0
  6. package/es/__new-tests__/experimental.test.js +94 -0
  7. package/es/__new-tests__/getInteraction.test.js +117 -0
  8. package/es/__new-tests__/hack.test.js +66 -0
  9. package/es/__new-tests__/omitProps.test.js +91 -0
  10. package/es/__new-tests__/passthroughProps.test.js +100 -0
  11. package/es/__new-tests__/pickProps.test.js +95 -0
  12. package/es/__new-tests__/safeCloneElement.test.js +86 -0
  13. package/lib/__new-tests__/ComponentIdentifier.test.js +80 -0
  14. package/lib/__new-tests__/DeterministicIdContext.test.js +91 -0
  15. package/lib/__new-tests__/callRenderProp.test.js +123 -0
  16. package/lib/__new-tests__/deprecated.test.js +227 -0
  17. package/lib/__new-tests__/experimental.test.js +98 -0
  18. package/lib/__new-tests__/getInteraction.test.js +119 -0
  19. package/lib/__new-tests__/hack.test.js +70 -0
  20. package/lib/__new-tests__/omitProps.test.js +94 -0
  21. package/lib/__new-tests__/passthroughProps.test.js +102 -0
  22. package/lib/__new-tests__/pickProps.test.js +98 -0
  23. package/lib/__new-tests__/safeCloneElement.test.js +89 -0
  24. package/package.json +9 -8
  25. package/src/__new-tests__/ComponentIdentifier.test.tsx +105 -0
  26. package/src/__new-tests__/DeterministicIdContext.test.tsx +126 -0
  27. package/src/__new-tests__/callRenderProp.test.tsx +136 -0
  28. package/src/__new-tests__/deprecated.test.tsx +357 -0
  29. package/src/__new-tests__/experimental.test.tsx +138 -0
  30. package/src/__new-tests__/getInteraction.test.tsx +119 -0
  31. package/src/__new-tests__/hack.test.tsx +90 -0
  32. package/src/__new-tests__/omitProps.test.tsx +113 -0
  33. package/src/__new-tests__/passthroughProps.test.tsx +100 -0
  34. package/src/__new-tests__/pickProps.test.tsx +111 -0
  35. package/src/__new-tests__/safeCloneElement.test.tsx +95 -0
  36. package/tsconfig.build.json +0 -3
  37. package/tsconfig.build.tsbuildinfo +1 -1
  38. package/types/__new-tests__/ComponentIdentifier.test.d.ts +2 -0
  39. package/types/__new-tests__/ComponentIdentifier.test.d.ts.map +1 -0
  40. package/types/__new-tests__/DeterministicIdContext.test.d.ts +2 -0
  41. package/types/__new-tests__/DeterministicIdContext.test.d.ts.map +1 -0
  42. package/types/__new-tests__/callRenderProp.test.d.ts +2 -0
  43. package/types/__new-tests__/callRenderProp.test.d.ts.map +1 -0
  44. package/types/__new-tests__/deprecated.test.d.ts +2 -0
  45. package/types/__new-tests__/deprecated.test.d.ts.map +1 -0
  46. package/types/__new-tests__/experimental.test.d.ts +2 -0
  47. package/types/__new-tests__/experimental.test.d.ts.map +1 -0
  48. package/types/__new-tests__/getInteraction.test.d.ts +2 -0
  49. package/types/__new-tests__/getInteraction.test.d.ts.map +1 -0
  50. package/types/__new-tests__/hack.test.d.ts +2 -0
  51. package/types/__new-tests__/hack.test.d.ts.map +1 -0
  52. package/types/__new-tests__/omitProps.test.d.ts +2 -0
  53. package/types/__new-tests__/omitProps.test.d.ts.map +1 -0
  54. package/types/__new-tests__/passthroughProps.test.d.ts +2 -0
  55. package/types/__new-tests__/passthroughProps.test.d.ts.map +1 -0
  56. package/types/__new-tests__/pickProps.test.d.ts +2 -0
  57. package/types/__new-tests__/pickProps.test.d.ts.map +1 -0
  58. package/types/__new-tests__/safeCloneElement.test.d.ts +2 -0
  59. package/types/__new-tests__/safeCloneElement.test.d.ts.map +1 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _react = _interopRequireWildcard(require("react"));
6
+ var _propTypes = _interopRequireDefault(require("prop-types"));
7
+ var _react2 = require("@testing-library/react");
8
+ require("@testing-library/jest-dom");
9
+ var _hack = require("../hack");
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+
34
+ class TestComponent extends _react.Component {
35
+ render() {
36
+ return /*#__PURE__*/_react.default.createElement("div", null, this.props.qux, " ", this.props.bar);
37
+ }
38
+ }
39
+ TestComponent.displayName = "TestComponent";
40
+ TestComponent.propTypes = {
41
+ bar: _propTypes.default.string,
42
+ qux: _propTypes.default.string
43
+ };
44
+ TestComponent.defaultProps = {
45
+ bar: void 0,
46
+ qux: 'Hello'
47
+ };
48
+ describe('@hack', () => {
49
+ describe('hack props', () => {
50
+ var _HackComponent, _HackComponent2;
51
+ const HackComponent = (0, _hack.hack)(['bar'])(TestComponent);
52
+ it('should warn when using an hack prop', () => {
53
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
54
+ (0, _react2.render)(_HackComponent || (_HackComponent = /*#__PURE__*/_react.default.createElement(HackComponent, {
55
+ bar: "Jane"
56
+ })));
57
+ const expectedWarningMessage = 'Warning: [TestComponent] The `bar` prop is a temporary hack and will be removed in a future release.';
58
+ expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
59
+ consoleWarningSpy.mockRestore();
60
+ });
61
+ it('should not output a warning using a non-hack prop', () => {
62
+ const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
63
+ (0, _react2.render)(_HackComponent2 || (_HackComponent2 = /*#__PURE__*/_react.default.createElement(HackComponent, {
64
+ qux: "Jane"
65
+ })));
66
+ expect(consoleWarningSpy).not.toHaveBeenCalled();
67
+ consoleWarningSpy.mockRestore();
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _propTypes = _interopRequireDefault(require("prop-types"));
5
+ require("@testing-library/jest-dom");
6
+ var _omitProps = require("../omitProps");
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ describe('omitProps', () => {
32
+ it('should work with PropTypes', () => {
33
+ const propTypes = {
34
+ prop1: _propTypes.default.string.isRequired,
35
+ prop2: _propTypes.default.number
36
+ };
37
+ const inputProps = {
38
+ prop1: 'hello',
39
+ prop2: 42,
40
+ excessiveProp: 'excessiveValue'
41
+ };
42
+ const expectedResult = {
43
+ excessiveProp: 'excessiveValue'
44
+ };
45
+ const actualResult = (0, _omitProps.omitProps)(inputProps, propTypes);
46
+ expect(actualResult).toEqual(expectedResult);
47
+ });
48
+ it('should work with PropTypes and exclude the given keys', () => {
49
+ const propTypes = {
50
+ prop1: _propTypes.default.string.isRequired,
51
+ prop2: _propTypes.default.number
52
+ };
53
+ const inputProps = {
54
+ prop1: 'hello',
55
+ prop2: 42,
56
+ excessiveProp1: 'excessiveValue1',
57
+ excessiveProp2: 'excessiveValue2'
58
+ };
59
+ const expectedResult = {
60
+ excessiveProp2: 'excessiveValue2'
61
+ };
62
+ const actualResult = (0, _omitProps.omitProps)(inputProps, propTypes, ['excessiveProp1']);
63
+ expect(actualResult).toEqual(expectedResult);
64
+ });
65
+ it('should work with an input of a list allowed prop names', () => {
66
+ const allowedPropKeys = ['prop1', 'prop2'];
67
+ const inputProps = {
68
+ prop1: 'hello',
69
+ prop2: 42,
70
+ excessiveProp1: 'excessiveValue1',
71
+ excessiveProp2: 'excessiveValue2'
72
+ };
73
+ const expectedResult = {
74
+ excessiveProp1: 'excessiveValue1',
75
+ excessiveProp2: 'excessiveValue2'
76
+ };
77
+ const actualResult = (0, _omitProps.omitProps)(inputProps, allowedPropKeys);
78
+ expect(actualResult).toEqual(expectedResult);
79
+ });
80
+ it('should work with an input of a list allowed prop names and exclude the given keys', () => {
81
+ const allowedPropKeys = ['prop1', 'prop2'];
82
+ const inputProps = {
83
+ prop1: 'hello',
84
+ prop2: 42,
85
+ excessiveProp1: 'excessiveValue1',
86
+ excessiveProp2: 'excessiveValue2'
87
+ };
88
+ const expectedResult = {
89
+ excessiveProp2: 'excessiveValue2'
90
+ };
91
+ const actualResult = (0, _omitProps.omitProps)(inputProps, allowedPropKeys, ['excessiveProp1']);
92
+ expect(actualResult).toEqual(expectedResult);
93
+ });
94
+ });
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _passthroughProps = require("../passthroughProps");
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('passthroughProps', () => {
30
+ it('should passthrough standard dom attributes', () => {
31
+ const props = {
32
+ id: 'myId',
33
+ title: 'My title'
34
+ };
35
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(2);
36
+ });
37
+ it('should passthrough data attributes', () => {
38
+ const props = {
39
+ 'data-test': true
40
+ };
41
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(1);
42
+ });
43
+ it('should passthrough valid react props', () => {
44
+ const props = {
45
+ ref: () => {},
46
+ innerHTML: '<span>hello world</span>'
47
+ };
48
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(2);
49
+ });
50
+ it('should passthrough props prefixed with "on"', () => {
51
+ const props = {
52
+ onClick: () => {},
53
+ onCustomCallback: () => {},
54
+ onChange: () => {}
55
+ };
56
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(3);
57
+ });
58
+ it('should omit invalid props', () => {
59
+ const props = {
60
+ myCustomProp: 'hello'
61
+ };
62
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(0);
63
+ });
64
+ it('should omit certain react props', () => {
65
+ const props = {
66
+ style: {
67
+ color: 'blue'
68
+ },
69
+ className: 'myClass',
70
+ children: 'hello world',
71
+ theme: {
72
+ themeVar: 'myColor'
73
+ }
74
+ };
75
+ expect(Object.keys((0, _passthroughProps.passthroughProps)(props)).length).toEqual(0);
76
+ });
77
+ it('should passthrough and omit correct props', () => {
78
+ const props = {
79
+ id: 'myId',
80
+ title: 'My title',
81
+ 'data-test': true,
82
+ className: 'myClassName',
83
+ children: 'hello world',
84
+ style: {
85
+ color: 'blue'
86
+ },
87
+ theme: {
88
+ themeVar: 'myColor'
89
+ },
90
+ withSomething: false,
91
+ onCustomCallback: null,
92
+ onChange: null
93
+ };
94
+ expect((0, _passthroughProps.passthroughProps)(props)).toEqual({
95
+ id: 'myId',
96
+ title: 'My title',
97
+ 'data-test': true,
98
+ onCustomCallback: null,
99
+ onChange: null
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _propTypes = _interopRequireDefault(require("prop-types"));
5
+ require("@testing-library/jest-dom");
6
+ var _pickProps = require("../pickProps");
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ describe('pickProps', () => {
32
+ it('should work with propTypes', () => {
33
+ const propTypes = {
34
+ prop1: _propTypes.default.string.isRequired,
35
+ prop2: _propTypes.default.number
36
+ };
37
+ const inputProps = {
38
+ prop1: 'hello',
39
+ prop2: 42,
40
+ excessiveProp: 'excessiveValue'
41
+ };
42
+ const expectedResult = {
43
+ prop1: 'hello',
44
+ prop2: 42
45
+ };
46
+ const actualResult = (0, _pickProps.pickProps)(inputProps, propTypes);
47
+ expect(actualResult).toEqual(expectedResult);
48
+ });
49
+ it('should add the `include` keys to the result with PropTypes', () => {
50
+ const propTypes = {
51
+ prop1: _propTypes.default.string.isRequired,
52
+ prop2: _propTypes.default.number
53
+ };
54
+ const inputProps = {
55
+ prop1: 'hello',
56
+ prop2: 42,
57
+ excessiveProp1: 'excessiveValue1',
58
+ excessiveProp2: 'excessiveValue2'
59
+ };
60
+ const expectedResult = {
61
+ prop1: 'hello',
62
+ prop2: 42,
63
+ excessiveProp2: 'excessiveValue2'
64
+ };
65
+ const actualResult = (0, _pickProps.pickProps)(inputProps, propTypes, ['excessiveProp2']);
66
+ expect(actualResult).toEqual(expectedResult);
67
+ });
68
+ it('should work with an input of a list allowed prop names', () => {
69
+ const allowedPropKeys = ['prop1', 'prop2'];
70
+ const inputProps = {
71
+ prop1: 'hello',
72
+ prop2: 42,
73
+ excessiveProp1: 'excessiveValue1'
74
+ };
75
+ const expectedResult = {
76
+ prop1: 'hello',
77
+ prop2: 42
78
+ };
79
+ const actualResult = (0, _pickProps.pickProps)(inputProps, allowedPropKeys);
80
+ expect(actualResult).toEqual(expectedResult);
81
+ });
82
+ it('should add the `include` keys to the result with a list allowed prop names', () => {
83
+ const allowedPropKeys = ['prop1', 'prop2'];
84
+ const inputProps = {
85
+ prop1: 'hello',
86
+ prop2: 42,
87
+ excessiveProp1: 'excessiveValue1',
88
+ excessiveProp2: 'excessiveValue2'
89
+ };
90
+ const expectedResult = {
91
+ prop1: 'hello',
92
+ prop2: 42,
93
+ excessiveProp2: 'excessiveValue2'
94
+ };
95
+ const actualResult = (0, _pickProps.pickProps)(inputProps, allowedPropKeys, ['excessiveProp2']);
96
+ expect(actualResult).toEqual(expectedResult);
97
+ });
98
+ });
@@ -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 _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
6
+ var _react2 = require("@testing-library/react");
7
+ require("@testing-library/jest-dom");
8
+ var _safeCloneElement = require("../safeCloneElement");
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
+
33
+ describe('safeCloneElement', () => {
34
+ const SafeClone = function ({
35
+ element,
36
+ props,
37
+ children
38
+ }) {
39
+ return (0, _safeCloneElement.safeCloneElement)(element, props, children);
40
+ };
41
+ it('should preserve refs', () => {
42
+ const origRef = jest.fn();
43
+ const cloneRef = jest.fn();
44
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(SafeClone, {
45
+ element: /*#__PURE__*/_react.default.createElement("div", {
46
+ ref: origRef
47
+ }),
48
+ props: {
49
+ ref: cloneRef
50
+ }
51
+ }));
52
+ expect(origRef).toHaveBeenCalled();
53
+ expect(cloneRef).toHaveBeenCalled();
54
+ });
55
+ it('should preserve event handlers', () => {
56
+ const onClickA = jest.fn();
57
+ const onClickB = jest.fn();
58
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(SafeClone, {
59
+ element: /*#__PURE__*/_react.default.createElement("button", {
60
+ onClick: onClickA
61
+ }),
62
+ props: {
63
+ onClick: onClickB
64
+ }
65
+ }));
66
+ const button = _react2.screen.getByRole('button');
67
+ button.click();
68
+ expect(onClickA).toHaveBeenCalled();
69
+ expect(onClickB).toHaveBeenCalled();
70
+ });
71
+ it('should preserve already chained functions', () => {
72
+ const onClickA = jest.fn();
73
+ const onClickB = jest.fn();
74
+ const onClickC = jest.fn();
75
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(SafeClone, {
76
+ element: /*#__PURE__*/_react.default.createElement("button", {
77
+ onClick: onClickA
78
+ }),
79
+ props: {
80
+ onClick: (0, _createChainedFunction.createChainedFunction)(onClickB, onClickC)
81
+ }
82
+ }));
83
+ const button = _react2.screen.getByRole('button');
84
+ button.click();
85
+ expect(onClickA).toHaveBeenCalled();
86
+ expect(onClickB).toHaveBeenCalled();
87
+ expect(onClickC).toHaveBeenCalled();
88
+ });
89
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-react-utils",
3
- "version": "8.53.2",
3
+ "version": "8.53.3-pr-snapshot-8",
4
4
  "description": "A React utility library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -22,17 +22,18 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
- "@instructure/ui-babel-preset": "8.53.2",
26
- "@instructure/ui-test-utils": "8.53.2"
25
+ "@instructure/ui-babel-preset": "8.53.3-pr-snapshot-8",
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
31
  "@emotion/is-prop-valid": "^1.2.1",
31
- "@instructure/console": "8.53.2",
32
- "@instructure/shared-types": "8.53.2",
33
- "@instructure/ui-decorator": "8.53.2",
34
- "@instructure/ui-dom-utils": "8.53.2",
35
- "@instructure/ui-utils": "8.53.2",
32
+ "@instructure/console": "8.53.3-pr-snapshot-8",
33
+ "@instructure/shared-types": "8.53.3-pr-snapshot-8",
34
+ "@instructure/ui-decorator": "8.53.3-pr-snapshot-8",
35
+ "@instructure/ui-dom-utils": "8.53.3-pr-snapshot-8",
36
+ "@instructure/ui-utils": "8.53.3-pr-snapshot-8",
36
37
  "hoist-non-react-statics": "^3.3.2",
37
38
  "prop-types": "^15.8.1"
38
39
  },
@@ -0,0 +1,105 @@
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, { Component, ReactNode } from 'react'
26
+ import PropTypes from 'prop-types'
27
+
28
+ import { render } from '@testing-library/react'
29
+ import '@testing-library/jest-dom'
30
+
31
+ import { ComponentIdentifier } from '../ComponentIdentifier'
32
+
33
+ describe('ComponentIdentifier', () => {
34
+ beforeAll(() => {
35
+ // Mocking console warnings to prevent test output pollution
36
+ jest.spyOn(console, 'warn').mockImplementation(() => {})
37
+ })
38
+ afterAll(() => {
39
+ jest.restoreAllMocks()
40
+ })
41
+
42
+ class Trigger extends ComponentIdentifier<any> {
43
+ static displayName = 'Trigger'
44
+ }
45
+
46
+ class App extends Component<{ children: ReactNode }> {
47
+ static propTypes = {
48
+ children: PropTypes.node
49
+ }
50
+
51
+ static defaultProps = {
52
+ children: null
53
+ }
54
+
55
+ render() {
56
+ const trigger = ComponentIdentifier.pick(Trigger, this.props.children)
57
+
58
+ return (
59
+ <div>
60
+ <h2>Trigger</h2>
61
+ {trigger}
62
+ </div>
63
+ )
64
+ }
65
+ }
66
+
67
+ it('should render only child', () => {
68
+ let buttonRef: HTMLButtonElement
69
+ render(
70
+ <App>
71
+ <Trigger>
72
+ <button ref={(el) => (buttonRef = el!)}>Click Me</button>
73
+ </Trigger>
74
+ </App>
75
+ )
76
+
77
+ expect(buttonRef!.textContent).toEqual('Click Me')
78
+ })
79
+
80
+ it('should not error when no children provided', () => {
81
+ const renderApp = () =>
82
+ render(
83
+ <App>
84
+ <Trigger />
85
+ </App>
86
+ )
87
+
88
+ expect(renderApp).not.toThrow()
89
+ })
90
+
91
+ it('should pass props', () => {
92
+ let buttonRef: HTMLButtonElement | null
93
+ const onClick = jest.fn()
94
+ render(
95
+ <App>
96
+ <Trigger onClick={onClick}>
97
+ <button ref={(el) => (buttonRef = el)}>Click Me</button>
98
+ </Trigger>
99
+ </App>
100
+ )
101
+
102
+ buttonRef!.click()
103
+ expect(onClick).toHaveBeenCalled()
104
+ })
105
+ })