@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.
- package/CHANGELOG.md +1 -1
- package/package.json +7 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/__new-tests__/DeterministicIdContext.test.js +0 -109
- package/es/__new-tests__/callRenderProp.test.js +0 -138
- package/es/__new-tests__/deprecated.test.js +0 -237
- package/es/__new-tests__/experimental.test.js +0 -98
- package/es/__new-tests__/getInteraction.test.js +0 -117
- package/es/__new-tests__/hack.test.js +0 -70
- package/es/__new-tests__/omitProps.test.js +0 -91
- package/es/__new-tests__/passthroughProps.test.js +0 -100
- package/es/__new-tests__/pickProps.test.js +0 -95
- package/es/__new-tests__/safeCloneElement.test.js +0 -87
- package/lib/__new-tests__/DeterministicIdContext.test.js +0 -110
- package/lib/__new-tests__/callRenderProp.test.js +0 -140
- package/lib/__new-tests__/deprecated.test.js +0 -240
- package/lib/__new-tests__/experimental.test.js +0 -101
- package/lib/__new-tests__/getInteraction.test.js +0 -119
- package/lib/__new-tests__/hack.test.js +0 -73
- package/lib/__new-tests__/omitProps.test.js +0 -94
- package/lib/__new-tests__/passthroughProps.test.js +0 -102
- package/lib/__new-tests__/pickProps.test.js +0 -98
- package/lib/__new-tests__/safeCloneElement.test.js +0 -89
- package/src/__new-tests__/DeterministicIdContext.test.tsx +0 -140
- package/src/__new-tests__/callRenderProp.test.tsx +0 -136
- package/src/__new-tests__/deprecated.test.tsx +0 -358
- package/src/__new-tests__/experimental.test.tsx +0 -139
- package/src/__new-tests__/getInteraction.test.tsx +0 -119
- package/src/__new-tests__/hack.test.tsx +0 -91
- package/src/__new-tests__/omitProps.test.tsx +0 -113
- package/src/__new-tests__/passthroughProps.test.tsx +0 -100
- package/src/__new-tests__/pickProps.test.tsx +0 -111
- package/src/__new-tests__/safeCloneElement.test.tsx +0 -96
- package/types/__new-tests__/DeterministicIdContext.test.d.ts +0 -2
- package/types/__new-tests__/DeterministicIdContext.test.d.ts.map +0 -1
- package/types/__new-tests__/callRenderProp.test.d.ts +0 -2
- package/types/__new-tests__/callRenderProp.test.d.ts.map +0 -1
- package/types/__new-tests__/deprecated.test.d.ts +0 -2
- package/types/__new-tests__/deprecated.test.d.ts.map +0 -1
- package/types/__new-tests__/experimental.test.d.ts +0 -2
- package/types/__new-tests__/experimental.test.d.ts.map +0 -1
- package/types/__new-tests__/getInteraction.test.d.ts +0 -2
- package/types/__new-tests__/getInteraction.test.d.ts.map +0 -1
- package/types/__new-tests__/hack.test.d.ts +0 -2
- package/types/__new-tests__/hack.test.d.ts.map +0 -1
- package/types/__new-tests__/omitProps.test.d.ts +0 -2
- package/types/__new-tests__/omitProps.test.d.ts.map +0 -1
- package/types/__new-tests__/passthroughProps.test.d.ts +0 -2
- package/types/__new-tests__/passthroughProps.test.d.ts.map +0 -1
- package/types/__new-tests__/pickProps.test.d.ts +0 -2
- package/types/__new-tests__/pickProps.test.d.ts.map +0 -1
- package/types/__new-tests__/safeCloneElement.test.d.ts +0 -2
- package/types/__new-tests__/safeCloneElement.test.d.ts.map +0 -1
|
@@ -1,358 +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
|
-
|
|
29
|
-
import { render } from '@testing-library/react'
|
|
30
|
-
import '@testing-library/jest-dom'
|
|
31
|
-
|
|
32
|
-
import { deprecated } from '../deprecated'
|
|
33
|
-
|
|
34
|
-
type TestComponentProps = {
|
|
35
|
-
bar: string
|
|
36
|
-
qux: string
|
|
37
|
-
}
|
|
38
|
-
class TestComponent extends Component<TestComponentProps> {
|
|
39
|
-
static propTypes = {
|
|
40
|
-
bar: PropTypes.string,
|
|
41
|
-
qux: PropTypes.string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static defaultProps = {
|
|
45
|
-
bar: null,
|
|
46
|
-
qux: 'Hello'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
render() {
|
|
50
|
-
return (
|
|
51
|
-
<div>
|
|
52
|
-
{this.props.qux} {this.props.bar}
|
|
53
|
-
</div>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
describe('@deprecated', () => {
|
|
59
|
-
describe('deprecated props', () => {
|
|
60
|
-
const DeprecatedComponent = deprecated('2.1.0', {
|
|
61
|
-
foo: 'bar',
|
|
62
|
-
baz: true
|
|
63
|
-
})(TestComponent)
|
|
64
|
-
|
|
65
|
-
it('should warn when suggesting new prop when using old prop', () => {
|
|
66
|
-
const consoleWarningSpy = vi
|
|
67
|
-
.spyOn(console, 'warn')
|
|
68
|
-
.mockImplementation(() => {})
|
|
69
|
-
|
|
70
|
-
render(<DeprecatedComponent foo="Jane" />)
|
|
71
|
-
|
|
72
|
-
const expectedWarningMessage =
|
|
73
|
-
'Warning: [TestComponent] `foo` is deprecated and will be removed in version 2.1.0. Use `bar` instead. '
|
|
74
|
-
|
|
75
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
76
|
-
expect.stringContaining(expectedWarningMessage),
|
|
77
|
-
expect.any(String)
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
consoleWarningSpy.mockRestore()
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should warn when using old prop with no new prop', () => {
|
|
84
|
-
const consoleWarningSpy = vi
|
|
85
|
-
.spyOn(console, 'warn')
|
|
86
|
-
.mockImplementation(() => {})
|
|
87
|
-
|
|
88
|
-
render(<DeprecatedComponent baz="Goodbye" />)
|
|
89
|
-
|
|
90
|
-
const expectedWarningMessage =
|
|
91
|
-
'Warning: [TestComponent] `baz` is deprecated and will be removed in version 2.1.0.'
|
|
92
|
-
|
|
93
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
94
|
-
expect.stringContaining(expectedWarningMessage),
|
|
95
|
-
expect.any(String)
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
consoleWarningSpy.mockRestore()
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('should not output a warning using new prop', () => {
|
|
102
|
-
const consoleWarningSpy = vi
|
|
103
|
-
.spyOn(console, 'warn')
|
|
104
|
-
.mockImplementation(() => {})
|
|
105
|
-
|
|
106
|
-
render(<DeprecatedComponent bar="Jane" />)
|
|
107
|
-
|
|
108
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
109
|
-
|
|
110
|
-
consoleWarningSpy.mockRestore()
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
describe('deprecated component', () => {
|
|
115
|
-
const DeprecatedComponent = deprecated('3.4.0')(TestComponent)
|
|
116
|
-
|
|
117
|
-
it('should warn that the entire component is deprecated if no old props are supplied', () => {
|
|
118
|
-
const consoleWarningSpy = vi
|
|
119
|
-
.spyOn(console, 'warn')
|
|
120
|
-
.mockImplementation(() => {})
|
|
121
|
-
|
|
122
|
-
render(<DeprecatedComponent />)
|
|
123
|
-
|
|
124
|
-
const expectedWarningMessage =
|
|
125
|
-
'Warning: [TestComponent] is deprecated and will be removed in version 3.4.0.'
|
|
126
|
-
|
|
127
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
128
|
-
expect.stringContaining(expectedWarningMessage),
|
|
129
|
-
expect.any(String)
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
consoleWarningSpy.mockRestore()
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
describe('deprecated component with a changed package message', () => {
|
|
137
|
-
const DeprecatedComponent = deprecated(
|
|
138
|
-
'5.0.0',
|
|
139
|
-
null,
|
|
140
|
-
deprecated.changedPackageWarning('ui-forms', 'ui-number-input')
|
|
141
|
-
)(TestComponent)
|
|
142
|
-
|
|
143
|
-
it('should warn that the component is deprecated and output a warning that the package changed', () => {
|
|
144
|
-
const consoleWarningSpy = vi
|
|
145
|
-
.spyOn(console, 'warn')
|
|
146
|
-
.mockImplementation(() => {})
|
|
147
|
-
|
|
148
|
-
const expectedWarningMessage =
|
|
149
|
-
'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.'
|
|
150
|
-
|
|
151
|
-
render(<DeprecatedComponent />)
|
|
152
|
-
|
|
153
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
154
|
-
expect.stringContaining(expectedWarningMessage),
|
|
155
|
-
expect.any(String)
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
consoleWarningSpy.mockRestore()
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
describe('component with deprecated prop values', () => {
|
|
163
|
-
it('should not warn when an allowed prop value is supplied', () => {
|
|
164
|
-
const consoleWarningSpy = vi
|
|
165
|
-
.spyOn(console, 'warn')
|
|
166
|
-
.mockImplementation(() => {})
|
|
167
|
-
type DeprecatedPropValueComponentProps = {
|
|
168
|
-
color: string
|
|
169
|
-
}
|
|
170
|
-
class DeprecatedPropValueComponent extends Component<DeprecatedPropValueComponentProps> {
|
|
171
|
-
static propTypes = {
|
|
172
|
-
color: deprecated.deprecatePropValues(
|
|
173
|
-
PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']),
|
|
174
|
-
['blue', 'orange', 'gold']
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
static defaultProps = {
|
|
179
|
-
color: 'red'
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
render() {
|
|
183
|
-
return <div>{this.props.color}</div>
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
render(<DeprecatedPropValueComponent color="yellow" />)
|
|
188
|
-
|
|
189
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
190
|
-
|
|
191
|
-
consoleWarningSpy.mockRestore()
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('should warn when a forbidden prop value is supplied', () => {
|
|
195
|
-
const consoleWarningSpy = vi
|
|
196
|
-
.spyOn(console, 'warn')
|
|
197
|
-
.mockImplementation(() => {})
|
|
198
|
-
|
|
199
|
-
const color = 'orange'
|
|
200
|
-
type DeprecatedPropValueComponentProps = {
|
|
201
|
-
color: string
|
|
202
|
-
}
|
|
203
|
-
class DeprecatedPropValueComponent extends Component<DeprecatedPropValueComponentProps> {
|
|
204
|
-
static propTypes = {
|
|
205
|
-
color: deprecated.deprecatePropValues(
|
|
206
|
-
PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']),
|
|
207
|
-
['blue', 'orange', 'gold']
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static defaultProps = {
|
|
212
|
-
color: 'red'
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
render() {
|
|
216
|
-
return <div>{this.props.color}</div>
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
render(<DeprecatedPropValueComponent color={color} />)
|
|
221
|
-
|
|
222
|
-
const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated.`
|
|
223
|
-
|
|
224
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
225
|
-
expect.stringContaining(expectedWarningMessage),
|
|
226
|
-
expect.any(String)
|
|
227
|
-
)
|
|
228
|
-
|
|
229
|
-
consoleWarningSpy.mockRestore()
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
it('should warn with additional message text when a forbidden prop value is supplied and has message text', () => {
|
|
233
|
-
const consoleWarningSpy = vi
|
|
234
|
-
.spyOn(console, 'warn')
|
|
235
|
-
.mockImplementation(() => {})
|
|
236
|
-
|
|
237
|
-
const color = 'gold'
|
|
238
|
-
const message = 'It will be removed in v8.0.0.'
|
|
239
|
-
type DeprecatedPropValueComponentProps = {
|
|
240
|
-
color: string
|
|
241
|
-
}
|
|
242
|
-
class DeprecatedPropValueComponent extends Component<DeprecatedPropValueComponentProps> {
|
|
243
|
-
static propTypes = {
|
|
244
|
-
color: deprecated.deprecatePropValues(
|
|
245
|
-
PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']),
|
|
246
|
-
['blue', 'orange', 'gold'],
|
|
247
|
-
'It will be removed in v8.0.0.'
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
static defaultProps = {
|
|
252
|
-
color: 'red'
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
render() {
|
|
256
|
-
return <div>{this.props.color}</div>
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
render(<DeprecatedPropValueComponent color={color} />)
|
|
261
|
-
|
|
262
|
-
const expectedWarningMessage = `The '${color}' value for the \`color\` prop is deprecated. ${message}`
|
|
263
|
-
|
|
264
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
265
|
-
expect.stringContaining(expectedWarningMessage),
|
|
266
|
-
expect.any(String)
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
consoleWarningSpy.mockRestore()
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
it('should call functional message with the correct props', () => {
|
|
273
|
-
const consoleWarningSpy = vi
|
|
274
|
-
.spyOn(console, 'warn')
|
|
275
|
-
.mockImplementation(() => {})
|
|
276
|
-
const messageMock = vi.fn()
|
|
277
|
-
|
|
278
|
-
const color = 'gold'
|
|
279
|
-
type DeprecatedPropValueComponentProps = {
|
|
280
|
-
color: string
|
|
281
|
-
}
|
|
282
|
-
class DeprecatedPropValueComponent extends Component<DeprecatedPropValueComponentProps> {
|
|
283
|
-
static propTypes = {
|
|
284
|
-
color: deprecated.deprecatePropValues(
|
|
285
|
-
PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']),
|
|
286
|
-
['blue', 'orange', 'gold'],
|
|
287
|
-
messageMock
|
|
288
|
-
)
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
static defaultProps = {
|
|
292
|
-
color: 'red'
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
render() {
|
|
296
|
-
return <div>{this.props.color}</div>
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
render(<DeprecatedPropValueComponent color={color} />)
|
|
301
|
-
|
|
302
|
-
const { props, propName, propValue } = messageMock.mock.calls[0][0]
|
|
303
|
-
|
|
304
|
-
expect(props).toEqual({ color })
|
|
305
|
-
expect(propName).toBe('color')
|
|
306
|
-
expect(propValue).toBe(color)
|
|
307
|
-
expect(consoleWarningSpy).toHaveBeenCalled()
|
|
308
|
-
|
|
309
|
-
consoleWarningSpy.mockRestore()
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
it('should warn with a completely custom message when provided message is functional and prop value is forbidden', () => {
|
|
313
|
-
const consoleWarningSpy = vi
|
|
314
|
-
.spyOn(console, 'warn')
|
|
315
|
-
.mockImplementation(() => {})
|
|
316
|
-
|
|
317
|
-
const color = 'gold'
|
|
318
|
-
type DeprecatedPropValueComponentProps = {
|
|
319
|
-
color: string
|
|
320
|
-
}
|
|
321
|
-
class DeprecatedPropValueComponent extends Component<DeprecatedPropValueComponentProps> {
|
|
322
|
-
static propTypes = {
|
|
323
|
-
color: deprecated.deprecatePropValues(
|
|
324
|
-
PropTypes.oneOf(['red', 'yellow', 'blue', 'orange', 'gold']),
|
|
325
|
-
['blue', 'orange', 'gold'],
|
|
326
|
-
({
|
|
327
|
-
propValue,
|
|
328
|
-
propName
|
|
329
|
-
}: {
|
|
330
|
-
propValue: string
|
|
331
|
-
propName: string
|
|
332
|
-
}) =>
|
|
333
|
-
`The ${propValue} value for ${propName} has been deprecated. Use the FooBar component with the 'baz' prop set instead.`
|
|
334
|
-
)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
static defaultProps = {
|
|
338
|
-
color: 'red'
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
render() {
|
|
342
|
-
return <div>{this.props.color}</div>
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
render(<DeprecatedPropValueComponent color={color} />)
|
|
347
|
-
|
|
348
|
-
const expectedWarningMessage = `The ${color} value for color has been deprecated. Use the FooBar component with the 'baz' prop set instead.`
|
|
349
|
-
|
|
350
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
351
|
-
expect.stringContaining(expectedWarningMessage),
|
|
352
|
-
expect.any(String)
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
consoleWarningSpy.mockRestore()
|
|
356
|
-
})
|
|
357
|
-
})
|
|
358
|
-
})
|
|
@@ -1,139 +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
|
-
|
|
29
|
-
import { render } from '@testing-library/react'
|
|
30
|
-
import '@testing-library/jest-dom'
|
|
31
|
-
|
|
32
|
-
import { experimental } from '../experimental'
|
|
33
|
-
|
|
34
|
-
type TestComponentProps = {
|
|
35
|
-
bar: string
|
|
36
|
-
qux: string
|
|
37
|
-
}
|
|
38
|
-
class TestComponent extends Component<TestComponentProps> {
|
|
39
|
-
static propTypes = {
|
|
40
|
-
bar: PropTypes.string,
|
|
41
|
-
qux: PropTypes.string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static defaultProps = {
|
|
45
|
-
bar: undefined,
|
|
46
|
-
qux: 'Hello'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
render() {
|
|
50
|
-
return (
|
|
51
|
-
<div>
|
|
52
|
-
{this.props.qux} {this.props.bar}
|
|
53
|
-
</div>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
describe('@experimental', () => {
|
|
59
|
-
describe('experimental props', () => {
|
|
60
|
-
const ExperimentalComponent = experimental(['bar'])(TestComponent)
|
|
61
|
-
|
|
62
|
-
it('should warn when using an experimental prop', () => {
|
|
63
|
-
const consoleWarningSpy = vi
|
|
64
|
-
.spyOn(console, 'warn')
|
|
65
|
-
.mockImplementation(() => {})
|
|
66
|
-
render(<ExperimentalComponent bar="Jane" />)
|
|
67
|
-
|
|
68
|
-
const expectedWarningMessage =
|
|
69
|
-
'Warning: [TestComponent] The `bar` prop is experimental and its API could change significantly in a future release.'
|
|
70
|
-
|
|
71
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
72
|
-
expect.stringContaining(expectedWarningMessage),
|
|
73
|
-
expect.any(String)
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
consoleWarningSpy.mockRestore()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should not output a warning using a non-experimental prop', () => {
|
|
80
|
-
const consoleWarningSpy = vi
|
|
81
|
-
.spyOn(console, 'warn')
|
|
82
|
-
.mockImplementation(() => {})
|
|
83
|
-
render(<ExperimentalComponent qux="Jane" />)
|
|
84
|
-
|
|
85
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
86
|
-
|
|
87
|
-
consoleWarningSpy.mockRestore()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should not output a warning for an experimental prop when dangerously ignored', () => {
|
|
91
|
-
const consoleWarningSpy = vi
|
|
92
|
-
.spyOn(console, 'warn')
|
|
93
|
-
.mockImplementation(() => {})
|
|
94
|
-
|
|
95
|
-
render(
|
|
96
|
-
<ExperimentalComponent
|
|
97
|
-
qux="Jane"
|
|
98
|
-
__dangerouslyIgnoreExperimentalWarnings
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
103
|
-
|
|
104
|
-
consoleWarningSpy.mockRestore()
|
|
105
|
-
})
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
describe('experimental component', () => {
|
|
109
|
-
const ExperimentalComponent = experimental()(TestComponent)
|
|
110
|
-
|
|
111
|
-
it('should warn that the entire component is experimental if no props are supplied', () => {
|
|
112
|
-
const consoleWarningSpy = vi
|
|
113
|
-
.spyOn(console, 'warn')
|
|
114
|
-
.mockImplementation(() => {})
|
|
115
|
-
render(<ExperimentalComponent />)
|
|
116
|
-
|
|
117
|
-
const expectedWarningMessage =
|
|
118
|
-
'Warning: [TestComponent] is experimental and its API could change significantly in a future release.'
|
|
119
|
-
|
|
120
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
121
|
-
expect.stringContaining(expectedWarningMessage),
|
|
122
|
-
expect.any(String)
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
consoleWarningSpy.mockRestore()
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('should not output a warning for a component when dangerously ignored', () => {
|
|
129
|
-
const consoleWarningSpy = vi
|
|
130
|
-
.spyOn(console, 'warn')
|
|
131
|
-
.mockImplementation(() => {})
|
|
132
|
-
render(<ExperimentalComponent __dangerouslyIgnoreExperimentalWarnings />)
|
|
133
|
-
|
|
134
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
135
|
-
|
|
136
|
-
consoleWarningSpy.mockRestore()
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
})
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import '@testing-library/jest-dom'
|
|
26
|
-
import { getInteraction, InteractionType } from '../getInteraction'
|
|
27
|
-
|
|
28
|
-
describe('getInteraction', () => {
|
|
29
|
-
it("should return 'enabled' when `interaction`, `disabled`, and `readOnly` are not provided", () => {
|
|
30
|
-
const props = {
|
|
31
|
-
foo: 'foo',
|
|
32
|
-
bar: 'bar'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
expect(getInteraction({ props })).toEqual('enabled')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('should return `interaction` value when `interaction` is specified', () => {
|
|
39
|
-
const props: { interaction: InteractionType } = {
|
|
40
|
-
interaction: 'enabled'
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
expect(getInteraction({ props })).toEqual('enabled')
|
|
44
|
-
|
|
45
|
-
props.interaction = 'disabled'
|
|
46
|
-
|
|
47
|
-
expect(getInteraction({ props })).toEqual('disabled')
|
|
48
|
-
|
|
49
|
-
props.interaction = 'readonly'
|
|
50
|
-
|
|
51
|
-
expect(getInteraction({ props })).toEqual('readonly')
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('should give preference to interaction even when disabled and readonly are also specified', () => {
|
|
55
|
-
const props: { interaction: InteractionType; [key: string]: any } = {
|
|
56
|
-
interaction: 'enabled',
|
|
57
|
-
disabled: true,
|
|
58
|
-
readOnly: true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
expect(getInteraction({ props })).toEqual('enabled')
|
|
62
|
-
|
|
63
|
-
props.disabled = false
|
|
64
|
-
props.interaction = 'disabled'
|
|
65
|
-
|
|
66
|
-
expect(getInteraction({ props })).toEqual('disabled')
|
|
67
|
-
|
|
68
|
-
props.readOnly = false
|
|
69
|
-
props.interaction = 'readonly'
|
|
70
|
-
|
|
71
|
-
expect(getInteraction({ props })).toEqual('readonly')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it("should return 'disabled' when `disabled` prop is set and `interaction` is not specified", () => {
|
|
75
|
-
const props = {
|
|
76
|
-
disabled: true
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
expect(getInteraction({ props })).toEqual('disabled')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it("should return 'disabled' when both `disabled` and `readonly` props are set and `interaction` is not specified", () => {
|
|
83
|
-
const props = {
|
|
84
|
-
disabled: true,
|
|
85
|
-
readOnly: true
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
expect(getInteraction({ props })).toEqual('disabled')
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it("should return 'readonly' when `readonly` prop is set and `interaction` and `disabled` are not specified", () => {
|
|
92
|
-
const props = {
|
|
93
|
-
disabled: true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
expect(getInteraction({ props })).toEqual('disabled')
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('should not include `disabled` if it is not listed in the interactionTypes', () => {
|
|
100
|
-
const props = {
|
|
101
|
-
disabled: true,
|
|
102
|
-
readOnly: true
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
expect(getInteraction({ props, interactionTypes: ['readonly'] })).toEqual(
|
|
106
|
-
'readonly'
|
|
107
|
-
)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('should not include `readonly` if it is not listed in the interactionTypes', () => {
|
|
111
|
-
const props = {
|
|
112
|
-
readOnly: true
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
expect(getInteraction({ props, interactionTypes: ['disabled'] })).toEqual(
|
|
116
|
-
'enabled'
|
|
117
|
-
)
|
|
118
|
-
})
|
|
119
|
-
})
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { Component } from 'react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
|
-
|
|
29
|
-
import { render } from '@testing-library/react'
|
|
30
|
-
import '@testing-library/jest-dom'
|
|
31
|
-
|
|
32
|
-
import { hack } from '../hack'
|
|
33
|
-
|
|
34
|
-
type TestComponentProps = {
|
|
35
|
-
bar: string
|
|
36
|
-
qux: string
|
|
37
|
-
}
|
|
38
|
-
class TestComponent extends Component<TestComponentProps> {
|
|
39
|
-
static propTypes = {
|
|
40
|
-
bar: PropTypes.string,
|
|
41
|
-
qux: PropTypes.string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static defaultProps = {
|
|
45
|
-
bar: undefined,
|
|
46
|
-
qux: 'Hello'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
render() {
|
|
50
|
-
return (
|
|
51
|
-
<div>
|
|
52
|
-
{this.props.qux} {this.props.bar}
|
|
53
|
-
</div>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
describe('@hack', () => {
|
|
59
|
-
describe('hack props', () => {
|
|
60
|
-
const HackComponent = hack(['bar'])(TestComponent)
|
|
61
|
-
|
|
62
|
-
it('should warn when using an hack prop', () => {
|
|
63
|
-
const consoleWarningSpy = vi
|
|
64
|
-
.spyOn(console, 'warn')
|
|
65
|
-
.mockImplementation(() => {})
|
|
66
|
-
render(<HackComponent bar="Jane" />)
|
|
67
|
-
|
|
68
|
-
const expectedWarningMessage =
|
|
69
|
-
'Warning: [TestComponent] The `bar` prop is a temporary hack and will be removed in a future release.'
|
|
70
|
-
|
|
71
|
-
expect(consoleWarningSpy).toHaveBeenCalledWith(
|
|
72
|
-
expect.stringContaining(expectedWarningMessage),
|
|
73
|
-
expect.any(String)
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
consoleWarningSpy.mockRestore()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should not output a warning using a non-hack prop', () => {
|
|
80
|
-
const consoleWarningSpy = vi
|
|
81
|
-
.spyOn(console, 'warn')
|
|
82
|
-
.mockImplementation(() => {})
|
|
83
|
-
|
|
84
|
-
render(<HackComponent qux="Jane" />)
|
|
85
|
-
|
|
86
|
-
expect(consoleWarningSpy).not.toHaveBeenCalled()
|
|
87
|
-
|
|
88
|
-
consoleWarningSpy.mockRestore()
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
})
|