@instructure/ui-react-utils 10.19.2-snapshot-3 → 10.19.2-snapshot-5

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 (53) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +7 -7
  3. package/tsconfig.build.tsbuildinfo +1 -1
  4. package/es/__new-tests__/DeterministicIdContext.test.js +0 -109
  5. package/es/__new-tests__/callRenderProp.test.js +0 -138
  6. package/es/__new-tests__/deprecated.test.js +0 -237
  7. package/es/__new-tests__/experimental.test.js +0 -98
  8. package/es/__new-tests__/getInteraction.test.js +0 -117
  9. package/es/__new-tests__/hack.test.js +0 -70
  10. package/es/__new-tests__/omitProps.test.js +0 -91
  11. package/es/__new-tests__/passthroughProps.test.js +0 -100
  12. package/es/__new-tests__/pickProps.test.js +0 -95
  13. package/es/__new-tests__/safeCloneElement.test.js +0 -87
  14. package/lib/__new-tests__/DeterministicIdContext.test.js +0 -110
  15. package/lib/__new-tests__/callRenderProp.test.js +0 -140
  16. package/lib/__new-tests__/deprecated.test.js +0 -240
  17. package/lib/__new-tests__/experimental.test.js +0 -101
  18. package/lib/__new-tests__/getInteraction.test.js +0 -119
  19. package/lib/__new-tests__/hack.test.js +0 -73
  20. package/lib/__new-tests__/omitProps.test.js +0 -94
  21. package/lib/__new-tests__/passthroughProps.test.js +0 -102
  22. package/lib/__new-tests__/pickProps.test.js +0 -98
  23. package/lib/__new-tests__/safeCloneElement.test.js +0 -89
  24. package/src/__new-tests__/DeterministicIdContext.test.tsx +0 -140
  25. package/src/__new-tests__/callRenderProp.test.tsx +0 -136
  26. package/src/__new-tests__/deprecated.test.tsx +0 -358
  27. package/src/__new-tests__/experimental.test.tsx +0 -139
  28. package/src/__new-tests__/getInteraction.test.tsx +0 -119
  29. package/src/__new-tests__/hack.test.tsx +0 -91
  30. package/src/__new-tests__/omitProps.test.tsx +0 -113
  31. package/src/__new-tests__/passthroughProps.test.tsx +0 -100
  32. package/src/__new-tests__/pickProps.test.tsx +0 -111
  33. package/src/__new-tests__/safeCloneElement.test.tsx +0 -96
  34. package/types/__new-tests__/DeterministicIdContext.test.d.ts +0 -2
  35. package/types/__new-tests__/DeterministicIdContext.test.d.ts.map +0 -1
  36. package/types/__new-tests__/callRenderProp.test.d.ts +0 -2
  37. package/types/__new-tests__/callRenderProp.test.d.ts.map +0 -1
  38. package/types/__new-tests__/deprecated.test.d.ts +0 -2
  39. package/types/__new-tests__/deprecated.test.d.ts.map +0 -1
  40. package/types/__new-tests__/experimental.test.d.ts +0 -2
  41. package/types/__new-tests__/experimental.test.d.ts.map +0 -1
  42. package/types/__new-tests__/getInteraction.test.d.ts +0 -2
  43. package/types/__new-tests__/getInteraction.test.d.ts.map +0 -1
  44. package/types/__new-tests__/hack.test.d.ts +0 -2
  45. package/types/__new-tests__/hack.test.d.ts.map +0 -1
  46. package/types/__new-tests__/omitProps.test.d.ts +0 -2
  47. package/types/__new-tests__/omitProps.test.d.ts.map +0 -1
  48. package/types/__new-tests__/passthroughProps.test.d.ts +0 -2
  49. package/types/__new-tests__/passthroughProps.test.d.ts.map +0 -1
  50. package/types/__new-tests__/pickProps.test.d.ts +0 -2
  51. package/types/__new-tests__/pickProps.test.d.ts.map +0 -1
  52. package/types/__new-tests__/safeCloneElement.test.d.ts +0 -2
  53. package/types/__new-tests__/safeCloneElement.test.d.ts.map +0 -1
@@ -1,117 +0,0 @@
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 '@testing-library/jest-dom';
26
- import { getInteraction } from '../getInteraction';
27
- describe('getInteraction', () => {
28
- it("should return 'enabled' when `interaction`, `disabled`, and `readOnly` are not provided", () => {
29
- const props = {
30
- foo: 'foo',
31
- bar: 'bar'
32
- };
33
- expect(getInteraction({
34
- props
35
- })).toEqual('enabled');
36
- });
37
- it('should return `interaction` value when `interaction` is specified', () => {
38
- const props = {
39
- interaction: 'enabled'
40
- };
41
- expect(getInteraction({
42
- props
43
- })).toEqual('enabled');
44
- props.interaction = 'disabled';
45
- expect(getInteraction({
46
- props
47
- })).toEqual('disabled');
48
- props.interaction = 'readonly';
49
- expect(getInteraction({
50
- props
51
- })).toEqual('readonly');
52
- });
53
- it('should give preference to interaction even when disabled and readonly are also specified', () => {
54
- const props = {
55
- interaction: 'enabled',
56
- disabled: true,
57
- readOnly: true
58
- };
59
- expect(getInteraction({
60
- props
61
- })).toEqual('enabled');
62
- props.disabled = false;
63
- props.interaction = 'disabled';
64
- expect(getInteraction({
65
- props
66
- })).toEqual('disabled');
67
- props.readOnly = false;
68
- props.interaction = 'readonly';
69
- expect(getInteraction({
70
- props
71
- })).toEqual('readonly');
72
- });
73
- it("should return 'disabled' when `disabled` prop is set and `interaction` is not specified", () => {
74
- const props = {
75
- disabled: true
76
- };
77
- expect(getInteraction({
78
- props
79
- })).toEqual('disabled');
80
- });
81
- it("should return 'disabled' when both `disabled` and `readonly` props are set and `interaction` is not specified", () => {
82
- const props = {
83
- disabled: true,
84
- readOnly: true
85
- };
86
- expect(getInteraction({
87
- props
88
- })).toEqual('disabled');
89
- });
90
- it("should return 'readonly' when `readonly` prop is set and `interaction` and `disabled` are not specified", () => {
91
- const props = {
92
- disabled: true
93
- };
94
- expect(getInteraction({
95
- props
96
- })).toEqual('disabled');
97
- });
98
- it('should not include `disabled` if it is not listed in the interactionTypes', () => {
99
- const props = {
100
- disabled: true,
101
- readOnly: true
102
- };
103
- expect(getInteraction({
104
- props,
105
- interactionTypes: ['readonly']
106
- })).toEqual('readonly');
107
- });
108
- it('should not include `readonly` if it is not listed in the interactionTypes', () => {
109
- const props = {
110
- readOnly: true
111
- };
112
- expect(getInteraction({
113
- props,
114
- interactionTypes: ['disabled']
115
- })).toEqual('enabled');
116
- });
117
- });
@@ -1,70 +0,0 @@
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 { Component } from 'react';
26
- import { vi } from 'vitest';
27
- import PropTypes from 'prop-types';
28
- import { render } from '@testing-library/react';
29
- import '@testing-library/jest-dom';
30
- import { hack } from '../hack';
31
- import { jsxs as _jsxs, jsx as _jsx } from "@emotion/react/jsx-runtime";
32
- class TestComponent extends Component {
33
- render() {
34
- return _jsxs("div", {
35
- children: [this.props.qux, " ", this.props.bar]
36
- });
37
- }
38
- }
39
- TestComponent.displayName = "TestComponent";
40
- TestComponent.propTypes = {
41
- bar: PropTypes.string,
42
- qux: PropTypes.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 = hack(['bar'])(TestComponent);
52
- it('should warn when using an hack prop', () => {
53
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
54
- render(_HackComponent || (_HackComponent = _jsx(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 = vi.spyOn(console, 'warn').mockImplementation(() => {});
63
- render(_HackComponent2 || (_HackComponent2 = _jsx(HackComponent, {
64
- qux: "Jane"
65
- })));
66
- expect(consoleWarningSpy).not.toHaveBeenCalled();
67
- consoleWarningSpy.mockRestore();
68
- });
69
- });
70
- });
@@ -1,91 +0,0 @@
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 PropTypes from 'prop-types';
26
- import '@testing-library/jest-dom';
27
- import { omitProps } from '../omitProps';
28
- describe('omitProps', () => {
29
- it('should work with PropTypes', () => {
30
- const propTypes = {
31
- prop1: PropTypes.string.isRequired,
32
- prop2: PropTypes.number
33
- };
34
- const inputProps = {
35
- prop1: 'hello',
36
- prop2: 42,
37
- excessiveProp: 'excessiveValue'
38
- };
39
- const expectedResult = {
40
- excessiveProp: 'excessiveValue'
41
- };
42
- const actualResult = omitProps(inputProps, propTypes);
43
- expect(actualResult).toEqual(expectedResult);
44
- });
45
- it('should work with PropTypes and exclude the given keys', () => {
46
- const propTypes = {
47
- prop1: PropTypes.string.isRequired,
48
- prop2: PropTypes.number
49
- };
50
- const inputProps = {
51
- prop1: 'hello',
52
- prop2: 42,
53
- excessiveProp1: 'excessiveValue1',
54
- excessiveProp2: 'excessiveValue2'
55
- };
56
- const expectedResult = {
57
- excessiveProp2: 'excessiveValue2'
58
- };
59
- const actualResult = omitProps(inputProps, propTypes, ['excessiveProp1']);
60
- expect(actualResult).toEqual(expectedResult);
61
- });
62
- it('should work with an input of a list allowed prop names', () => {
63
- const allowedPropKeys = ['prop1', 'prop2'];
64
- const inputProps = {
65
- prop1: 'hello',
66
- prop2: 42,
67
- excessiveProp1: 'excessiveValue1',
68
- excessiveProp2: 'excessiveValue2'
69
- };
70
- const expectedResult = {
71
- excessiveProp1: 'excessiveValue1',
72
- excessiveProp2: 'excessiveValue2'
73
- };
74
- const actualResult = omitProps(inputProps, allowedPropKeys);
75
- expect(actualResult).toEqual(expectedResult);
76
- });
77
- it('should work with an input of a list allowed prop names and exclude the given keys', () => {
78
- const allowedPropKeys = ['prop1', 'prop2'];
79
- const inputProps = {
80
- prop1: 'hello',
81
- prop2: 42,
82
- excessiveProp1: 'excessiveValue1',
83
- excessiveProp2: 'excessiveValue2'
84
- };
85
- const expectedResult = {
86
- excessiveProp2: 'excessiveValue2'
87
- };
88
- const actualResult = omitProps(inputProps, allowedPropKeys, ['excessiveProp1']);
89
- expect(actualResult).toEqual(expectedResult);
90
- });
91
- });
@@ -1,100 +0,0 @@
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 '@testing-library/jest-dom';
26
- import { passthroughProps } from '../passthroughProps';
27
- describe('passthroughProps', () => {
28
- it('should passthrough standard dom attributes', () => {
29
- const props = {
30
- id: 'myId',
31
- title: 'My title'
32
- };
33
- expect(Object.keys(passthroughProps(props)).length).toEqual(2);
34
- });
35
- it('should passthrough data attributes', () => {
36
- const props = {
37
- 'data-test': true
38
- };
39
- expect(Object.keys(passthroughProps(props)).length).toEqual(1);
40
- });
41
- it('should passthrough valid react props', () => {
42
- const props = {
43
- ref: () => {},
44
- innerHTML: '<span>hello world</span>'
45
- };
46
- expect(Object.keys(passthroughProps(props)).length).toEqual(2);
47
- });
48
- it('should passthrough props prefixed with "on"', () => {
49
- const props = {
50
- onClick: () => {},
51
- onCustomCallback: () => {},
52
- onChange: () => {}
53
- };
54
- expect(Object.keys(passthroughProps(props)).length).toEqual(3);
55
- });
56
- it('should omit invalid props', () => {
57
- const props = {
58
- myCustomProp: 'hello'
59
- };
60
- expect(Object.keys(passthroughProps(props)).length).toEqual(0);
61
- });
62
- it('should omit certain react props', () => {
63
- const props = {
64
- style: {
65
- color: 'blue'
66
- },
67
- className: 'myClass',
68
- children: 'hello world',
69
- theme: {
70
- themeVar: 'myColor'
71
- }
72
- };
73
- expect(Object.keys(passthroughProps(props)).length).toEqual(0);
74
- });
75
- it('should passthrough and omit correct props', () => {
76
- const props = {
77
- id: 'myId',
78
- title: 'My title',
79
- 'data-test': true,
80
- className: 'myClassName',
81
- children: 'hello world',
82
- style: {
83
- color: 'blue'
84
- },
85
- theme: {
86
- themeVar: 'myColor'
87
- },
88
- withSomething: false,
89
- onCustomCallback: null,
90
- onChange: null
91
- };
92
- expect(passthroughProps(props)).toEqual({
93
- id: 'myId',
94
- title: 'My title',
95
- 'data-test': true,
96
- onCustomCallback: null,
97
- onChange: null
98
- });
99
- });
100
- });
@@ -1,95 +0,0 @@
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 PropTypes from 'prop-types';
26
- import '@testing-library/jest-dom';
27
- import { pickProps } from '../pickProps';
28
- describe('pickProps', () => {
29
- it('should work with propTypes', () => {
30
- const propTypes = {
31
- prop1: PropTypes.string.isRequired,
32
- prop2: PropTypes.number
33
- };
34
- const inputProps = {
35
- prop1: 'hello',
36
- prop2: 42,
37
- excessiveProp: 'excessiveValue'
38
- };
39
- const expectedResult = {
40
- prop1: 'hello',
41
- prop2: 42
42
- };
43
- const actualResult = pickProps(inputProps, propTypes);
44
- expect(actualResult).toEqual(expectedResult);
45
- });
46
- it('should add the `include` keys to the result with PropTypes', () => {
47
- const propTypes = {
48
- prop1: PropTypes.string.isRequired,
49
- prop2: PropTypes.number
50
- };
51
- const inputProps = {
52
- prop1: 'hello',
53
- prop2: 42,
54
- excessiveProp1: 'excessiveValue1',
55
- excessiveProp2: 'excessiveValue2'
56
- };
57
- const expectedResult = {
58
- prop1: 'hello',
59
- prop2: 42,
60
- excessiveProp2: 'excessiveValue2'
61
- };
62
- const actualResult = pickProps(inputProps, propTypes, ['excessiveProp2']);
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
- };
72
- const expectedResult = {
73
- prop1: 'hello',
74
- prop2: 42
75
- };
76
- const actualResult = pickProps(inputProps, allowedPropKeys);
77
- expect(actualResult).toEqual(expectedResult);
78
- });
79
- it('should add the `include` keys to the result with a list allowed prop names', () => {
80
- const allowedPropKeys = ['prop1', 'prop2'];
81
- const inputProps = {
82
- prop1: 'hello',
83
- prop2: 42,
84
- excessiveProp1: 'excessiveValue1',
85
- excessiveProp2: 'excessiveValue2'
86
- };
87
- const expectedResult = {
88
- prop1: 'hello',
89
- prop2: 42,
90
- excessiveProp2: 'excessiveValue2'
91
- };
92
- const actualResult = pickProps(inputProps, allowedPropKeys, ['excessiveProp2']);
93
- expect(actualResult).toEqual(expectedResult);
94
- });
95
- });
@@ -1,87 +0,0 @@
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 { vi } from 'vitest';
26
- import { createChainedFunction } from '@instructure/ui-utils';
27
- import { render, screen } from '@testing-library/react';
28
- import '@testing-library/jest-dom';
29
- import { safeCloneElement } from '../safeCloneElement';
30
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
31
- describe('safeCloneElement', () => {
32
- const SafeClone = function ({
33
- element,
34
- props,
35
- children
36
- }) {
37
- return safeCloneElement(element, props, children);
38
- };
39
- it('should preserve refs', () => {
40
- const origRef = vi.fn();
41
- const cloneRef = vi.fn();
42
- render(_jsx(SafeClone, {
43
- element: _jsx("div", {
44
- ref: origRef
45
- }),
46
- props: {
47
- ref: cloneRef
48
- }
49
- }));
50
- expect(origRef).toHaveBeenCalled();
51
- expect(cloneRef).toHaveBeenCalled();
52
- });
53
- it('should preserve event handlers', () => {
54
- const onClickA = vi.fn();
55
- const onClickB = vi.fn();
56
- render(_jsx(SafeClone, {
57
- element: _jsx("button", {
58
- onClick: onClickA
59
- }),
60
- props: {
61
- onClick: onClickB
62
- }
63
- }));
64
- const button = screen.getByRole('button');
65
- button.click();
66
- expect(onClickA).toHaveBeenCalled();
67
- expect(onClickB).toHaveBeenCalled();
68
- });
69
- it('should preserve already chained functions', () => {
70
- const onClickA = vi.fn();
71
- const onClickB = vi.fn();
72
- const onClickC = vi.fn();
73
- render(_jsx(SafeClone, {
74
- element: _jsx("button", {
75
- onClick: onClickA
76
- }),
77
- props: {
78
- onClick: createChainedFunction(onClickB, onClickC)
79
- }
80
- }));
81
- const button = screen.getByRole('button');
82
- button.click();
83
- expect(onClickA).toHaveBeenCalled();
84
- expect(onClickB).toHaveBeenCalled();
85
- expect(onClickC).toHaveBeenCalled();
86
- });
87
- });
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("react");
4
- var _react2 = require("@testing-library/react");
5
- require("@testing-library/jest-dom");
6
- var _DeterministicIdContext = require("../DeterministicIdContext");
7
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
8
- var _dec, _class, _TestComponent, _div, _WrapperComponent2, _div2, _div3, _div4;
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
- let TestComponent = (_dec = (0, _DeterministicIdContext.withDeterministicId)(), _dec(_class = (_TestComponent = class TestComponent extends _react.Component {
33
- render() {
34
- return (0, _jsxRuntime.jsx)("div", {
35
- "data-testid": "test-component",
36
- id: this.props.deterministicId(),
37
- children: this.props.children
38
- });
39
- }
40
- }, _TestComponent.displayName = "TestComponent", _TestComponent)) || _class);
41
- class WrapperComponent extends _react.Component {
42
- render() {
43
- return _div || (_div = (0, _jsxRuntime.jsx)("div", {
44
- children: (0, _jsxRuntime.jsx)(TestComponent, {})
45
- }));
46
- }
47
- }
48
- WrapperComponent.displayName = "WrapperComponent";
49
- const uniqueIds = el => {
50
- const idList = Array.from(el.children).map(child => child.id);
51
- return new Set(idList).size === idList.length;
52
- };
53
- describe('DeterministicIdContext', () => {
54
- it('can be found and tested with ReactTestUtils', () => {
55
- (0, _react2.render)(_WrapperComponent2 || (_WrapperComponent2 = (0, _jsxRuntime.jsx)(WrapperComponent, {})));
56
- const testComponent = _react2.screen.getByTestId('test-component');
57
- expect(testComponent).toBeInTheDocument();
58
- expect(testComponent.id).toBeDefined();
59
- });
60
- it('should generate unique ids without Provider wrapper', () => {
61
- (0, _react2.render)(_div2 || (_div2 = (0, _jsxRuntime.jsxs)("div", {
62
- "data-testid": "test-components",
63
- children: [(0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {})]
64
- })));
65
- const el = _react2.screen.getByTestId('test-components');
66
- expect(uniqueIds(el)).toBe(true);
67
- });
68
- it('should generate unique ids when components are rendered both out and inside of provider', () => {
69
- (0, _react2.render)(_div3 || (_div3 = (0, _jsxRuntime.jsxs)("div", {
70
- "data-testid": "test-components",
71
- children: [(0, _jsxRuntime.jsxs)(_DeterministicIdContext.DeterministicIdContextProvider, {
72
- children: [(0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {})]
73
- }), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {})]
74
- })));
75
- const el = _react2.screen.getByTestId('test-components');
76
- expect(uniqueIds(el)).toBe(true);
77
- });
78
- it('should generate unique ids with provider only', () => {
79
- const Wrapper = ({
80
- children
81
- }) => {
82
- return (0, _jsxRuntime.jsx)(_DeterministicIdContext.DeterministicIdContextProvider, {
83
- children: (0, _jsxRuntime.jsx)("div", {
84
- "data-testid": "wrapper",
85
- children: children
86
- })
87
- });
88
- };
89
- const children = [];
90
- for (let i = 0; i < 10; i++) {
91
- children.push((0, _jsxRuntime.jsx)(TestComponent, {}, i));
92
- }
93
- (0, _react2.render)((0, _jsxRuntime.jsx)(Wrapper, {
94
- children: children
95
- }));
96
- const el = _react2.screen.getByTestId('wrapper');
97
- expect(uniqueIds(el)).toBe(true);
98
- });
99
- it('should use a global object for ID counter', () => {
100
- const instUIInstanceCounter = '__INSTUI_GLOBAL_INSTANCE_COUNTER__';
101
- const counterValue = 345;
102
- globalThis[instUIInstanceCounter].set('TestComponent', counterValue);
103
- (0, _react2.render)(_div4 || (_div4 = (0, _jsxRuntime.jsxs)("div", {
104
- "data-testid": "test-components",
105
- children: [(0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {}), (0, _jsxRuntime.jsx)(TestComponent, {})]
106
- })));
107
- const instanceCounter = globalThis[instUIInstanceCounter];
108
- expect(instanceCounter.get('TestComponent')).toBe(counterValue + 5);
109
- });
110
- });