@instructure/ui-date-input 9.10.2 → 9.11.1
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 +19 -0
- package/es/DateInput/__new-tests__/DateInput.test.js +1 -1
- package/es/DateInput2/__new-tests__/DateInput2.test.js +301 -0
- package/lib/DateInput/__new-tests__/DateInput.test.js +1 -1
- package/lib/DateInput2/__new-tests__/DateInput2.test.js +305 -0
- package/package.json +20 -20
- package/src/DateInput/__new-tests__/DateInput.test.tsx +3 -1
- package/src/DateInput2/__new-tests__/DateInput2.test.tsx +360 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput2/__new-tests__/DateInput2.test.d.ts +2 -0
- package/types/DateInput2/__new-tests__/DateInput2.test.d.ts.map +1 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instructure/ui-date-input",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.11.1",
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
6
6
|
"module": "./es/index.js",
|
@@ -23,11 +23,11 @@
|
|
23
23
|
},
|
24
24
|
"license": "MIT",
|
25
25
|
"devDependencies": {
|
26
|
-
"@instructure/ui-axe-check": "9.
|
27
|
-
"@instructure/ui-babel-preset": "9.
|
28
|
-
"@instructure/ui-buttons": "9.
|
29
|
-
"@instructure/ui-scripts": "9.
|
30
|
-
"@instructure/ui-test-utils": "9.
|
26
|
+
"@instructure/ui-axe-check": "9.11.1",
|
27
|
+
"@instructure/ui-babel-preset": "9.11.1",
|
28
|
+
"@instructure/ui-buttons": "9.11.1",
|
29
|
+
"@instructure/ui-scripts": "9.11.1",
|
30
|
+
"@instructure/ui-test-utils": "9.11.1",
|
31
31
|
"@testing-library/jest-dom": "^6.4.6",
|
32
32
|
"@testing-library/react": "^15.0.7",
|
33
33
|
"@testing-library/user-event": "^14.5.2",
|
@@ -35,20 +35,20 @@
|
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
37
|
"@babel/runtime": "^7.24.5",
|
38
|
-
"@instructure/emotion": "9.
|
39
|
-
"@instructure/shared-types": "9.
|
40
|
-
"@instructure/ui-calendar": "9.
|
41
|
-
"@instructure/ui-form-field": "9.
|
42
|
-
"@instructure/ui-i18n": "9.
|
43
|
-
"@instructure/ui-icons": "9.
|
44
|
-
"@instructure/ui-popover": "9.
|
45
|
-
"@instructure/ui-position": "9.
|
46
|
-
"@instructure/ui-prop-types": "9.
|
47
|
-
"@instructure/ui-react-utils": "9.
|
48
|
-
"@instructure/ui-selectable": "9.
|
49
|
-
"@instructure/ui-testable": "9.
|
50
|
-
"@instructure/ui-text-input": "9.
|
51
|
-
"@instructure/ui-utils": "9.
|
38
|
+
"@instructure/emotion": "9.11.1",
|
39
|
+
"@instructure/shared-types": "9.11.1",
|
40
|
+
"@instructure/ui-calendar": "9.11.1",
|
41
|
+
"@instructure/ui-form-field": "9.11.1",
|
42
|
+
"@instructure/ui-i18n": "9.11.1",
|
43
|
+
"@instructure/ui-icons": "9.11.1",
|
44
|
+
"@instructure/ui-popover": "9.11.1",
|
45
|
+
"@instructure/ui-position": "9.11.1",
|
46
|
+
"@instructure/ui-prop-types": "9.11.1",
|
47
|
+
"@instructure/ui-react-utils": "9.11.1",
|
48
|
+
"@instructure/ui-selectable": "9.11.1",
|
49
|
+
"@instructure/ui-testable": "9.11.1",
|
50
|
+
"@instructure/ui-text-input": "9.11.1",
|
51
|
+
"@instructure/ui-utils": "9.11.1",
|
52
52
|
"moment-timezone": "^0.5.45",
|
53
53
|
"prop-types": "^15.8.1"
|
54
54
|
},
|
@@ -381,7 +381,9 @@ describe('<DateInput />', () => {
|
|
381
381
|
{generateDays()}
|
382
382
|
</DateInput>
|
383
383
|
)
|
384
|
-
const dateInput = container.querySelector(
|
384
|
+
const dateInput = container.querySelector(
|
385
|
+
'span[class$="-formFieldLayout__label"]'
|
386
|
+
)
|
385
387
|
|
386
388
|
expect(dateInput).toHaveTextContent('Choose date')
|
387
389
|
|
@@ -0,0 +1,360 @@
|
|
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
|
+
import React, { useState } from 'react'
|
25
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
26
|
+
import { vi, MockInstance } from 'vitest'
|
27
|
+
import userEvent from '@testing-library/user-event'
|
28
|
+
import '@testing-library/jest-dom'
|
29
|
+
|
30
|
+
import { DateInput2 } from '../index'
|
31
|
+
|
32
|
+
const LABEL_TEXT = 'Choose a date'
|
33
|
+
|
34
|
+
const DateInputExample = () => {
|
35
|
+
const [inputValue, setInputValue] = useState('')
|
36
|
+
|
37
|
+
return (
|
38
|
+
<DateInput2
|
39
|
+
renderLabel={LABEL_TEXT}
|
40
|
+
screenReaderLabels={{
|
41
|
+
calendarIcon: 'Calendar',
|
42
|
+
nextMonthButton: 'Next month',
|
43
|
+
prevMonthButton: 'Previous month'
|
44
|
+
}}
|
45
|
+
value={inputValue}
|
46
|
+
onChange={(_e, inputValue, _dateString) => {
|
47
|
+
setInputValue(inputValue)
|
48
|
+
}}
|
49
|
+
/>
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
describe('<DateInput2 />', () => {
|
54
|
+
let consoleWarningMock: MockInstance<typeof console.error>
|
55
|
+
let consoleErrorMock: MockInstance<typeof console.error>
|
56
|
+
|
57
|
+
beforeEach(() => {
|
58
|
+
// Mocking console to prevent test output pollution
|
59
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
60
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {})
|
61
|
+
})
|
62
|
+
|
63
|
+
afterEach(() => {
|
64
|
+
consoleWarningMock.mockRestore()
|
65
|
+
consoleErrorMock.mockRestore()
|
66
|
+
})
|
67
|
+
|
68
|
+
it('should render an input', async () => {
|
69
|
+
const { container } = render(<DateInputExample />)
|
70
|
+
const dateInput = container.querySelector('input')
|
71
|
+
|
72
|
+
expect(dateInput).toBeInTheDocument()
|
73
|
+
expect(dateInput).toHaveAttribute('type', 'text')
|
74
|
+
})
|
75
|
+
|
76
|
+
it('should render an input label', async () => {
|
77
|
+
const { container } = render(<DateInputExample />)
|
78
|
+
|
79
|
+
const label = container.querySelector('label')
|
80
|
+
|
81
|
+
expect(label).toBeInTheDocument()
|
82
|
+
expect(label).toHaveTextContent(LABEL_TEXT)
|
83
|
+
})
|
84
|
+
|
85
|
+
it('should render an input placeholder', async () => {
|
86
|
+
const placeholder = 'Placeholder'
|
87
|
+
render(
|
88
|
+
<DateInput2
|
89
|
+
renderLabel="Choose a date"
|
90
|
+
screenReaderLabels={{
|
91
|
+
calendarIcon: 'Calendar',
|
92
|
+
nextMonthButton: 'Next month',
|
93
|
+
prevMonthButton: 'Previous month'
|
94
|
+
}}
|
95
|
+
placeholder={placeholder}
|
96
|
+
value=""
|
97
|
+
/>
|
98
|
+
)
|
99
|
+
const dateInput = screen.getByLabelText('Choose a date')
|
100
|
+
|
101
|
+
expect(dateInput).toHaveAttribute('placeholder', placeholder)
|
102
|
+
})
|
103
|
+
|
104
|
+
it('should render a calendar icon with screen reader label', async () => {
|
105
|
+
const iconLabel = 'Calendar icon Label'
|
106
|
+
const { container } = render(
|
107
|
+
<DateInput2
|
108
|
+
renderLabel="Choose a date"
|
109
|
+
screenReaderLabels={{
|
110
|
+
calendarIcon: iconLabel,
|
111
|
+
nextMonthButton: 'Next month',
|
112
|
+
prevMonthButton: 'Previous month'
|
113
|
+
}}
|
114
|
+
value=""
|
115
|
+
/>
|
116
|
+
)
|
117
|
+
const calendarIcon = container.querySelector(
|
118
|
+
'svg[name="IconCalendarMonth"]'
|
119
|
+
)
|
120
|
+
const calendarLabel = screen.getByText(iconLabel)
|
121
|
+
|
122
|
+
expect(calendarIcon).toBeInTheDocument()
|
123
|
+
expect(calendarLabel).toBeInTheDocument()
|
124
|
+
})
|
125
|
+
|
126
|
+
it('should not show calendar table by default', async () => {
|
127
|
+
render(<DateInputExample />)
|
128
|
+
const calendarTable = screen.queryByRole('table')
|
129
|
+
|
130
|
+
expect(calendarTable).not.toBeInTheDocument()
|
131
|
+
})
|
132
|
+
|
133
|
+
it('should render navigation arrow buttons with screen reader labels', async () => {
|
134
|
+
const nextMonthLabel = 'Next month'
|
135
|
+
const prevMonthLabel = 'Previous month'
|
136
|
+
|
137
|
+
render(
|
138
|
+
<DateInput2
|
139
|
+
renderLabel="Choose a date"
|
140
|
+
screenReaderLabels={{
|
141
|
+
calendarIcon: 'Calendar',
|
142
|
+
nextMonthButton: nextMonthLabel,
|
143
|
+
prevMonthButton: prevMonthLabel
|
144
|
+
}}
|
145
|
+
value=""
|
146
|
+
/>
|
147
|
+
)
|
148
|
+
const calendarButton = screen.getByRole('button')
|
149
|
+
|
150
|
+
await userEvent.click(calendarButton)
|
151
|
+
|
152
|
+
await waitFor(() => {
|
153
|
+
const prevMonthButton = screen.getByRole('button', {
|
154
|
+
name: prevMonthLabel
|
155
|
+
})
|
156
|
+
const nextMonthButton = screen.getByRole('button', {
|
157
|
+
name: nextMonthLabel
|
158
|
+
})
|
159
|
+
|
160
|
+
expect(prevMonthButton).toBeInTheDocument()
|
161
|
+
expect(nextMonthButton).toBeInTheDocument()
|
162
|
+
|
163
|
+
const prevButtonLabel = screen.getByText(prevMonthLabel)
|
164
|
+
const nextButtonLabel = screen.getByText(nextMonthLabel)
|
165
|
+
|
166
|
+
expect(prevButtonLabel).toBeInTheDocument()
|
167
|
+
expect(nextButtonLabel).toBeInTheDocument()
|
168
|
+
|
169
|
+
const prevMonthIcon = prevMonthButton.querySelector(
|
170
|
+
'svg[name="IconArrowOpenStart"]'
|
171
|
+
)
|
172
|
+
const nextMonthIcon = nextMonthButton.querySelector(
|
173
|
+
'svg[name="IconArrowOpenEnd"]'
|
174
|
+
)
|
175
|
+
|
176
|
+
expect(prevMonthIcon).toBeInTheDocument()
|
177
|
+
expect(nextMonthIcon).toBeInTheDocument()
|
178
|
+
})
|
179
|
+
})
|
180
|
+
|
181
|
+
it('should programmatically set and render the initial value', async () => {
|
182
|
+
const value = '26/03/2024'
|
183
|
+
render(
|
184
|
+
<DateInput2
|
185
|
+
renderLabel="Choose a date"
|
186
|
+
screenReaderLabels={{
|
187
|
+
calendarIcon: 'Calendar',
|
188
|
+
nextMonthButton: 'Next month',
|
189
|
+
prevMonthButton: 'Previous month'
|
190
|
+
}}
|
191
|
+
locale="en-GB"
|
192
|
+
timezone="UTC"
|
193
|
+
value={value}
|
194
|
+
/>
|
195
|
+
)
|
196
|
+
const dateInput = screen.getByLabelText('Choose a date')
|
197
|
+
|
198
|
+
expect(dateInput).toHaveValue(value)
|
199
|
+
expect(dateInput).toBeInTheDocument()
|
200
|
+
})
|
201
|
+
|
202
|
+
it('should set interaction type to disabled', async () => {
|
203
|
+
const interactionDisabled = 'disabled'
|
204
|
+
const { container } = render(
|
205
|
+
<DateInput2
|
206
|
+
renderLabel="Choose a date"
|
207
|
+
screenReaderLabels={{
|
208
|
+
calendarIcon: 'Calendar',
|
209
|
+
nextMonthButton: 'Next month',
|
210
|
+
prevMonthButton: 'Previous month'
|
211
|
+
}}
|
212
|
+
value=""
|
213
|
+
interaction={interactionDisabled}
|
214
|
+
/>
|
215
|
+
)
|
216
|
+
const dateInput = container.querySelector('input')
|
217
|
+
|
218
|
+
expect(dateInput).toHaveAttribute(interactionDisabled)
|
219
|
+
})
|
220
|
+
|
221
|
+
it('should set interaction type to readonly', async () => {
|
222
|
+
const interactionReadOnly = 'readonly'
|
223
|
+
const { container } = render(
|
224
|
+
<DateInput2
|
225
|
+
renderLabel="Choose a date"
|
226
|
+
screenReaderLabels={{
|
227
|
+
calendarIcon: 'Calendar',
|
228
|
+
nextMonthButton: 'Next month',
|
229
|
+
prevMonthButton: 'Previous month'
|
230
|
+
}}
|
231
|
+
value=""
|
232
|
+
interaction={interactionReadOnly}
|
233
|
+
/>
|
234
|
+
)
|
235
|
+
const dateInput = container.querySelector('input')
|
236
|
+
const calendarButton = screen.getByRole('button')
|
237
|
+
|
238
|
+
expect(dateInput).toHaveAttribute(interactionReadOnly)
|
239
|
+
expect(calendarButton).toBeInTheDocument()
|
240
|
+
|
241
|
+
await userEvent.click(calendarButton)
|
242
|
+
|
243
|
+
await waitFor(() => {
|
244
|
+
const calendarTable = screen.queryByRole('table')
|
245
|
+
|
246
|
+
expect(calendarTable).not.toBeInTheDocument()
|
247
|
+
})
|
248
|
+
})
|
249
|
+
|
250
|
+
it('should set required', async () => {
|
251
|
+
const { container } = render(
|
252
|
+
<DateInput2
|
253
|
+
renderLabel="Choose a date"
|
254
|
+
screenReaderLabels={{
|
255
|
+
calendarIcon: 'Calendar',
|
256
|
+
nextMonthButton: 'Next month',
|
257
|
+
prevMonthButton: 'Previous month'
|
258
|
+
}}
|
259
|
+
value=""
|
260
|
+
isRequired
|
261
|
+
/>
|
262
|
+
)
|
263
|
+
const dateInput = container.querySelector('input')
|
264
|
+
|
265
|
+
expect(dateInput).toHaveAttribute('required')
|
266
|
+
})
|
267
|
+
|
268
|
+
it('should call onBlur', async () => {
|
269
|
+
const onBlur = vi.fn()
|
270
|
+
render(
|
271
|
+
<DateInput2
|
272
|
+
renderLabel="Choose a date"
|
273
|
+
screenReaderLabels={{
|
274
|
+
calendarIcon: 'Calendar',
|
275
|
+
nextMonthButton: 'Next month',
|
276
|
+
prevMonthButton: 'Previous month'
|
277
|
+
}}
|
278
|
+
value=""
|
279
|
+
onBlur={onBlur}
|
280
|
+
/>
|
281
|
+
)
|
282
|
+
const dateInput = screen.getByLabelText('Choose a date')
|
283
|
+
|
284
|
+
fireEvent.blur(dateInput)
|
285
|
+
|
286
|
+
await waitFor(() => {
|
287
|
+
expect(onBlur).toHaveBeenCalled()
|
288
|
+
})
|
289
|
+
})
|
290
|
+
|
291
|
+
it('should validate if the invalidDateErrorMessage prop is provided', async () => {
|
292
|
+
const errorMsg = 'errorMsg'
|
293
|
+
const Example = () => {
|
294
|
+
const [inputValue, setInputValue] = useState('')
|
295
|
+
|
296
|
+
return (
|
297
|
+
<DateInput2
|
298
|
+
renderLabel={LABEL_TEXT}
|
299
|
+
screenReaderLabels={{
|
300
|
+
calendarIcon: 'Calendar',
|
301
|
+
nextMonthButton: 'Next month',
|
302
|
+
prevMonthButton: 'Previous month'
|
303
|
+
}}
|
304
|
+
value={inputValue}
|
305
|
+
onChange={(_e, inputValue, _dateString) => {
|
306
|
+
setInputValue(inputValue)
|
307
|
+
}}
|
308
|
+
invalidDateErrorMessage={errorMsg}
|
309
|
+
/>
|
310
|
+
)
|
311
|
+
}
|
312
|
+
|
313
|
+
render(<Example />)
|
314
|
+
|
315
|
+
expect(screen.queryByText(errorMsg)).not.toBeInTheDocument()
|
316
|
+
|
317
|
+
const dateInput = screen.getByLabelText(LABEL_TEXT)
|
318
|
+
|
319
|
+
await userEvent.click(dateInput)
|
320
|
+
await userEvent.type(dateInput, 'Not a date')
|
321
|
+
|
322
|
+
dateInput.blur()
|
323
|
+
|
324
|
+
await waitFor(() => {
|
325
|
+
expect(screen.getByText(errorMsg)).toBeInTheDocument()
|
326
|
+
})
|
327
|
+
})
|
328
|
+
|
329
|
+
it('should show form field messages', async () => {
|
330
|
+
const messages: any = [
|
331
|
+
{ text: 'TypeLess' },
|
332
|
+
{ type: 'error', text: 'Error' },
|
333
|
+
{ type: 'success', text: 'Success' },
|
334
|
+
{ type: 'hint', text: 'Hint' },
|
335
|
+
{ type: 'screenreader-only', text: 'Screenreader' }
|
336
|
+
]
|
337
|
+
|
338
|
+
render(
|
339
|
+
<DateInput2
|
340
|
+
renderLabel="Choose a date"
|
341
|
+
screenReaderLabels={{
|
342
|
+
calendarIcon: 'Calendar',
|
343
|
+
nextMonthButton: 'Next month',
|
344
|
+
prevMonthButton: 'Previous month'
|
345
|
+
}}
|
346
|
+
value=""
|
347
|
+
messages={messages}
|
348
|
+
/>
|
349
|
+
)
|
350
|
+
|
351
|
+
expect(screen.getByText('TypeLess')).toBeVisible()
|
352
|
+
expect(screen.getByText('Error')).toBeVisible()
|
353
|
+
expect(screen.getByText('Success')).toBeVisible()
|
354
|
+
expect(screen.getByText('Hint')).toBeVisible()
|
355
|
+
|
356
|
+
const screenreaderMessage = screen.getByText('Screenreader')
|
357
|
+
expect(screenreaderMessage).toBeInTheDocument()
|
358
|
+
expect(screenreaderMessage).toHaveClass(/screenReaderContent/)
|
359
|
+
})
|
360
|
+
})
|