@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.
- package/CHANGELOG.md +8 -0
- package/es/__new-tests__/ComponentIdentifier.test.js +77 -0
- package/es/__new-tests__/DeterministicIdContext.test.js +89 -0
- package/es/__new-tests__/callRenderProp.test.js +121 -0
- package/es/__new-tests__/deprecated.test.js +223 -0
- package/es/__new-tests__/experimental.test.js +94 -0
- package/es/__new-tests__/getInteraction.test.js +117 -0
- package/es/__new-tests__/hack.test.js +66 -0
- package/es/__new-tests__/omitProps.test.js +91 -0
- package/es/__new-tests__/passthroughProps.test.js +100 -0
- package/es/__new-tests__/pickProps.test.js +95 -0
- package/es/__new-tests__/safeCloneElement.test.js +86 -0
- package/lib/__new-tests__/ComponentIdentifier.test.js +80 -0
- package/lib/__new-tests__/DeterministicIdContext.test.js +91 -0
- package/lib/__new-tests__/callRenderProp.test.js +123 -0
- package/lib/__new-tests__/deprecated.test.js +227 -0
- package/lib/__new-tests__/experimental.test.js +98 -0
- package/lib/__new-tests__/getInteraction.test.js +119 -0
- package/lib/__new-tests__/hack.test.js +70 -0
- package/lib/__new-tests__/omitProps.test.js +94 -0
- package/lib/__new-tests__/passthroughProps.test.js +102 -0
- package/lib/__new-tests__/pickProps.test.js +98 -0
- package/lib/__new-tests__/safeCloneElement.test.js +89 -0
- package/package.json +9 -8
- package/src/__new-tests__/ComponentIdentifier.test.tsx +105 -0
- package/src/__new-tests__/DeterministicIdContext.test.tsx +126 -0
- package/src/__new-tests__/callRenderProp.test.tsx +136 -0
- package/src/__new-tests__/deprecated.test.tsx +357 -0
- package/src/__new-tests__/experimental.test.tsx +138 -0
- package/src/__new-tests__/getInteraction.test.tsx +119 -0
- package/src/__new-tests__/hack.test.tsx +90 -0
- package/src/__new-tests__/omitProps.test.tsx +113 -0
- package/src/__new-tests__/passthroughProps.test.tsx +100 -0
- package/src/__new-tests__/pickProps.test.tsx +111 -0
- package/src/__new-tests__/safeCloneElement.test.tsx +95 -0
- package/tsconfig.build.json +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/__new-tests__/ComponentIdentifier.test.d.ts +2 -0
- package/types/__new-tests__/ComponentIdentifier.test.d.ts.map +1 -0
- package/types/__new-tests__/DeterministicIdContext.test.d.ts +2 -0
- package/types/__new-tests__/DeterministicIdContext.test.d.ts.map +1 -0
- package/types/__new-tests__/callRenderProp.test.d.ts +2 -0
- package/types/__new-tests__/callRenderProp.test.d.ts.map +1 -0
- package/types/__new-tests__/deprecated.test.d.ts +2 -0
- package/types/__new-tests__/deprecated.test.d.ts.map +1 -0
- package/types/__new-tests__/experimental.test.d.ts +2 -0
- package/types/__new-tests__/experimental.test.d.ts.map +1 -0
- package/types/__new-tests__/getInteraction.test.d.ts +2 -0
- package/types/__new-tests__/getInteraction.test.d.ts.map +1 -0
- package/types/__new-tests__/hack.test.d.ts +2 -0
- package/types/__new-tests__/hack.test.d.ts.map +1 -0
- package/types/__new-tests__/omitProps.test.d.ts +2 -0
- package/types/__new-tests__/omitProps.test.d.ts.map +1 -0
- package/types/__new-tests__/passthroughProps.test.d.ts +2 -0
- package/types/__new-tests__/passthroughProps.test.d.ts.map +1 -0
- package/types/__new-tests__/pickProps.test.d.ts +2 -0
- package/types/__new-tests__/pickProps.test.d.ts.map +1 -0
- package/types/__new-tests__/safeCloneElement.test.d.ts +2 -0
- package/types/__new-tests__/safeCloneElement.test.d.ts.map +1 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _DeterministicIdContext = require("../DeterministicIdContext");
|
|
8
|
+
var _dec, _class, _class2, _div, _WrapperComponent, _div2, _div3;
|
|
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 = (_class2 = class TestComponent extends _react.default.Component {
|
|
33
|
+
render() {
|
|
34
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
35
|
+
"data-testid": "test-component",
|
|
36
|
+
id: this.props.deterministicId()
|
|
37
|
+
}, this.props.children);
|
|
38
|
+
}
|
|
39
|
+
}, _class2.displayName = "TestComponent", _class2)) || _class);
|
|
40
|
+
class WrapperComponent extends _react.default.Component {
|
|
41
|
+
render() {
|
|
42
|
+
return _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(TestComponent, null)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
WrapperComponent.displayName = "WrapperComponent";
|
|
46
|
+
const uniqueIds = el => {
|
|
47
|
+
const idList = Array.from(el.children).map(child => child.id);
|
|
48
|
+
return new Set(idList).size === idList.length;
|
|
49
|
+
};
|
|
50
|
+
describe('DeterministicIdContext', () => {
|
|
51
|
+
it('can be found and tested with ReactTestUtils', () => {
|
|
52
|
+
(0, _react2.render)(_WrapperComponent || (_WrapperComponent = /*#__PURE__*/_react.default.createElement(WrapperComponent, null)));
|
|
53
|
+
const testComponent = _react2.screen.getByTestId('test-component');
|
|
54
|
+
expect(testComponent).toBeInTheDocument();
|
|
55
|
+
expect(testComponent.id).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
it('should generate unique ids without Provider wrapper', () => {
|
|
58
|
+
(0, _react2.render)(_div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", {
|
|
59
|
+
"data-testid": "test-components"
|
|
60
|
+
}, /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null))));
|
|
61
|
+
const el = _react2.screen.getByTestId('test-components');
|
|
62
|
+
expect(uniqueIds(el)).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it('should generate unique ids when components are rendered both out and inside of provider', () => {
|
|
65
|
+
(0, _react2.render)(_div3 || (_div3 = /*#__PURE__*/_react.default.createElement("div", {
|
|
66
|
+
"data-testid": "test-components"
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(_DeterministicIdContext.DeterministicIdContextProvider, null, /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null)), /*#__PURE__*/_react.default.createElement(TestComponent, null), /*#__PURE__*/_react.default.createElement(TestComponent, null))));
|
|
68
|
+
const el = _react2.screen.getByTestId('test-components');
|
|
69
|
+
expect(uniqueIds(el)).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
it('should generate unique ids with provider only', () => {
|
|
72
|
+
const Wrapper = ({
|
|
73
|
+
children
|
|
74
|
+
}) => {
|
|
75
|
+
return /*#__PURE__*/_react.default.createElement(_DeterministicIdContext.DeterministicIdContextProvider, {
|
|
76
|
+
instanceCounterMap: (0, _DeterministicIdContext.generateInstanceCounterMap)()
|
|
77
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
78
|
+
"data-testid": "wrapper"
|
|
79
|
+
}, children));
|
|
80
|
+
};
|
|
81
|
+
const children = [];
|
|
82
|
+
for (let i = 0; i < 10; i++) {
|
|
83
|
+
children.push( /*#__PURE__*/_react.default.createElement(TestComponent, {
|
|
84
|
+
key: i
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(Wrapper, null, children));
|
|
88
|
+
const el = _react2.screen.getByTestId('wrapper');
|
|
89
|
+
expect(uniqueIds(el)).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
6
|
+
var _react2 = require("@testing-library/react");
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _callRenderProp = require("../callRenderProp");
|
|
9
|
+
var _div, _div2;
|
|
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
|
+
describe('callRenderProp', () => {
|
|
34
|
+
it('strings', () => {
|
|
35
|
+
expect((0, _callRenderProp.callRenderProp)('foo')).toEqual('foo');
|
|
36
|
+
});
|
|
37
|
+
it('numbers', () => {
|
|
38
|
+
expect((0, _callRenderProp.callRenderProp)(2)).toEqual(2);
|
|
39
|
+
});
|
|
40
|
+
it('arrays', () => {
|
|
41
|
+
const prop = ['foo', 'bar', 'baz'];
|
|
42
|
+
expect((0, _callRenderProp.callRenderProp)(prop)).toStrictEqual(prop);
|
|
43
|
+
expect((0, _callRenderProp.callRenderProp)([])).toStrictEqual([]);
|
|
44
|
+
});
|
|
45
|
+
it('booleans', () => {
|
|
46
|
+
expect((0, _callRenderProp.callRenderProp)(false)).toEqual(false);
|
|
47
|
+
});
|
|
48
|
+
it('JSX literals', () => {
|
|
49
|
+
const Foo = () => _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, "hello"));
|
|
50
|
+
expect((0, _callRenderProp.callRenderProp)( /*#__PURE__*/_react.default.createElement(Foo, null))).toStrictEqual( /*#__PURE__*/_react.default.createElement(Foo, null));
|
|
51
|
+
});
|
|
52
|
+
it('React classes', () => {
|
|
53
|
+
class Foo extends _react.default.Component {
|
|
54
|
+
render() {
|
|
55
|
+
return _div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", null, "hello"));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
Foo.displayName = "Foo";
|
|
59
|
+
const Result = (0, _callRenderProp.callRenderProp)(Foo);
|
|
60
|
+
expect(Result).toStrictEqual( /*#__PURE__*/_react.default.createElement(Foo, null));
|
|
61
|
+
const _render = (0, _react2.render)(Result),
|
|
62
|
+
getByText = _render.getByText;
|
|
63
|
+
expect(getByText('hello')).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
it('functions', () => {
|
|
66
|
+
const Baz = function () {
|
|
67
|
+
return 'some text';
|
|
68
|
+
};
|
|
69
|
+
const result = (0, _callRenderProp.callRenderProp)(Baz);
|
|
70
|
+
const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, result)),
|
|
71
|
+
getByText = _render2.getByText;
|
|
72
|
+
expect(getByText('some text')).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
it('fat arrow functions', () => {
|
|
75
|
+
const Baz = () => 'some text';
|
|
76
|
+
|
|
77
|
+
// in this test we are trying to test that it works with fat arrow functions,
|
|
78
|
+
// but the babel config when we run these tests is currently configured
|
|
79
|
+
// to transpile fat arrow functions down to normal functions.
|
|
80
|
+
// Real, untranspiled, fat-arrow functions don't have a `prototype` but when
|
|
81
|
+
// they are transpiled down they do. So this next line is to make sure
|
|
82
|
+
// the thing we are testing really doesn't have a prototype like it would
|
|
83
|
+
// if it was a real untranspiled fat arrow function.
|
|
84
|
+
if (Baz.prototype) Baz.prototype = void 0;
|
|
85
|
+
const result = (0, _callRenderProp.callRenderProp)(Baz);
|
|
86
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, result)),
|
|
87
|
+
getByText = _render3.getByText;
|
|
88
|
+
expect(getByText('some text')).toBeInTheDocument();
|
|
89
|
+
});
|
|
90
|
+
describe('passing props', () => {
|
|
91
|
+
it('should pass props correctly to functions', () => {
|
|
92
|
+
const someFunc = ({
|
|
93
|
+
shape
|
|
94
|
+
}) => /*#__PURE__*/_react.default.createElement("div", null, shape);
|
|
95
|
+
const result = (0, _callRenderProp.callRenderProp)(someFunc, {
|
|
96
|
+
shape: 'rectangle'
|
|
97
|
+
});
|
|
98
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, result)),
|
|
99
|
+
getByText = _render4.getByText;
|
|
100
|
+
expect(getByText('rectangle')).toBeInTheDocument();
|
|
101
|
+
});
|
|
102
|
+
it('should pass props correctly to React classes', () => {
|
|
103
|
+
class Foo extends _react.default.Component {
|
|
104
|
+
render() {
|
|
105
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.shape);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
Foo.displayName = "Foo";
|
|
109
|
+
Foo.propTypes = {
|
|
110
|
+
shape: _propTypes.default.oneOf(['circle', 'rectangle'])
|
|
111
|
+
};
|
|
112
|
+
Foo.defaultProps = {
|
|
113
|
+
shape: 'circle'
|
|
114
|
+
};
|
|
115
|
+
const result = (0, _callRenderProp.callRenderProp)(Foo, {
|
|
116
|
+
shape: 'rectangle'
|
|
117
|
+
});
|
|
118
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement("div", null, result)),
|
|
119
|
+
getByText = _render5.getByText;
|
|
120
|
+
expect(getByText('rectangle')).toBeInTheDocument();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
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 _deprecated = require("../deprecated");
|
|
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: null,
|
|
46
|
+
qux: 'Hello'
|
|
47
|
+
};
|
|
48
|
+
describe('@deprecated', () => {
|
|
49
|
+
describe('deprecated props', () => {
|
|
50
|
+
var _DeprecatedComponent, _DeprecatedComponent2, _DeprecatedComponent3;
|
|
51
|
+
const DeprecatedComponent = (0, _deprecated.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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
57
|
+
(0, _react2.render)(_DeprecatedComponent || (_DeprecatedComponent = /*#__PURE__*/_react.default.createElement(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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
66
|
+
(0, _react2.render)(_DeprecatedComponent2 || (_DeprecatedComponent2 = /*#__PURE__*/_react.default.createElement(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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
75
|
+
(0, _react2.render)(_DeprecatedComponent3 || (_DeprecatedComponent3 = /*#__PURE__*/_react.default.createElement(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 = (0, _deprecated.deprecated)('3.4.0')(TestComponent);
|
|
85
|
+
it('should warn that the entire component is deprecated if no old props are supplied', () => {
|
|
86
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
87
|
+
(0, _react2.render)(_DeprecatedComponent4 || (_DeprecatedComponent4 = /*#__PURE__*/_react.default.createElement(DeprecatedComponent, null)));
|
|
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 = (0, _deprecated.deprecated)('5.0.0', null, _deprecated.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 = jest.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
|
+
(0, _react2.render)(_DeprecatedComponent5 || (_DeprecatedComponent5 = /*#__PURE__*/_react.default.createElement(DeprecatedComponent, null)));
|
|
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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
107
|
+
class DeprecatedPropValueComponent extends _react.Component {
|
|
108
|
+
render() {
|
|
109
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.color);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
|
|
113
|
+
DeprecatedPropValueComponent.propTypes = {
|
|
114
|
+
color: _deprecated.deprecated.deprecatePropValues(_propTypes.default.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'])
|
|
115
|
+
};
|
|
116
|
+
DeprecatedPropValueComponent.defaultProps = {
|
|
117
|
+
color: 'red'
|
|
118
|
+
};
|
|
119
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DeprecatedPropValueComponent, {
|
|
120
|
+
color: "yellow"
|
|
121
|
+
}));
|
|
122
|
+
expect(consoleWarningSpy).not.toHaveBeenCalled();
|
|
123
|
+
consoleWarningSpy.mockRestore();
|
|
124
|
+
});
|
|
125
|
+
it('should warn when a forbidden prop value is supplied', () => {
|
|
126
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
127
|
+
const color = 'orange';
|
|
128
|
+
class DeprecatedPropValueComponent extends _react.Component {
|
|
129
|
+
render() {
|
|
130
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.color);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
|
|
134
|
+
DeprecatedPropValueComponent.propTypes = {
|
|
135
|
+
color: _deprecated.deprecated.deprecatePropValues(_propTypes.default.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'])
|
|
136
|
+
};
|
|
137
|
+
DeprecatedPropValueComponent.defaultProps = {
|
|
138
|
+
color: 'red'
|
|
139
|
+
};
|
|
140
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DeprecatedPropValueComponent, {
|
|
141
|
+
color: color
|
|
142
|
+
}));
|
|
143
|
+
const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated.`;
|
|
144
|
+
expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
|
|
145
|
+
consoleWarningSpy.mockRestore();
|
|
146
|
+
});
|
|
147
|
+
it('should warn with additional message text when a forbidden prop value is supplied and has message text', () => {
|
|
148
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
149
|
+
const color = 'gold';
|
|
150
|
+
const message = 'It will be removed in v8.0.0.';
|
|
151
|
+
class DeprecatedPropValueComponent extends _react.Component {
|
|
152
|
+
render() {
|
|
153
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.color);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
|
|
157
|
+
DeprecatedPropValueComponent.propTypes = {
|
|
158
|
+
color: _deprecated.deprecated.deprecatePropValues(_propTypes.default.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], 'It will be removed in v8.0.0.')
|
|
159
|
+
};
|
|
160
|
+
DeprecatedPropValueComponent.defaultProps = {
|
|
161
|
+
color: 'red'
|
|
162
|
+
};
|
|
163
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DeprecatedPropValueComponent, {
|
|
164
|
+
color: color
|
|
165
|
+
}));
|
|
166
|
+
const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated. ${message}`;
|
|
167
|
+
expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
|
|
168
|
+
consoleWarningSpy.mockRestore();
|
|
169
|
+
});
|
|
170
|
+
it('should call functional message with the correct props', () => {
|
|
171
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
172
|
+
const messageMock = jest.fn();
|
|
173
|
+
const color = 'gold';
|
|
174
|
+
class DeprecatedPropValueComponent extends _react.Component {
|
|
175
|
+
render() {
|
|
176
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.color);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
|
|
180
|
+
DeprecatedPropValueComponent.propTypes = {
|
|
181
|
+
color: _deprecated.deprecated.deprecatePropValues(_propTypes.default.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], messageMock)
|
|
182
|
+
};
|
|
183
|
+
DeprecatedPropValueComponent.defaultProps = {
|
|
184
|
+
color: 'red'
|
|
185
|
+
};
|
|
186
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DeprecatedPropValueComponent, {
|
|
187
|
+
color: color
|
|
188
|
+
}));
|
|
189
|
+
const _messageMock$mock$cal = messageMock.mock.calls[0][0],
|
|
190
|
+
props = _messageMock$mock$cal.props,
|
|
191
|
+
propName = _messageMock$mock$cal.propName,
|
|
192
|
+
propValue = _messageMock$mock$cal.propValue;
|
|
193
|
+
expect(props).toEqual({
|
|
194
|
+
color
|
|
195
|
+
});
|
|
196
|
+
expect(propName).toBe('color');
|
|
197
|
+
expect(propValue).toBe(color);
|
|
198
|
+
expect(consoleWarningSpy).toHaveBeenCalled();
|
|
199
|
+
consoleWarningSpy.mockRestore();
|
|
200
|
+
});
|
|
201
|
+
it('should warn with a completely custom message when provided message is functional and prop value is forbidden', () => {
|
|
202
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
203
|
+
const color = 'gold';
|
|
204
|
+
class DeprecatedPropValueComponent extends _react.Component {
|
|
205
|
+
render() {
|
|
206
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.props.color);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
DeprecatedPropValueComponent.displayName = "DeprecatedPropValueComponent";
|
|
210
|
+
DeprecatedPropValueComponent.propTypes = {
|
|
211
|
+
color: _deprecated.deprecated.deprecatePropValues(_propTypes.default.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']), ['blue', 'orange', 'gold'], ({
|
|
212
|
+
propValue,
|
|
213
|
+
propName
|
|
214
|
+
}) => `The ${propValue} value for ${propName} has been deprecated. Use the FooBar component with the 'baz' prop set instead.`)
|
|
215
|
+
};
|
|
216
|
+
DeprecatedPropValueComponent.defaultProps = {
|
|
217
|
+
color: 'red'
|
|
218
|
+
};
|
|
219
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(DeprecatedPropValueComponent, {
|
|
220
|
+
color: color
|
|
221
|
+
}));
|
|
222
|
+
const expectedWarningMessage = `The ${color} value for color has been deprecated. Use the FooBar component with the 'baz' prop set instead.`;
|
|
223
|
+
expect(consoleWarningSpy).toHaveBeenCalledWith(expect.stringContaining(expectedWarningMessage), expect.any(String));
|
|
224
|
+
consoleWarningSpy.mockRestore();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
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 _experimental = require("../experimental");
|
|
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('@experimental', () => {
|
|
49
|
+
describe('experimental props', () => {
|
|
50
|
+
var _ExperimentalComponen, _ExperimentalComponen2, _ExperimentalComponen3;
|
|
51
|
+
const ExperimentalComponent = (0, _experimental.experimental)(['bar'])(TestComponent);
|
|
52
|
+
it('should warn when using an experimental prop', () => {
|
|
53
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
54
|
+
(0, _react2.render)(_ExperimentalComponen || (_ExperimentalComponen = /*#__PURE__*/_react.default.createElement(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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
63
|
+
(0, _react2.render)(_ExperimentalComponen2 || (_ExperimentalComponen2 = /*#__PURE__*/_react.default.createElement(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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
71
|
+
(0, _react2.render)(_ExperimentalComponen3 || (_ExperimentalComponen3 = /*#__PURE__*/_react.default.createElement(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 = (0, _experimental.experimental)()(TestComponent);
|
|
82
|
+
it('should warn that the entire component is experimental if no props are supplied', () => {
|
|
83
|
+
const consoleWarningSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
84
|
+
(0, _react2.render)(_ExperimentalComponen4 || (_ExperimentalComponen4 = /*#__PURE__*/_react.default.createElement(ExperimentalComponent, null)));
|
|
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 = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
91
|
+
(0, _react2.render)(_ExperimentalComponen5 || (_ExperimentalComponen5 = /*#__PURE__*/_react.default.createElement(ExperimentalComponent, {
|
|
92
|
+
__dangerouslyIgnoreExperimentalWarnings: true
|
|
93
|
+
})));
|
|
94
|
+
expect(consoleWarningSpy).not.toHaveBeenCalled();
|
|
95
|
+
consoleWarningSpy.mockRestore();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
var _getInteraction = require("../getInteraction");
|
|
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('getInteraction', () => {
|
|
30
|
+
it("should return 'enabled' when `interaction`, `disabled`, and `readOnly` are not provided", () => {
|
|
31
|
+
const props = {
|
|
32
|
+
foo: 'foo',
|
|
33
|
+
bar: 'bar'
|
|
34
|
+
};
|
|
35
|
+
expect((0, _getInteraction.getInteraction)({
|
|
36
|
+
props
|
|
37
|
+
})).toEqual('enabled');
|
|
38
|
+
});
|
|
39
|
+
it('should return `interaction` value when `interaction` is specified', () => {
|
|
40
|
+
const props = {
|
|
41
|
+
interaction: 'enabled'
|
|
42
|
+
};
|
|
43
|
+
expect((0, _getInteraction.getInteraction)({
|
|
44
|
+
props
|
|
45
|
+
})).toEqual('enabled');
|
|
46
|
+
props.interaction = 'disabled';
|
|
47
|
+
expect((0, _getInteraction.getInteraction)({
|
|
48
|
+
props
|
|
49
|
+
})).toEqual('disabled');
|
|
50
|
+
props.interaction = 'readonly';
|
|
51
|
+
expect((0, _getInteraction.getInteraction)({
|
|
52
|
+
props
|
|
53
|
+
})).toEqual('readonly');
|
|
54
|
+
});
|
|
55
|
+
it('should give preference to interaction even when disabled and readonly are also specified', () => {
|
|
56
|
+
const props = {
|
|
57
|
+
interaction: 'enabled',
|
|
58
|
+
disabled: true,
|
|
59
|
+
readOnly: true
|
|
60
|
+
};
|
|
61
|
+
expect((0, _getInteraction.getInteraction)({
|
|
62
|
+
props
|
|
63
|
+
})).toEqual('enabled');
|
|
64
|
+
props.disabled = false;
|
|
65
|
+
props.interaction = 'disabled';
|
|
66
|
+
expect((0, _getInteraction.getInteraction)({
|
|
67
|
+
props
|
|
68
|
+
})).toEqual('disabled');
|
|
69
|
+
props.readOnly = false;
|
|
70
|
+
props.interaction = 'readonly';
|
|
71
|
+
expect((0, _getInteraction.getInteraction)({
|
|
72
|
+
props
|
|
73
|
+
})).toEqual('readonly');
|
|
74
|
+
});
|
|
75
|
+
it("should return 'disabled' when `disabled` prop is set and `interaction` is not specified", () => {
|
|
76
|
+
const props = {
|
|
77
|
+
disabled: true
|
|
78
|
+
};
|
|
79
|
+
expect((0, _getInteraction.getInteraction)({
|
|
80
|
+
props
|
|
81
|
+
})).toEqual('disabled');
|
|
82
|
+
});
|
|
83
|
+
it("should return 'disabled' when both `disabled` and `readonly` props are set and `interaction` is not specified", () => {
|
|
84
|
+
const props = {
|
|
85
|
+
disabled: true,
|
|
86
|
+
readOnly: true
|
|
87
|
+
};
|
|
88
|
+
expect((0, _getInteraction.getInteraction)({
|
|
89
|
+
props
|
|
90
|
+
})).toEqual('disabled');
|
|
91
|
+
});
|
|
92
|
+
it("should return 'readonly' when `readonly` prop is set and `interaction` and `disabled` are not specified", () => {
|
|
93
|
+
const props = {
|
|
94
|
+
disabled: true
|
|
95
|
+
};
|
|
96
|
+
expect((0, _getInteraction.getInteraction)({
|
|
97
|
+
props
|
|
98
|
+
})).toEqual('disabled');
|
|
99
|
+
});
|
|
100
|
+
it('should not include `disabled` if it is not listed in the interactionTypes', () => {
|
|
101
|
+
const props = {
|
|
102
|
+
disabled: true,
|
|
103
|
+
readOnly: true
|
|
104
|
+
};
|
|
105
|
+
expect((0, _getInteraction.getInteraction)({
|
|
106
|
+
props,
|
|
107
|
+
interactionTypes: ['readonly']
|
|
108
|
+
})).toEqual('readonly');
|
|
109
|
+
});
|
|
110
|
+
it('should not include `readonly` if it is not listed in the interactionTypes', () => {
|
|
111
|
+
const props = {
|
|
112
|
+
readOnly: true
|
|
113
|
+
};
|
|
114
|
+
expect((0, _getInteraction.getInteraction)({
|
|
115
|
+
props,
|
|
116
|
+
interactionTypes: ['disabled']
|
|
117
|
+
})).toEqual('enabled');
|
|
118
|
+
});
|
|
119
|
+
});
|