@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,109 +0,0 @@
1
- var _dec, _class, _TestComponent, _div, _WrapperComponent2, _div2, _div3, _div4;
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 { Component } from 'react';
27
- import { render, screen } from '@testing-library/react';
28
- import '@testing-library/jest-dom';
29
- import { withDeterministicId, DeterministicIdContextProvider } from '../DeterministicIdContext';
30
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
31
- let TestComponent = (_dec = withDeterministicId(), _dec(_class = (_TestComponent = class TestComponent extends Component {
32
- render() {
33
- return _jsx("div", {
34
- "data-testid": "test-component",
35
- id: this.props.deterministicId(),
36
- children: this.props.children
37
- });
38
- }
39
- }, _TestComponent.displayName = "TestComponent", _TestComponent)) || _class);
40
- class WrapperComponent extends Component {
41
- render() {
42
- return _div || (_div = _jsx("div", {
43
- children: _jsx(TestComponent, {})
44
- }));
45
- }
46
- }
47
- WrapperComponent.displayName = "WrapperComponent";
48
- const uniqueIds = el => {
49
- const idList = Array.from(el.children).map(child => child.id);
50
- return new Set(idList).size === idList.length;
51
- };
52
- describe('DeterministicIdContext', () => {
53
- it('can be found and tested with ReactTestUtils', () => {
54
- render(_WrapperComponent2 || (_WrapperComponent2 = _jsx(WrapperComponent, {})));
55
- const testComponent = screen.getByTestId('test-component');
56
- expect(testComponent).toBeInTheDocument();
57
- expect(testComponent.id).toBeDefined();
58
- });
59
- it('should generate unique ids without Provider wrapper', () => {
60
- render(_div2 || (_div2 = _jsxs("div", {
61
- "data-testid": "test-components",
62
- children: [_jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {})]
63
- })));
64
- const el = screen.getByTestId('test-components');
65
- expect(uniqueIds(el)).toBe(true);
66
- });
67
- it('should generate unique ids when components are rendered both out and inside of provider', () => {
68
- render(_div3 || (_div3 = _jsxs("div", {
69
- "data-testid": "test-components",
70
- children: [_jsxs(DeterministicIdContextProvider, {
71
- children: [_jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {})]
72
- }), _jsx(TestComponent, {}), _jsx(TestComponent, {})]
73
- })));
74
- const el = screen.getByTestId('test-components');
75
- expect(uniqueIds(el)).toBe(true);
76
- });
77
- it('should generate unique ids with provider only', () => {
78
- const Wrapper = ({
79
- children
80
- }) => {
81
- return _jsx(DeterministicIdContextProvider, {
82
- children: _jsx("div", {
83
- "data-testid": "wrapper",
84
- children: children
85
- })
86
- });
87
- };
88
- const children = [];
89
- for (let i = 0; i < 10; i++) {
90
- children.push(_jsx(TestComponent, {}, i));
91
- }
92
- render(_jsx(Wrapper, {
93
- children: children
94
- }));
95
- const el = screen.getByTestId('wrapper');
96
- expect(uniqueIds(el)).toBe(true);
97
- });
98
- it('should use a global object for ID counter', () => {
99
- const instUIInstanceCounter = '__INSTUI_GLOBAL_INSTANCE_COUNTER__';
100
- const counterValue = 345;
101
- globalThis[instUIInstanceCounter].set('TestComponent', counterValue);
102
- render(_div4 || (_div4 = _jsxs("div", {
103
- "data-testid": "test-components",
104
- children: [_jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {}), _jsx(TestComponent, {})]
105
- })));
106
- const instanceCounter = globalThis[instUIInstanceCounter];
107
- expect(instanceCounter.get('TestComponent')).toBe(counterValue + 5);
108
- });
109
- });
@@ -1,138 +0,0 @@
1
- var _div, _div2;
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 { Component } from 'react';
27
- import PropTypes from 'prop-types';
28
- import { render } from '@testing-library/react';
29
- import '@testing-library/jest-dom';
30
- import { callRenderProp } from '../callRenderProp';
31
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
- describe('callRenderProp', () => {
33
- it('strings', () => {
34
- expect(callRenderProp('foo')).toEqual('foo');
35
- });
36
- it('numbers', () => {
37
- expect(callRenderProp(2)).toEqual(2);
38
- });
39
- it('arrays', () => {
40
- const prop = ['foo', 'bar', 'baz'];
41
- expect(callRenderProp(prop)).toStrictEqual(prop);
42
- expect(callRenderProp([])).toStrictEqual([]);
43
- });
44
- it('booleans', () => {
45
- expect(callRenderProp(false)).toEqual(false);
46
- });
47
- it('JSX literals', () => {
48
- const Foo = () => _div || (_div = _jsx("div", {
49
- children: "hello"
50
- }));
51
- expect(callRenderProp(_jsx(Foo, {}))).toStrictEqual(_jsx(Foo, {}));
52
- });
53
- it('React classes', () => {
54
- class Foo extends Component {
55
- render() {
56
- return _div2 || (_div2 = _jsx("div", {
57
- children: "hello"
58
- }));
59
- }
60
- }
61
- Foo.displayName = "Foo";
62
- const Result = callRenderProp(Foo);
63
- expect(Result).toStrictEqual(_jsx(Foo, {}));
64
- const _render = render(Result),
65
- getByText = _render.getByText;
66
- expect(getByText('hello')).toBeInTheDocument();
67
- });
68
- it('functions', () => {
69
- const Baz = function () {
70
- return 'some text';
71
- };
72
- const result = callRenderProp(Baz);
73
- const _render2 = render(_jsx("div", {
74
- children: result
75
- })),
76
- getByText = _render2.getByText;
77
- expect(getByText('some text')).toBeInTheDocument();
78
- });
79
- it('fat arrow functions', () => {
80
- const Baz = () => 'some text';
81
-
82
- // in this test we are trying to test that it works with fat arrow functions,
83
- // but the babel config when we run these tests is currently configured
84
- // to transpile fat arrow functions down to normal functions.
85
- // Real, untranspiled, fat-arrow functions don't have a `prototype` but when
86
- // they are transpiled down they do. So this next line is to make sure
87
- // the thing we are testing really doesn't have a prototype like it would
88
- // if it was a real untranspiled fat arrow function.
89
- if (Baz.prototype) Baz.prototype = void 0;
90
- const result = callRenderProp(Baz);
91
- const _render3 = render(_jsx("div", {
92
- children: result
93
- })),
94
- getByText = _render3.getByText;
95
- expect(getByText('some text')).toBeInTheDocument();
96
- });
97
- describe('passing props', () => {
98
- it('should pass props correctly to functions', () => {
99
- const someFunc = ({
100
- shape
101
- }) => _jsx("div", {
102
- children: shape
103
- });
104
- const result = callRenderProp(someFunc, {
105
- shape: 'rectangle'
106
- });
107
- const _render4 = render(_jsx("div", {
108
- children: result
109
- })),
110
- getByText = _render4.getByText;
111
- expect(getByText('rectangle')).toBeInTheDocument();
112
- });
113
- it('should pass props correctly to React classes', () => {
114
- class Foo extends Component {
115
- render() {
116
- return _jsx("div", {
117
- children: this.props.shape
118
- });
119
- }
120
- }
121
- Foo.displayName = "Foo";
122
- Foo.propTypes = {
123
- shape: PropTypes.oneOf(['circle', 'rectangle'])
124
- };
125
- Foo.defaultProps = {
126
- shape: 'circle'
127
- };
128
- const result = callRenderProp(Foo, {
129
- shape: 'rectangle'
130
- });
131
- const _render5 = render(_jsx("div", {
132
- children: result
133
- })),
134
- getByText = _render5.getByText;
135
- expect(getByText('rectangle')).toBeInTheDocument();
136
- });
137
- });
138
- });
@@ -1,237 +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 { deprecated } from '../deprecated';
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: null,
46
- qux: 'Hello'
47
- };
48
- describe('@deprecated', () => {
49
- describe('deprecated props', () => {
50
- var _DeprecatedComponent, _DeprecatedComponent2, _DeprecatedComponent3;
51
- const DeprecatedComponent = deprecated('2.1.0', {
52
- foo: 'bar',
53
- baz: true
54
- })(TestComponent);
55
- it('should warn when suggesting new prop when using old prop', () => {
56
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
57
- render(_DeprecatedComponent || (_DeprecatedComponent = _jsx(DeprecatedComponent, {
58
- foo: "Jane"
59
- })));
60
- const expectedWarningMessage = 'Warning: [TestComponent] `foo` is deprecated and will be removed in version 2.1.0. Use `bar` instead. ';
61
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
62
- consoleWarningSpy.mockRestore();
63
- });
64
- it('should warn when using old prop with no new prop', () => {
65
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
66
- render(_DeprecatedComponent2 || (_DeprecatedComponent2 = _jsx(DeprecatedComponent, {
67
- baz: "Goodbye"
68
- })));
69
- const expectedWarningMessage = 'Warning: [TestComponent] `baz` is deprecated and will be removed in version 2.1.0.';
70
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
71
- consoleWarningSpy.mockRestore();
72
- });
73
- it('should not output a warning using new prop', () => {
74
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
75
- render(_DeprecatedComponent3 || (_DeprecatedComponent3 = _jsx(DeprecatedComponent, {
76
- bar: "Jane"
77
- })));
78
- expect(consoleWarningSpy).not.toHaveBeenCalled();
79
- consoleWarningSpy.mockRestore();
80
- });
81
- });
82
- describe('deprecated component', () => {
83
- var _DeprecatedComponent4;
84
- const DeprecatedComponent = deprecated('3.4.0')(TestComponent);
85
- it('should warn that the entire component is deprecated if no old props are supplied', () => {
86
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
87
- render(_DeprecatedComponent4 || (_DeprecatedComponent4 = _jsx(DeprecatedComponent, {})));
88
- const expectedWarningMessage = 'Warning: [TestComponent] is deprecated and will be removed in version 3.4.0.';
89
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
90
- consoleWarningSpy.mockRestore();
91
- });
92
- });
93
- describe('deprecated component with a changed package message', () => {
94
- var _DeprecatedComponent5;
95
- const DeprecatedComponent = deprecated('5.0.0', null, deprecated.changedPackageWarning('ui-forms', 'ui-number-input'))(TestComponent);
96
- it('should warn that the component is deprecated and output a warning that the package changed', () => {
97
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
98
- const expectedWarningMessage = 'Warning: [TestComponent] is deprecated and will be removed in version 5.0.0. It has been moved from @instructure/ui-forms to @instructure/ui-number-input.';
99
- render(_DeprecatedComponent5 || (_DeprecatedComponent5 = _jsx(DeprecatedComponent, {})));
100
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
101
- consoleWarningSpy.mockRestore();
102
- });
103
- });
104
- describe('component with deprecated prop values', () => {
105
- it('should not warn when an allowed prop value is supplied', () => {
106
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
107
- class DeprecatedPropValueComponent extends Component {
108
- render() {
109
- return _jsx("div", {
110
- children: this.props.color
111
- });
112
- }
113
- }
114
- DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
115
- DeprecatedPropValueComponent.propTypes = {
116
- color: deprecated.deprecatePropValues(PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'])
117
- };
118
- DeprecatedPropValueComponent.defaultProps = {
119
- color: 'red'
120
- };
121
- render(_jsx(DeprecatedPropValueComponent, {
122
- color: "yellow"
123
- }));
124
- expect(consoleWarningSpy).not.toHaveBeenCalled();
125
- consoleWarningSpy.mockRestore();
126
- });
127
- it('should warn when a forbidden prop value is supplied', () => {
128
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
129
- const color = 'orange';
130
- class DeprecatedPropValueComponent extends Component {
131
- render() {
132
- return _jsx("div", {
133
- children: this.props.color
134
- });
135
- }
136
- }
137
- DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
138
- DeprecatedPropValueComponent.propTypes = {
139
- color: deprecated.deprecatePropValues(PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'])
140
- };
141
- DeprecatedPropValueComponent.defaultProps = {
142
- color: 'red'
143
- };
144
- render(_jsx(DeprecatedPropValueComponent, {
145
- color: color
146
- }));
147
- const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated.`;
148
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
149
- consoleWarningSpy.mockRestore();
150
- });
151
- it('should warn with additional message text when a forbidden prop value is supplied and has message text', () => {
152
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
153
- const color = 'gold';
154
- const message = 'It will be removed in v8.0.0.';
155
- class DeprecatedPropValueComponent extends Component {
156
- render() {
157
- return _jsx("div", {
158
- children: this.props.color
159
- });
160
- }
161
- }
162
- DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
163
- DeprecatedPropValueComponent.propTypes = {
164
- color: deprecated.deprecatePropValues(PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], 'It will be removed in v8.0.0.')
165
- };
166
- DeprecatedPropValueComponent.defaultProps = {
167
- color: 'red'
168
- };
169
- render(_jsx(DeprecatedPropValueComponent, {
170
- color: color
171
- }));
172
- const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated. ${message}`;
173
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
174
- consoleWarningSpy.mockRestore();
175
- });
176
- it('should call functional message with the correct props', () => {
177
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
178
- const messageMock = vi.fn();
179
- const color = 'gold';
180
- class DeprecatedPropValueComponent extends Component {
181
- render() {
182
- return _jsx("div", {
183
- children: this.props.color
184
- });
185
- }
186
- }
187
- DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
188
- DeprecatedPropValueComponent.propTypes = {
189
- color: deprecated.deprecatePropValues(PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], messageMock)
190
- };
191
- DeprecatedPropValueComponent.defaultProps = {
192
- color: 'red'
193
- };
194
- render(_jsx(DeprecatedPropValueComponent, {
195
- color: color
196
- }));
197
- const _messageMock$mock$cal = messageMock.mock.calls[0][0],
198
- props = _messageMock$mock$cal.props,
199
- propName = _messageMock$mock$cal.propName,
200
- propValue = _messageMock$mock$cal.propValue;
201
- expect(props).toEqual({
202
- color
203
- });
204
- expect(propName).toBe('color');
205
- expect(propValue).toBe(color);
206
- expect(consoleWarningSpy).toHaveBeenCalled();
207
- consoleWarningSpy.mockRestore();
208
- });
209
- it('should warn with a completely custom message when provided message is functional and prop value is forbidden', () => {
210
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
211
- const color = 'gold';
212
- class DeprecatedPropValueComponent extends Component {
213
- render() {
214
- return _jsx("div", {
215
- children: this.props.color
216
- });
217
- }
218
- }
219
- DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
220
- DeprecatedPropValueComponent.propTypes = {
221
- color: deprecated.deprecatePropValues(PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], ({
222
- propValue,
223
- propName
224
- }) => `The ${propValue} value for ${propName} has been deprecated. Use the FooBar component with the 'baz' prop set instead.`)
225
- };
226
- DeprecatedPropValueComponent.defaultProps = {
227
- color: 'red'
228
- };
229
- render(_jsx(DeprecatedPropValueComponent, {
230
- color: color
231
- }));
232
- const expectedWarningMessage = `The ${color} value for color has been deprecated. Use the FooBar component with the 'baz' prop set instead.`;
233
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
234
- consoleWarningSpy.mockRestore();
235
- });
236
- });
237
- });
@@ -1,98 +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 { experimental } from '../experimental';
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('@experimental', () => {
49
- describe('experimental props', () => {
50
- var _ExperimentalComponen, _ExperimentalComponen2, _ExperimentalComponen3;
51
- const ExperimentalComponent = experimental(['bar'])(TestComponent);
52
- it('should warn when using an experimental prop', () => {
53
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
54
- render(_ExperimentalComponen || (_ExperimentalComponen = _jsx(ExperimentalComponent, {
55
- bar: "Jane"
56
- })));
57
- const expectedWarningMessage = 'Warning: [TestComponent] The `bar` prop is experimental and its API could change significantly 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-experimental prop', () => {
62
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
63
- render(_ExperimentalComponen2 || (_ExperimentalComponen2 = _jsx(ExperimentalComponent, {
64
- qux: "Jane"
65
- })));
66
- expect(consoleWarningSpy).not.toHaveBeenCalled();
67
- consoleWarningSpy.mockRestore();
68
- });
69
- it('should not output a warning for an experimental prop when dangerously ignored', () => {
70
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
71
- render(_ExperimentalComponen3 || (_ExperimentalComponen3 = _jsx(ExperimentalComponent, {
72
- qux: "Jane",
73
- __dangerouslyIgnoreExperimentalWarnings: true
74
- })));
75
- expect(consoleWarningSpy).not.toHaveBeenCalled();
76
- consoleWarningSpy.mockRestore();
77
- });
78
- });
79
- describe('experimental component', () => {
80
- var _ExperimentalComponen4, _ExperimentalComponen5;
81
- const ExperimentalComponent = experimental()(TestComponent);
82
- it('should warn that the entire component is experimental if no props are supplied', () => {
83
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
84
- render(_ExperimentalComponen4 || (_ExperimentalComponen4 = _jsx(ExperimentalComponent, {})));
85
- const expectedWarningMessage = 'Warning: [TestComponent] is experimental and its API could change significantly in a future release.';
86
- expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
87
- consoleWarningSpy.mockRestore();
88
- });
89
- it('should not output a warning for a component when dangerously ignored', () => {
90
- const consoleWarningSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
91
- render(_ExperimentalComponen5 || (_ExperimentalComponen5 = _jsx(ExperimentalComponent, {
92
- __dangerouslyIgnoreExperimentalWarnings: true
93
- })));
94
- expect(consoleWarningSpy).not.toHaveBeenCalled();
95
- consoleWarningSpy.mockRestore();
96
- });
97
- });
98
- });