@instructure/ui-date-input 10.16.1-snapshot-0 → 10.16.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 +1 -1
- package/es/DateInput/__new-tests__/DateInput.test.js +167 -129
- package/es/DateInput/index.js +71 -58
- package/es/DateInput2/__new-tests__/DateInput2.test.js +20 -19
- package/es/DateInput2/index.js +37 -35
- package/lib/DateInput/__new-tests__/DateInput.test.js +228 -191
- package/lib/DateInput/index.js +70 -58
- package/lib/DateInput2/__new-tests__/DateInput2.test.js +20 -20
- package/lib/DateInput2/index.js +37 -35
- package/package.json +20 -20
- package/src/DateInput/__new-tests__/DateInput.test.tsx +1 -1
- package/src/DateInput/index.tsx +2 -3
- package/src/DateInput/props.ts +1 -1
- package/src/DateInput2/__new-tests__/DateInput2.test.tsx +1 -1
- package/src/DateInput2/index.tsx +0 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput/index.d.ts +15 -17
- package/types/DateInput/index.d.ts.map +1 -1
- package/types/DateInput/props.d.ts +1 -1
- package/types/DateInput/props.d.ts.map +1 -1
- package/types/DateInput2/index.d.ts +1 -2
- package/types/DateInput2/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
-
## [10.16.1
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
7
7
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-date-input
|
9
9
|
|
@@ -22,7 +22,7 @@ var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
23
|
* SOFTWARE.
|
24
24
|
*/
|
25
|
-
|
25
|
+
|
26
26
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
27
27
|
import { vi } from 'vitest';
|
28
28
|
import userEvent from '@testing-library/user-event';
|
@@ -34,17 +34,18 @@ import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
34
34
|
import { Calendar } from '@instructure/ui-calendar';
|
35
35
|
import Examples from '../__examples__/DateInput.examples';
|
36
36
|
import { DateInput } from '../index';
|
37
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
37
38
|
describe('<DateInput />', () => {
|
38
39
|
const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
39
40
|
const generateDays = (count = Calendar.DAY_COUNT) => {
|
40
41
|
const days = [];
|
41
42
|
const date = new Date('2019-07-28');
|
42
43
|
while (days.length < count) {
|
43
|
-
days.push(
|
44
|
-
key: date.toISOString(),
|
44
|
+
days.push(_jsx(Calendar.Day, {
|
45
45
|
date: date.toISOString(),
|
46
|
-
label: date.toISOString()
|
47
|
-
|
46
|
+
label: date.toISOString(),
|
47
|
+
children: date.getDate()
|
48
|
+
}, date.toISOString()));
|
48
49
|
date.setDate(date.getDate() + 1);
|
49
50
|
}
|
50
51
|
return days;
|
@@ -61,11 +62,12 @@ describe('<DateInput />', () => {
|
|
61
62
|
consoleErrorMock.mockRestore();
|
62
63
|
});
|
63
64
|
it('should render an input and a calendar', async () => {
|
64
|
-
const _render = render(
|
65
|
+
const _render = render(_jsx(DateInput, {
|
65
66
|
renderLabel: "date-input",
|
66
67
|
renderWeekdayLabels: weekdayLabels,
|
67
|
-
isShowingCalendar: true
|
68
|
-
|
68
|
+
isShowingCalendar: true,
|
69
|
+
children: generateDays()
|
70
|
+
})),
|
69
71
|
container = _render.container,
|
70
72
|
findByRole = _render.findByRole;
|
71
73
|
const dateInput = container.querySelector('input');
|
@@ -82,32 +84,35 @@ describe('<DateInput />', () => {
|
|
82
84
|
describe('input', () => {
|
83
85
|
it('should render a label', () => {
|
84
86
|
const labelText = 'label text';
|
85
|
-
render(
|
87
|
+
render(_jsx(DateInput, {
|
86
88
|
renderLabel: labelText,
|
87
|
-
renderWeekdayLabels: weekdayLabels
|
88
|
-
|
89
|
+
renderWeekdayLabels: weekdayLabels,
|
90
|
+
children: generateDays()
|
91
|
+
}));
|
89
92
|
const dateInput = screen.getByLabelText('label text');
|
90
93
|
expect(dateInput).toBeInTheDocument();
|
91
94
|
});
|
92
95
|
it('should set value', () => {
|
93
96
|
const value = 'January 5';
|
94
|
-
render(
|
97
|
+
render(_jsx(DateInput, {
|
95
98
|
renderLabel: "Choose date",
|
96
99
|
value: value,
|
97
100
|
onChange: vi.fn(),
|
98
|
-
renderWeekdayLabels: weekdayLabels
|
99
|
-
|
101
|
+
renderWeekdayLabels: weekdayLabels,
|
102
|
+
children: generateDays()
|
103
|
+
}));
|
100
104
|
const dateInput = screen.getByLabelText('Choose date');
|
101
105
|
expect(dateInput).toHaveValue(value);
|
102
106
|
});
|
103
107
|
it('should call onChange with the updated value', async () => {
|
104
108
|
const onChange = vi.fn();
|
105
109
|
const value = 'May 18, 2022';
|
106
|
-
render(
|
110
|
+
render(_jsx(DateInput, {
|
107
111
|
renderLabel: "Choose date",
|
108
112
|
renderWeekdayLabels: weekdayLabels,
|
109
|
-
onChange: onChange
|
110
|
-
|
113
|
+
onChange: onChange,
|
114
|
+
children: generateDays()
|
115
|
+
}));
|
111
116
|
const dateInput = screen.getByLabelText('Choose date');
|
112
117
|
fireEvent.change(dateInput, {
|
113
118
|
target: {
|
@@ -126,101 +131,111 @@ describe('<DateInput />', () => {
|
|
126
131
|
});
|
127
132
|
it('should call onBlur', () => {
|
128
133
|
const onBlur = vi.fn();
|
129
|
-
render(
|
134
|
+
render(_jsx(DateInput, {
|
130
135
|
renderLabel: "Choose date",
|
131
136
|
renderWeekdayLabels: weekdayLabels,
|
132
|
-
onBlur: onBlur
|
133
|
-
|
137
|
+
onBlur: onBlur,
|
138
|
+
children: generateDays()
|
139
|
+
}));
|
134
140
|
const dateInput = screen.getByLabelText('Choose date');
|
135
141
|
fireEvent.blur(dateInput);
|
136
142
|
expect(onBlur).toHaveBeenCalledTimes(1);
|
137
143
|
});
|
138
144
|
it('should correctly set interaction type', async () => {
|
139
|
-
const _render2 = render(
|
145
|
+
const _render2 = render(_jsx(DateInput, {
|
140
146
|
renderLabel: "Choose date",
|
141
147
|
renderWeekdayLabels: weekdayLabels,
|
142
|
-
interaction: "disabled"
|
143
|
-
|
148
|
+
interaction: "disabled",
|
149
|
+
children: generateDays()
|
150
|
+
})),
|
144
151
|
rerender = _render2.rerender;
|
145
152
|
const dateInput = screen.getByLabelText('Choose date');
|
146
153
|
expect(dateInput).toHaveAttribute('disabled');
|
147
|
-
rerender(
|
154
|
+
rerender(_jsx(DateInput, {
|
148
155
|
renderLabel: "Choose date",
|
149
156
|
renderWeekdayLabels: weekdayLabels,
|
150
|
-
interaction: "readonly"
|
151
|
-
|
157
|
+
interaction: "readonly",
|
158
|
+
children: generateDays()
|
159
|
+
}));
|
152
160
|
const dateInputAfterUpdate = screen.getByLabelText('Choose date');
|
153
161
|
await waitFor(() => {
|
154
162
|
expect(dateInputAfterUpdate).toHaveAttribute('readonly');
|
155
163
|
});
|
156
164
|
});
|
157
165
|
it('should correctly set disabled', () => {
|
158
|
-
render(
|
166
|
+
render(_jsx(DateInput, {
|
159
167
|
renderLabel: "Choose date",
|
160
168
|
renderWeekdayLabels: weekdayLabels,
|
161
|
-
disabled: true
|
162
|
-
|
169
|
+
disabled: true,
|
170
|
+
children: generateDays()
|
171
|
+
}));
|
163
172
|
const dateInput = screen.getByLabelText('Choose date');
|
164
173
|
expect(dateInput).toHaveAttribute('disabled');
|
165
174
|
});
|
166
175
|
it('should correctly set readOnly', () => {
|
167
|
-
render(
|
176
|
+
render(_jsx(DateInput, {
|
168
177
|
renderLabel: "Choose date",
|
169
178
|
renderWeekdayLabels: weekdayLabels,
|
170
|
-
readOnly: true
|
171
|
-
|
179
|
+
readOnly: true,
|
180
|
+
children: generateDays()
|
181
|
+
}));
|
172
182
|
const dateInput = screen.getByLabelText('Choose date');
|
173
183
|
expect(dateInput).toHaveAttribute('readOnly');
|
174
184
|
});
|
175
185
|
it('should set placeholder', () => {
|
176
186
|
const placeholder = 'Start typing to choose a date';
|
177
|
-
render(
|
187
|
+
render(_jsx(DateInput, {
|
178
188
|
renderLabel: "Choose date",
|
179
189
|
renderWeekdayLabels: weekdayLabels,
|
180
|
-
placeholder: placeholder
|
181
|
-
|
190
|
+
placeholder: placeholder,
|
191
|
+
children: generateDays()
|
192
|
+
}));
|
182
193
|
const dateInput = screen.getByLabelText('Choose date');
|
183
194
|
expect(dateInput).toHaveAttribute('placeholder', placeholder);
|
184
195
|
});
|
185
196
|
it('should be requireable', () => {
|
186
|
-
render(
|
197
|
+
render(_jsx(DateInput, {
|
187
198
|
renderLabel: "Choose date",
|
188
199
|
renderWeekdayLabels: weekdayLabels,
|
189
|
-
isRequired: true
|
190
|
-
|
200
|
+
isRequired: true,
|
201
|
+
children: generateDays()
|
202
|
+
}));
|
191
203
|
const dateInput = screen.getByLabelText('Choose date *');
|
192
204
|
expect(dateInput).toHaveAttribute('required');
|
193
205
|
});
|
194
206
|
it('should provide inputRef', () => {
|
195
207
|
const inputRef = vi.fn();
|
196
|
-
render(
|
208
|
+
render(_jsx(DateInput, {
|
197
209
|
renderLabel: "Choose date",
|
198
210
|
renderWeekdayLabels: weekdayLabels,
|
199
|
-
inputRef: inputRef
|
200
|
-
|
211
|
+
inputRef: inputRef,
|
212
|
+
children: generateDays()
|
213
|
+
}));
|
201
214
|
const dateInput = screen.getByLabelText('Choose date');
|
202
215
|
expect(inputRef).toHaveBeenCalledWith(dateInput);
|
203
216
|
});
|
204
217
|
it('should render messages', () => {
|
205
218
|
const text = 'The selected date is invalid';
|
206
|
-
const _render3 = render(
|
219
|
+
const _render3 = render(_jsx(DateInput, {
|
207
220
|
renderLabel: "Choose date",
|
208
221
|
renderWeekdayLabels: weekdayLabels,
|
209
222
|
messages: [{
|
210
223
|
type: 'error',
|
211
224
|
text
|
212
|
-
}]
|
213
|
-
|
225
|
+
}],
|
226
|
+
children: generateDays()
|
227
|
+
})),
|
214
228
|
container = _render3.container;
|
215
229
|
expect(container).toHaveTextContent(text);
|
216
230
|
});
|
217
231
|
it('should allow custom props to pass through', () => {
|
218
|
-
render(
|
232
|
+
render(_jsx(DateInput, {
|
219
233
|
renderLabel: "Choose date",
|
220
234
|
renderWeekdayLabels: weekdayLabels,
|
221
235
|
"data-custom-attr": "custom value",
|
222
|
-
name: "my name"
|
223
|
-
|
236
|
+
name: "my name",
|
237
|
+
children: generateDays()
|
238
|
+
}));
|
224
239
|
const dateInput = screen.getByLabelText('Choose date');
|
225
240
|
expect(dateInput).toHaveAttribute('data-custom-attr', 'custom value');
|
226
241
|
expect(dateInput).toHaveAttribute('name', 'my name');
|
@@ -228,10 +243,11 @@ describe('<DateInput />', () => {
|
|
228
243
|
});
|
229
244
|
describe('Calendar', () => {
|
230
245
|
it('should show calendar when `isShowingCalendar` is set', async () => {
|
231
|
-
const _render4 = render(
|
246
|
+
const _render4 = render(_jsx(DateInput, {
|
232
247
|
renderLabel: "Choose date",
|
233
|
-
renderWeekdayLabels: weekdayLabels
|
234
|
-
|
248
|
+
renderWeekdayLabels: weekdayLabels,
|
249
|
+
children: generateDays()
|
250
|
+
})),
|
235
251
|
rerender = _render4.rerender,
|
236
252
|
queryByRole = _render4.queryByRole;
|
237
253
|
const dateInput = screen.getByLabelText('Choose date');
|
@@ -240,11 +256,12 @@ describe('<DateInput />', () => {
|
|
240
256
|
expect(dateInput).toBeInTheDocument();
|
241
257
|
expect(calendarTable).not.toBeInTheDocument();
|
242
258
|
expect(calendarWrapper).not.toBeInTheDocument();
|
243
|
-
rerender(
|
259
|
+
rerender(_jsx(DateInput, {
|
244
260
|
renderLabel: "Choose date",
|
245
261
|
renderWeekdayLabels: weekdayLabels,
|
246
|
-
isShowingCalendar: true
|
247
|
-
|
262
|
+
isShowingCalendar: true,
|
263
|
+
children: generateDays()
|
264
|
+
}));
|
248
265
|
const dateInputAfterUpdate = screen.getByLabelText('Choose date');
|
249
266
|
const calendarTableAfterUpdate = await queryByRole('listbox');
|
250
267
|
const calendarWrapperAfterUpdate = await document.querySelector('[id^="Selectable_"][id$="-list"]');
|
@@ -257,11 +274,12 @@ describe('<DateInput />', () => {
|
|
257
274
|
describe('onRequestShowCalendar', () => {
|
258
275
|
it('should call onRequestShowCalendar when label is clicked', async () => {
|
259
276
|
const onRequestShowCalendar = vi.fn();
|
260
|
-
const _render5 = render(
|
277
|
+
const _render5 = render(_jsx(DateInput, {
|
261
278
|
renderLabel: "Choose date",
|
262
279
|
renderWeekdayLabels: weekdayLabels,
|
263
|
-
onRequestShowCalendar: onRequestShowCalendar
|
264
|
-
|
280
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
281
|
+
children: generateDays()
|
282
|
+
})),
|
265
283
|
container = _render5.container;
|
266
284
|
const dateInput = container.querySelector('span[class$="-formFieldLayout__label"]');
|
267
285
|
expect(dateInput).toHaveTextContent('Choose date');
|
@@ -272,11 +290,12 @@ describe('<DateInput />', () => {
|
|
272
290
|
});
|
273
291
|
it('should call onRequestShowCalendar when input is clicked', async () => {
|
274
292
|
const onRequestShowCalendar = vi.fn();
|
275
|
-
const _render6 = render(
|
293
|
+
const _render6 = render(_jsx(DateInput, {
|
276
294
|
renderLabel: "Choose date",
|
277
295
|
renderWeekdayLabels: weekdayLabels,
|
278
|
-
onRequestShowCalendar: onRequestShowCalendar
|
279
|
-
|
296
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
297
|
+
children: generateDays()
|
298
|
+
})),
|
280
299
|
container = _render6.container;
|
281
300
|
const dateInput = container.querySelector('input');
|
282
301
|
await userEvent.click(dateInput);
|
@@ -286,11 +305,12 @@ describe('<DateInput />', () => {
|
|
286
305
|
});
|
287
306
|
it('should call onRequestShowCalendar when input receives space event', async () => {
|
288
307
|
const onRequestShowCalendar = vi.fn();
|
289
|
-
render(
|
308
|
+
render(_jsx(DateInput, {
|
290
309
|
renderLabel: "Choose date",
|
291
310
|
renderWeekdayLabels: weekdayLabels,
|
292
|
-
onRequestShowCalendar: onRequestShowCalendar
|
293
|
-
|
311
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
312
|
+
children: generateDays()
|
313
|
+
}));
|
294
314
|
const dateInput = screen.getByLabelText('Choose date');
|
295
315
|
await userEvent.type(dateInput, '{space}');
|
296
316
|
await waitFor(() => {
|
@@ -299,12 +319,13 @@ describe('<DateInput />', () => {
|
|
299
319
|
});
|
300
320
|
it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
|
301
321
|
const onRequestShowCalendar = vi.fn();
|
302
|
-
render(
|
322
|
+
render(_jsx(DateInput, {
|
303
323
|
renderLabel: "Choose date",
|
304
324
|
renderWeekdayLabels: weekdayLabels,
|
305
325
|
onRequestShowCalendar: onRequestShowCalendar,
|
306
|
-
isShowingCalendar: true
|
307
|
-
|
326
|
+
isShowingCalendar: true,
|
327
|
+
children: generateDays()
|
328
|
+
}));
|
308
329
|
const dateInput = screen.getByLabelText('Choose date');
|
309
330
|
await userEvent.type(dateInput, '{space}');
|
310
331
|
await waitFor(() => {
|
@@ -313,11 +334,12 @@ describe('<DateInput />', () => {
|
|
313
334
|
});
|
314
335
|
it('should call onRequestShowCalendar when input receives down arrow event', async () => {
|
315
336
|
const onRequestShowCalendar = vi.fn();
|
316
|
-
render(
|
337
|
+
render(_jsx(DateInput, {
|
317
338
|
renderLabel: "Choose date",
|
318
339
|
renderWeekdayLabels: weekdayLabels,
|
319
|
-
onRequestShowCalendar: onRequestShowCalendar
|
320
|
-
|
340
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
341
|
+
children: generateDays()
|
342
|
+
}));
|
321
343
|
const dateInput = screen.getByLabelText('Choose date');
|
322
344
|
await userEvent.type(dateInput, '{arrowdown}');
|
323
345
|
await waitFor(() => {
|
@@ -326,12 +348,13 @@ describe('<DateInput />', () => {
|
|
326
348
|
});
|
327
349
|
it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
|
328
350
|
const onRequestShowCalendar = vi.fn();
|
329
|
-
render(
|
351
|
+
render(_jsx(DateInput, {
|
330
352
|
renderLabel: "Choose date",
|
331
353
|
renderWeekdayLabels: weekdayLabels,
|
332
354
|
onRequestShowCalendar: onRequestShowCalendar,
|
333
|
-
isShowingCalendar: true
|
334
|
-
|
355
|
+
isShowingCalendar: true,
|
356
|
+
children: generateDays()
|
357
|
+
}));
|
335
358
|
const dateInput = screen.getByLabelText('Choose date');
|
336
359
|
await userEvent.type(dateInput, '{arrowdown}');
|
337
360
|
await waitFor(() => {
|
@@ -340,11 +363,12 @@ describe('<DateInput />', () => {
|
|
340
363
|
});
|
341
364
|
it('should call onRequestShowCalendar when input receives up arrow event', async () => {
|
342
365
|
const onRequestShowCalendar = vi.fn();
|
343
|
-
render(
|
366
|
+
render(_jsx(DateInput, {
|
344
367
|
renderLabel: "Choose date",
|
345
368
|
renderWeekdayLabels: weekdayLabels,
|
346
|
-
onRequestShowCalendar: onRequestShowCalendar
|
347
|
-
|
369
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
370
|
+
children: generateDays()
|
371
|
+
}));
|
348
372
|
const dateInput = screen.getByLabelText('Choose date');
|
349
373
|
await userEvent.type(dateInput, '{arrowup}');
|
350
374
|
await waitFor(() => {
|
@@ -353,12 +377,13 @@ describe('<DateInput />', () => {
|
|
353
377
|
});
|
354
378
|
it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
|
355
379
|
const onRequestShowCalendar = vi.fn();
|
356
|
-
render(
|
380
|
+
render(_jsx(DateInput, {
|
357
381
|
renderLabel: "Choose date",
|
358
382
|
renderWeekdayLabels: weekdayLabels,
|
359
383
|
onRequestShowCalendar: onRequestShowCalendar,
|
360
|
-
isShowingCalendar: true
|
361
|
-
|
384
|
+
isShowingCalendar: true,
|
385
|
+
children: generateDays()
|
386
|
+
}));
|
362
387
|
const dateInput = screen.getByLabelText('Choose date');
|
363
388
|
await userEvent.type(dateInput, '{arrowup}');
|
364
389
|
await waitFor(() => {
|
@@ -367,11 +392,12 @@ describe('<DateInput />', () => {
|
|
367
392
|
});
|
368
393
|
it('should call onRequestShowCalendar when input receives onChange event', async () => {
|
369
394
|
const onRequestShowCalendar = vi.fn();
|
370
|
-
render(
|
395
|
+
render(_jsx(DateInput, {
|
371
396
|
renderLabel: "Choose date",
|
372
397
|
renderWeekdayLabels: weekdayLabels,
|
373
|
-
onRequestShowCalendar: onRequestShowCalendar
|
374
|
-
|
398
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
399
|
+
children: generateDays()
|
400
|
+
}));
|
375
401
|
const dateInput = screen.getByLabelText('Choose date');
|
376
402
|
fireEvent.change(dateInput, {
|
377
403
|
target: {
|
@@ -384,12 +410,13 @@ describe('<DateInput />', () => {
|
|
384
410
|
});
|
385
411
|
it('should not call onRequestShowCalendar when disabled', async () => {
|
386
412
|
const onRequestShowCalendar = vi.fn();
|
387
|
-
render(
|
413
|
+
render(_jsx(DateInput, {
|
388
414
|
renderLabel: "Choose date",
|
389
415
|
renderWeekdayLabels: weekdayLabels,
|
390
416
|
onRequestShowCalendar: onRequestShowCalendar,
|
391
|
-
interaction: "disabled"
|
392
|
-
|
417
|
+
interaction: "disabled",
|
418
|
+
children: generateDays()
|
419
|
+
}));
|
393
420
|
const dateInput = screen.getByLabelText('Choose date');
|
394
421
|
fireEvent.click(dateInput);
|
395
422
|
await userEvent.type(dateInput, '{arrowup}{arrowdown}{space}January 5', {
|
@@ -404,13 +431,14 @@ describe('<DateInput />', () => {
|
|
404
431
|
it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
|
405
432
|
const onRequestHideCalendar = vi.fn();
|
406
433
|
const onRequestValidateDate = vi.fn();
|
407
|
-
render(
|
434
|
+
render(_jsx(DateInput, {
|
408
435
|
renderLabel: "Choose date",
|
409
436
|
renderWeekdayLabels: weekdayLabels,
|
410
437
|
onRequestHideCalendar: onRequestHideCalendar,
|
411
438
|
onRequestValidateDate: onRequestValidateDate,
|
412
|
-
isShowingCalendar: true
|
413
|
-
|
439
|
+
isShowingCalendar: true,
|
440
|
+
children: generateDays()
|
441
|
+
}));
|
414
442
|
const dateInput = screen.getByLabelText('Choose date');
|
415
443
|
fireEvent.blur(dateInput);
|
416
444
|
await waitFor(() => {
|
@@ -421,13 +449,14 @@ describe('<DateInput />', () => {
|
|
421
449
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
|
422
450
|
const onRequestHideCalendar = vi.fn();
|
423
451
|
const onRequestValidateDate = vi.fn();
|
424
|
-
render(
|
452
|
+
render(_jsx(DateInput, {
|
425
453
|
renderLabel: "Choose date",
|
426
454
|
renderWeekdayLabels: weekdayLabels,
|
427
455
|
onRequestHideCalendar: onRequestHideCalendar,
|
428
456
|
onRequestValidateDate: onRequestValidateDate,
|
429
|
-
isShowingCalendar: true
|
430
|
-
|
457
|
+
isShowingCalendar: true,
|
458
|
+
children: generateDays()
|
459
|
+
}));
|
431
460
|
const dateInput = screen.getByLabelText('Choose date');
|
432
461
|
await userEvent.type(dateInput, '{esc}');
|
433
462
|
await waitFor(() => {
|
@@ -439,19 +468,20 @@ describe('<DateInput />', () => {
|
|
439
468
|
const onRequestHideCalendar = vi.fn();
|
440
469
|
const onRequestValidateDate = vi.fn();
|
441
470
|
const days = generateDays();
|
442
|
-
days[4] = _Calendar$Day || (_Calendar$Day =
|
443
|
-
key: "4",
|
471
|
+
days[4] = _Calendar$Day || (_Calendar$Day = _jsx(Calendar.Day, {
|
444
472
|
label: "4",
|
445
473
|
date: "2019-09-28",
|
446
|
-
isSelected: true
|
447
|
-
|
448
|
-
|
474
|
+
isSelected: true,
|
475
|
+
children: 4
|
476
|
+
}, "4"));
|
477
|
+
render(_jsx(DateInput, {
|
449
478
|
renderLabel: "Choose date",
|
450
479
|
renderWeekdayLabels: weekdayLabels,
|
451
480
|
onRequestHideCalendar: onRequestHideCalendar,
|
452
481
|
onRequestValidateDate: onRequestValidateDate,
|
453
|
-
isShowingCalendar: true
|
454
|
-
|
482
|
+
isShowingCalendar: true,
|
483
|
+
children: days
|
484
|
+
}));
|
455
485
|
const dateInput = screen.getByLabelText('Choose date');
|
456
486
|
await userEvent.type(dateInput, '{enter}');
|
457
487
|
await waitFor(() => {
|
@@ -462,24 +492,27 @@ describe('<DateInput />', () => {
|
|
462
492
|
});
|
463
493
|
it('should render calendar navigation label', () => {
|
464
494
|
const label = 'January 2019';
|
465
|
-
render(
|
495
|
+
render(_jsx(DateInput, {
|
466
496
|
renderLabel: "Choose date",
|
467
497
|
renderWeekdayLabels: weekdayLabels,
|
468
|
-
renderNavigationLabel:
|
469
|
-
"data-testId": "label-id"
|
470
|
-
|
471
|
-
|
472
|
-
|
498
|
+
renderNavigationLabel: _jsx("div", {
|
499
|
+
"data-testId": "label-id",
|
500
|
+
children: label
|
501
|
+
}),
|
502
|
+
isShowingCalendar: true,
|
503
|
+
children: generateDays()
|
504
|
+
}));
|
473
505
|
const navigationLabel = screen.getByTestId('label-id');
|
474
506
|
expect(navigationLabel).toBeInTheDocument();
|
475
507
|
expect(navigationLabel).toHaveTextContent(label);
|
476
508
|
});
|
477
509
|
it('should render calendar weekday labels', async () => {
|
478
|
-
render(
|
510
|
+
render(_jsx(DateInput, {
|
479
511
|
renderLabel: "Choose date",
|
480
512
|
renderWeekdayLabels: weekdayLabels,
|
481
|
-
isShowingCalendar: true
|
482
|
-
|
513
|
+
isShowingCalendar: true,
|
514
|
+
children: generateDays()
|
515
|
+
}));
|
483
516
|
const calendar = await screen.findByRole('listbox');
|
484
517
|
const headers = calendar.querySelectorAll('th');
|
485
518
|
expect(headers.length).toEqual(7);
|
@@ -488,17 +521,20 @@ describe('<DateInput />', () => {
|
|
488
521
|
});
|
489
522
|
});
|
490
523
|
it('should render all focusable elements in calendar with tabIndex="-1"', async () => {
|
491
|
-
render(
|
524
|
+
render(_jsx(DateInput, {
|
492
525
|
renderLabel: "Choose date",
|
493
526
|
renderWeekdayLabels: weekdayLabels,
|
494
|
-
renderNextMonthButton: _button || (_button =
|
495
|
-
"data-testId": "button-next"
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
527
|
+
renderNextMonthButton: _button || (_button = _jsx("button", {
|
528
|
+
"data-testId": "button-next",
|
529
|
+
children: "next"
|
530
|
+
})),
|
531
|
+
renderPrevMonthButton: _button2 || (_button2 = _jsx("button", {
|
532
|
+
"data-testId": "button-prev",
|
533
|
+
children: "prev"
|
534
|
+
})),
|
535
|
+
isShowingCalendar: true,
|
536
|
+
children: generateDays()
|
537
|
+
}));
|
502
538
|
const calendar = await screen.findByRole('listbox');
|
503
539
|
const calendarDays = calendar.querySelectorAll('button');
|
504
540
|
const nextMonthButton = screen.getByTestId('button-next');
|
@@ -512,18 +548,19 @@ describe('<DateInput />', () => {
|
|
512
548
|
});
|
513
549
|
it('should render days with the correct role', async () => {
|
514
550
|
const days = generateDays();
|
515
|
-
days[5] = _Calendar$Day2 || (_Calendar$Day2 =
|
516
|
-
key: "5",
|
551
|
+
days[5] = _Calendar$Day2 || (_Calendar$Day2 = _jsx(Calendar.Day, {
|
517
552
|
label: "5",
|
518
553
|
date: "2019-09-28",
|
519
554
|
id: "5",
|
520
|
-
isOutsideMonth: true
|
521
|
-
|
522
|
-
|
555
|
+
isOutsideMonth: true,
|
556
|
+
children: "outside"
|
557
|
+
}, "5"));
|
558
|
+
render(_jsx(DateInput, {
|
523
559
|
renderLabel: "Choose date",
|
524
560
|
renderWeekdayLabels: weekdayLabels,
|
525
|
-
isShowingCalendar: true
|
526
|
-
|
561
|
+
isShowingCalendar: true,
|
562
|
+
children: days
|
563
|
+
}));
|
527
564
|
const calendar = await screen.findByRole('listbox');
|
528
565
|
const calendarDays = calendar.querySelectorAll('button');
|
529
566
|
calendarDays.forEach(day => {
|
@@ -536,18 +573,19 @@ describe('<DateInput />', () => {
|
|
536
573
|
});
|
537
574
|
it('should assign aria-selected to the selected date and link it to the input', async () => {
|
538
575
|
const days = generateDays();
|
539
|
-
days[7] = _Calendar$Day3 || (_Calendar$Day3 =
|
540
|
-
key: "7",
|
576
|
+
days[7] = _Calendar$Day3 || (_Calendar$Day3 = _jsx(Calendar.Day, {
|
541
577
|
label: "7",
|
542
578
|
date: "2019-09-28",
|
543
579
|
id: "selected-day-id",
|
544
|
-
isSelected: true
|
545
|
-
|
546
|
-
|
580
|
+
isSelected: true,
|
581
|
+
children: "selected"
|
582
|
+
}, "7"));
|
583
|
+
render(_jsx(DateInput, {
|
547
584
|
renderLabel: "Choose date",
|
548
585
|
renderWeekdayLabels: weekdayLabels,
|
549
|
-
isShowingCalendar: true
|
550
|
-
|
586
|
+
isShowingCalendar: true,
|
587
|
+
children: days
|
588
|
+
}));
|
551
589
|
const calendar = await screen.findByRole('listbox');
|
552
590
|
const calendarDays = calendar.querySelectorAll('button');
|
553
591
|
let selectedDayID = '';
|
@@ -577,7 +615,7 @@ describe('<DateInput />', () => {
|
|
577
615
|
describe('with minimal config', () => {
|
578
616
|
it('should render 44 buttons (a calendar) when clicked', async () => {
|
579
617
|
const onChange = vi.fn();
|
580
|
-
render(
|
618
|
+
render(_jsx(DateInput, {
|
581
619
|
renderLabel: "Choose date",
|
582
620
|
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
583
621
|
width: "20rem",
|