@instructure/ui-react-utils 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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,94 +0,0 @@
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
- });
@@ -1,102 +0,0 @@
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
- });
@@ -1,98 +0,0 @@
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
- });
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
5
- var _react = require("@testing-library/react");
6
- require("@testing-library/jest-dom");
7
- var _safeCloneElement = require("../safeCloneElement");
8
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
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 = _vitest.vi.fn();
43
- const cloneRef = _vitest.vi.fn();
44
- (0, _react.render)((0, _jsxRuntime.jsx)(SafeClone, {
45
- element: (0, _jsxRuntime.jsx)("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 = _vitest.vi.fn();
57
- const onClickB = _vitest.vi.fn();
58
- (0, _react.render)((0, _jsxRuntime.jsx)(SafeClone, {
59
- element: (0, _jsxRuntime.jsx)("button", {
60
- onClick: onClickA
61
- }),
62
- props: {
63
- onClick: onClickB
64
- }
65
- }));
66
- const button = _react.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 = _vitest.vi.fn();
73
- const onClickB = _vitest.vi.fn();
74
- const onClickC = _vitest.vi.fn();
75
- (0, _react.render)((0, _jsxRuntime.jsx)(SafeClone, {
76
- element: (0, _jsxRuntime.jsx)("button", {
77
- onClick: onClickA
78
- }),
79
- props: {
80
- onClick: (0, _createChainedFunction.createChainedFunction)(onClickB, onClickC)
81
- }
82
- }));
83
- const button = _react.screen.getByRole('button');
84
- button.click();
85
- expect(onClickA).toHaveBeenCalled();
86
- expect(onClickB).toHaveBeenCalled();
87
- expect(onClickC).toHaveBeenCalled();
88
- });
89
- });
@@ -1,140 +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
-
27
- import { render, screen } from '@testing-library/react'
28
- import '@testing-library/jest-dom'
29
-
30
- import {
31
- withDeterministicId,
32
- DeterministicIdContextProvider
33
- } from '../DeterministicIdContext'
34
- import type { WithDeterministicIdProps } from '../DeterministicIdContext'
35
-
36
- @withDeterministicId()
37
- class TestComponent extends Component<
38
- React.PropsWithChildren<WithDeterministicIdProps>
39
- > {
40
- render() {
41
- return (
42
- <div data-testid="test-component" id={this.props.deterministicId!()}>
43
- {this.props.children}
44
- </div>
45
- )
46
- }
47
- }
48
-
49
- class WrapperComponent extends Component {
50
- render() {
51
- return (
52
- <div>
53
- <TestComponent />
54
- </div>
55
- )
56
- }
57
- }
58
-
59
- const uniqueIds = (el: Element) => {
60
- const idList = Array.from(el.children).map((child) => child.id)
61
- return new Set(idList).size === idList.length
62
- }
63
-
64
- describe('DeterministicIdContext', () => {
65
- it('can be found and tested with ReactTestUtils', () => {
66
- render(<WrapperComponent />)
67
- const testComponent = screen.getByTestId('test-component')
68
-
69
- expect(testComponent).toBeInTheDocument()
70
- expect(testComponent.id).toBeDefined()
71
- })
72
-
73
- it('should generate unique ids without Provider wrapper', () => {
74
- render(
75
- <div data-testid="test-components">
76
- <TestComponent />
77
- <TestComponent />
78
- <TestComponent />
79
- <TestComponent />
80
- <TestComponent />
81
- </div>
82
- )
83
- const el = screen.getByTestId('test-components')
84
-
85
- expect(uniqueIds(el)).toBe(true)
86
- })
87
-
88
- it('should generate unique ids when components are rendered both out and inside of provider', () => {
89
- render(
90
- <div data-testid="test-components">
91
- <DeterministicIdContextProvider>
92
- <TestComponent />
93
- <TestComponent />
94
- <TestComponent />
95
- </DeterministicIdContextProvider>
96
- <TestComponent />
97
- <TestComponent />
98
- </div>
99
- )
100
- const el = screen.getByTestId('test-components')
101
-
102
- expect(uniqueIds(el)).toBe(true)
103
- })
104
-
105
- it('should generate unique ids with provider only', () => {
106
- const Wrapper = ({ children }: any) => {
107
- return (
108
- <DeterministicIdContextProvider>
109
- <div data-testid="wrapper">{children}</div>
110
- </DeterministicIdContextProvider>
111
- )
112
- }
113
- const children = []
114
- for (let i = 0; i < 10; i++) {
115
- children.push(<TestComponent key={i} />)
116
- }
117
-
118
- render(<Wrapper>{children}</Wrapper>)
119
- const el = screen.getByTestId('wrapper')
120
-
121
- expect(uniqueIds(el)).toBe(true)
122
- })
123
-
124
- it('should use a global object for ID counter', () => {
125
- const instUIInstanceCounter = '__INSTUI_GLOBAL_INSTANCE_COUNTER__'
126
- const counterValue = 345
127
- globalThis[instUIInstanceCounter].set('TestComponent', counterValue)
128
- render(
129
- <div data-testid="test-components">
130
- <TestComponent />
131
- <TestComponent />
132
- <TestComponent />
133
- <TestComponent />
134
- <TestComponent />
135
- </div>
136
- )
137
- const instanceCounter = globalThis[instUIInstanceCounter]
138
- expect(instanceCounter.get('TestComponent')).toBe(counterValue + 5)
139
- })
140
- })
@@ -1,136 +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 PropTypes from 'prop-types'
27
-
28
- import { render } from '@testing-library/react'
29
- import '@testing-library/jest-dom'
30
-
31
- import { callRenderProp } from '../callRenderProp'
32
-
33
- describe('callRenderProp', () => {
34
- it('strings', () => {
35
- expect(callRenderProp('foo')).toEqual('foo')
36
- })
37
-
38
- it('numbers', () => {
39
- expect(callRenderProp(2)).toEqual(2)
40
- })
41
-
42
- it('arrays', () => {
43
- const prop = ['foo', 'bar', 'baz']
44
-
45
- expect(callRenderProp(prop)).toStrictEqual(prop)
46
- expect(callRenderProp([])).toStrictEqual([])
47
- })
48
-
49
- it('booleans', () => {
50
- expect(callRenderProp(false)).toEqual(false)
51
- })
52
-
53
- it('JSX literals', () => {
54
- const Foo = () => <div>hello</div>
55
- expect(callRenderProp(<Foo />)).toStrictEqual(<Foo />)
56
- })
57
-
58
- it('React classes', () => {
59
- class Foo extends Component {
60
- render() {
61
- return <div>hello</div>
62
- }
63
- }
64
-
65
- const Result = callRenderProp(Foo)
66
- expect(Result).toStrictEqual(<Foo />)
67
-
68
- const { getByText } = render(Result)
69
- expect(getByText('hello')).toBeInTheDocument()
70
- })
71
-
72
- it('functions', () => {
73
- const Baz = function () {
74
- return 'some text'
75
- }
76
- const result = callRenderProp(Baz)
77
-
78
- const { getByText } = render(<div>{result}</div>)
79
-
80
- expect(getByText('some text')).toBeInTheDocument()
81
- })
82
-
83
- it('fat arrow functions', () => {
84
- const Baz = () => 'some text'
85
-
86
- // in this test we are trying to test that it works with fat arrow functions,
87
- // but the babel config when we run these tests is currently configured
88
- // to transpile fat arrow functions down to normal functions.
89
- // Real, untranspiled, fat-arrow functions don't have a `prototype` but when
90
- // they are transpiled down they do. So this next line is to make sure
91
- // the thing we are testing really doesn't have a prototype like it would
92
- // if it was a real untranspiled fat arrow function.
93
- if (Baz.prototype) Baz.prototype! = undefined
94
-
95
- const result = callRenderProp(Baz)
96
-
97
- const { getByText } = render(<div>{result}</div>)
98
-
99
- expect(getByText('some text')).toBeInTheDocument()
100
- })
101
-
102
- describe('passing props', () => {
103
- it('should pass props correctly to functions', () => {
104
- const someFunc = ({ shape }: { shape: string }) => <div>{shape}</div>
105
-
106
- const result = callRenderProp(someFunc, { shape: 'rectangle' })
107
-
108
- const { getByText } = render(<div>{result}</div>)
109
-
110
- expect(getByText('rectangle')).toBeInTheDocument()
111
- })
112
-
113
- it('should pass props correctly to React classes', () => {
114
- type FooProps = { shape?: string }
115
- class Foo extends Component<FooProps> {
116
- static propTypes = {
117
- shape: PropTypes.oneOf(['circle', 'rectangle'])
118
- }
119
-
120
- static defaultProps = {
121
- shape: 'circle'
122
- }
123
-
124
- render() {
125
- return <div>{this.props.shape}</div>
126
- }
127
- }
128
-
129
- const result = callRenderProp(Foo, { shape: 'rectangle' })
130
-
131
- const { getByText } = render(<div>{result}</div>)
132
-
133
- expect(getByText('rectangle')).toBeInTheDocument()
134
- })
135
- })
136
- })