@instructure/ui-date-input 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.
@@ -1,643 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = require("@testing-library/react");
5
- var _vitest = require("vitest");
6
- var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
7
- require("@testing-library/jest-dom");
8
- var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
9
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
10
- var _Calendar = require("@instructure/ui-calendar/lib/Calendar");
11
- var _DateInput = _interopRequireDefault(require("../__examples__/DateInput.examples"));
12
- var _index = require("../index");
13
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
14
- var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
15
- /*
16
- * The MIT License (MIT)
17
- *
18
- * Copyright (c) 2015 - present Instructure, Inc.
19
- *
20
- * Permission is hereby granted, free of charge, to any person obtaining a copy
21
- * of this software and associated documentation files (the "Software"), to deal
22
- * in the Software without restriction, including without limitation the rights
23
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
- * copies of the Software, and to permit persons to whom the Software is
25
- * furnished to do so, subject to the following conditions:
26
- *
27
- * The above copyright notice and this permission notice shall be included in all
28
- * copies or substantial portions of the Software.
29
- *
30
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
- * SOFTWARE.
37
- */
38
- // eslint-disable-next-line no-restricted-imports
39
- describe('<DateInput />', () => {
40
- const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
41
- const generateDays = (count = _Calendar.Calendar.DAY_COUNT) => {
42
- const days = [];
43
- const date = new Date('2019-07-28');
44
- while (days.length < count) {
45
- days.push((0, _jsxRuntime.jsx)(_Calendar.Calendar.Day, {
46
- date: date.toISOString(),
47
- label: date.toISOString(),
48
- children: date.getDate()
49
- }, date.toISOString()));
50
- date.setDate(date.getDate() + 1);
51
- }
52
- return days;
53
- };
54
- let consoleWarningMock;
55
- let consoleErrorMock;
56
- beforeEach(() => {
57
- // Mocking console to prevent test output pollution
58
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
59
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
60
- });
61
- afterEach(() => {
62
- consoleWarningMock.mockRestore();
63
- consoleErrorMock.mockRestore();
64
- });
65
- it('should render an input and a calendar', async () => {
66
- const _render = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
67
- renderLabel: "date-input",
68
- renderWeekdayLabels: weekdayLabels,
69
- isShowingCalendar: true,
70
- children: generateDays()
71
- })),
72
- container = _render.container,
73
- findByRole = _render.findByRole;
74
- const dateInput = container.querySelector('input');
75
- expect(dateInput).toBeInTheDocument();
76
- expect(dateInput).toHaveAttribute('type', 'text');
77
- await _userEvent.default.click(dateInput);
78
- const calendarTable = await findByRole('listbox');
79
- const calendarWrapper = await document.querySelector('[id^="Selectable_"][id$="-list"]');
80
- await (0, _react.waitFor)(() => {
81
- expect(calendarWrapper).toBeInTheDocument();
82
- expect(calendarTable).toBeInTheDocument();
83
- });
84
- });
85
- describe('input', () => {
86
- it('should render a label', () => {
87
- const labelText = 'label text';
88
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
89
- renderLabel: labelText,
90
- renderWeekdayLabels: weekdayLabels,
91
- children: generateDays()
92
- }));
93
- const dateInput = _react.screen.getByLabelText('label text');
94
- expect(dateInput).toBeInTheDocument();
95
- });
96
- it('should set value', () => {
97
- const value = 'January 5';
98
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
99
- renderLabel: "Choose date",
100
- value: value,
101
- onChange: _vitest.vi.fn(),
102
- renderWeekdayLabels: weekdayLabels,
103
- children: generateDays()
104
- }));
105
- const dateInput = _react.screen.getByLabelText('Choose date');
106
- expect(dateInput).toHaveValue(value);
107
- });
108
- it('should call onChange with the updated value', async () => {
109
- const onChange = _vitest.vi.fn();
110
- const value = 'May 18, 2022';
111
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
112
- renderLabel: "Choose date",
113
- renderWeekdayLabels: weekdayLabels,
114
- onChange: onChange,
115
- children: generateDays()
116
- }));
117
- const dateInput = _react.screen.getByLabelText('Choose date');
118
- _react.fireEvent.change(dateInput, {
119
- target: {
120
- value: value
121
- }
122
- });
123
- _react.fireEvent.keyDown(dateInput, {
124
- key: 'Enter',
125
- code: 'Enter'
126
- });
127
- _react.fireEvent.blur(dateInput);
128
- await (0, _react.waitFor)(() => {
129
- expect(onChange).toHaveBeenCalledTimes(1);
130
- expect(onChange.mock.calls[0][1].value).toEqual(expect.stringContaining(value));
131
- });
132
- });
133
- it('should call onBlur', () => {
134
- const onBlur = _vitest.vi.fn();
135
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
136
- renderLabel: "Choose date",
137
- renderWeekdayLabels: weekdayLabels,
138
- onBlur: onBlur,
139
- children: generateDays()
140
- }));
141
- const dateInput = _react.screen.getByLabelText('Choose date');
142
- _react.fireEvent.blur(dateInput);
143
- expect(onBlur).toHaveBeenCalledTimes(1);
144
- });
145
- it('should correctly set interaction type', async () => {
146
- const _render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
147
- renderLabel: "Choose date",
148
- renderWeekdayLabels: weekdayLabels,
149
- interaction: "disabled",
150
- children: generateDays()
151
- })),
152
- rerender = _render2.rerender;
153
- const dateInput = _react.screen.getByLabelText('Choose date');
154
- expect(dateInput).toHaveAttribute('disabled');
155
- rerender((0, _jsxRuntime.jsx)(_index.DateInput, {
156
- renderLabel: "Choose date",
157
- renderWeekdayLabels: weekdayLabels,
158
- interaction: "readonly",
159
- children: generateDays()
160
- }));
161
- const dateInputAfterUpdate = _react.screen.getByLabelText('Choose date');
162
- await (0, _react.waitFor)(() => {
163
- expect(dateInputAfterUpdate).toHaveAttribute('readonly');
164
- });
165
- });
166
- it('should correctly set disabled', () => {
167
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
168
- renderLabel: "Choose date",
169
- renderWeekdayLabels: weekdayLabels,
170
- disabled: true,
171
- children: generateDays()
172
- }));
173
- const dateInput = _react.screen.getByLabelText('Choose date');
174
- expect(dateInput).toHaveAttribute('disabled');
175
- });
176
- it('should correctly set readOnly', () => {
177
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
178
- renderLabel: "Choose date",
179
- renderWeekdayLabels: weekdayLabels,
180
- readOnly: true,
181
- children: generateDays()
182
- }));
183
- const dateInput = _react.screen.getByLabelText('Choose date');
184
- expect(dateInput).toHaveAttribute('readOnly');
185
- });
186
- it('should set placeholder', () => {
187
- const placeholder = 'Start typing to choose a date';
188
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
189
- renderLabel: "Choose date",
190
- renderWeekdayLabels: weekdayLabels,
191
- placeholder: placeholder,
192
- children: generateDays()
193
- }));
194
- const dateInput = _react.screen.getByLabelText('Choose date');
195
- expect(dateInput).toHaveAttribute('placeholder', placeholder);
196
- });
197
- it('should be requireable', () => {
198
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
199
- renderLabel: "Choose date",
200
- renderWeekdayLabels: weekdayLabels,
201
- isRequired: true,
202
- children: generateDays()
203
- }));
204
- const dateInput = _react.screen.getByLabelText('Choose date *');
205
- expect(dateInput).toHaveAttribute('required');
206
- });
207
- it('should provide inputRef', () => {
208
- const inputRef = _vitest.vi.fn();
209
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
210
- renderLabel: "Choose date",
211
- renderWeekdayLabels: weekdayLabels,
212
- inputRef: inputRef,
213
- children: generateDays()
214
- }));
215
- const dateInput = _react.screen.getByLabelText('Choose date');
216
- expect(inputRef).toHaveBeenCalledWith(dateInput);
217
- });
218
- it('should render messages', () => {
219
- const text = 'The selected date is invalid';
220
- const _render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
221
- renderLabel: "Choose date",
222
- renderWeekdayLabels: weekdayLabels,
223
- messages: [{
224
- type: 'error',
225
- text
226
- }],
227
- children: generateDays()
228
- })),
229
- container = _render3.container;
230
- expect(container).toHaveTextContent(text);
231
- });
232
- it('should allow custom props to pass through', () => {
233
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
234
- renderLabel: "Choose date",
235
- renderWeekdayLabels: weekdayLabels,
236
- "data-custom-attr": "custom value",
237
- name: "my name",
238
- children: generateDays()
239
- }));
240
- const dateInput = _react.screen.getByLabelText('Choose date');
241
- expect(dateInput).toHaveAttribute('data-custom-attr', 'custom value');
242
- expect(dateInput).toHaveAttribute('name', 'my name');
243
- });
244
- });
245
- describe('Calendar', () => {
246
- it('should show calendar when `isShowingCalendar` is set', async () => {
247
- const _render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
248
- renderLabel: "Choose date",
249
- renderWeekdayLabels: weekdayLabels,
250
- children: generateDays()
251
- })),
252
- rerender = _render4.rerender,
253
- queryByRole = _render4.queryByRole;
254
- const dateInput = _react.screen.getByLabelText('Choose date');
255
- const calendarTable = await queryByRole('listbox');
256
- const calendarWrapper = await document.querySelector('[id^="Selectable_"][id$="-list"]');
257
- expect(dateInput).toBeInTheDocument();
258
- expect(calendarTable).not.toBeInTheDocument();
259
- expect(calendarWrapper).not.toBeInTheDocument();
260
- rerender((0, _jsxRuntime.jsx)(_index.DateInput, {
261
- renderLabel: "Choose date",
262
- renderWeekdayLabels: weekdayLabels,
263
- isShowingCalendar: true,
264
- children: generateDays()
265
- }));
266
- const dateInputAfterUpdate = _react.screen.getByLabelText('Choose date');
267
- const calendarTableAfterUpdate = await queryByRole('listbox');
268
- const calendarWrapperAfterUpdate = await document.querySelector('[id^="Selectable_"][id$="-list"]');
269
- await (0, _react.waitFor)(() => {
270
- expect(dateInputAfterUpdate).toBeInTheDocument();
271
- expect(calendarTableAfterUpdate).toBeInTheDocument();
272
- expect(calendarWrapperAfterUpdate).toBeInTheDocument();
273
- });
274
- });
275
- describe('onRequestShowCalendar', () => {
276
- it('should call onRequestShowCalendar when label is clicked', async () => {
277
- const onRequestShowCalendar = _vitest.vi.fn();
278
- const _render5 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
279
- renderLabel: "Choose date",
280
- renderWeekdayLabels: weekdayLabels,
281
- onRequestShowCalendar: onRequestShowCalendar,
282
- children: generateDays()
283
- })),
284
- container = _render5.container;
285
- const dateInput = container.querySelector('span[class$="-formFieldLayout__label"]');
286
- expect(dateInput).toHaveTextContent('Choose date');
287
- await _userEvent.default.click(dateInput);
288
- await (0, _react.waitFor)(() => {
289
- expect(onRequestShowCalendar).toHaveBeenCalled();
290
- });
291
- });
292
- it('should call onRequestShowCalendar when input is clicked', async () => {
293
- const onRequestShowCalendar = _vitest.vi.fn();
294
- const _render6 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
295
- renderLabel: "Choose date",
296
- renderWeekdayLabels: weekdayLabels,
297
- onRequestShowCalendar: onRequestShowCalendar,
298
- children: generateDays()
299
- })),
300
- container = _render6.container;
301
- const dateInput = container.querySelector('input');
302
- await _userEvent.default.click(dateInput);
303
- await (0, _react.waitFor)(() => {
304
- expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
305
- });
306
- });
307
- it('should call onRequestShowCalendar when input receives space event', async () => {
308
- const onRequestShowCalendar = _vitest.vi.fn();
309
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
310
- renderLabel: "Choose date",
311
- renderWeekdayLabels: weekdayLabels,
312
- onRequestShowCalendar: onRequestShowCalendar,
313
- children: generateDays()
314
- }));
315
- const dateInput = _react.screen.getByLabelText('Choose date');
316
- await _userEvent.default.type(dateInput, '{space}');
317
- await (0, _react.waitFor)(() => {
318
- expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
319
- });
320
- });
321
- it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
322
- const onRequestShowCalendar = _vitest.vi.fn();
323
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
324
- renderLabel: "Choose date",
325
- renderWeekdayLabels: weekdayLabels,
326
- onRequestShowCalendar: onRequestShowCalendar,
327
- isShowingCalendar: true,
328
- children: generateDays()
329
- }));
330
- const dateInput = _react.screen.getByLabelText('Choose date');
331
- await _userEvent.default.type(dateInput, '{space}');
332
- await (0, _react.waitFor)(() => {
333
- expect(onRequestShowCalendar).not.toHaveBeenCalled();
334
- });
335
- });
336
- it('should call onRequestShowCalendar when input receives down arrow event', async () => {
337
- const onRequestShowCalendar = _vitest.vi.fn();
338
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
339
- renderLabel: "Choose date",
340
- renderWeekdayLabels: weekdayLabels,
341
- onRequestShowCalendar: onRequestShowCalendar,
342
- children: generateDays()
343
- }));
344
- const dateInput = _react.screen.getByLabelText('Choose date');
345
- await _userEvent.default.type(dateInput, '{arrowdown}');
346
- await (0, _react.waitFor)(() => {
347
- expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
348
- });
349
- });
350
- it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
351
- const onRequestShowCalendar = _vitest.vi.fn();
352
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
353
- renderLabel: "Choose date",
354
- renderWeekdayLabels: weekdayLabels,
355
- onRequestShowCalendar: onRequestShowCalendar,
356
- isShowingCalendar: true,
357
- children: generateDays()
358
- }));
359
- const dateInput = _react.screen.getByLabelText('Choose date');
360
- await _userEvent.default.type(dateInput, '{arrowdown}');
361
- await (0, _react.waitFor)(() => {
362
- expect(onRequestShowCalendar).not.toHaveBeenCalled();
363
- });
364
- });
365
- it('should call onRequestShowCalendar when input receives up arrow event', async () => {
366
- const onRequestShowCalendar = _vitest.vi.fn();
367
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
368
- renderLabel: "Choose date",
369
- renderWeekdayLabels: weekdayLabels,
370
- onRequestShowCalendar: onRequestShowCalendar,
371
- children: generateDays()
372
- }));
373
- const dateInput = _react.screen.getByLabelText('Choose date');
374
- await _userEvent.default.type(dateInput, '{arrowup}');
375
- await (0, _react.waitFor)(() => {
376
- expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
377
- });
378
- });
379
- it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
380
- const onRequestShowCalendar = _vitest.vi.fn();
381
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
382
- renderLabel: "Choose date",
383
- renderWeekdayLabels: weekdayLabels,
384
- onRequestShowCalendar: onRequestShowCalendar,
385
- isShowingCalendar: true,
386
- children: generateDays()
387
- }));
388
- const dateInput = _react.screen.getByLabelText('Choose date');
389
- await _userEvent.default.type(dateInput, '{arrowup}');
390
- await (0, _react.waitFor)(() => {
391
- expect(onRequestShowCalendar).not.toHaveBeenCalled();
392
- });
393
- });
394
- it('should call onRequestShowCalendar when input receives onChange event', async () => {
395
- const onRequestShowCalendar = _vitest.vi.fn();
396
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
397
- renderLabel: "Choose date",
398
- renderWeekdayLabels: weekdayLabels,
399
- onRequestShowCalendar: onRequestShowCalendar,
400
- children: generateDays()
401
- }));
402
- const dateInput = _react.screen.getByLabelText('Choose date');
403
- _react.fireEvent.change(dateInput, {
404
- target: {
405
- value: 'January 5'
406
- }
407
- });
408
- await (0, _react.waitFor)(() => {
409
- expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
410
- });
411
- });
412
- it('should not call onRequestShowCalendar when disabled', async () => {
413
- const onRequestShowCalendar = _vitest.vi.fn();
414
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
415
- renderLabel: "Choose date",
416
- renderWeekdayLabels: weekdayLabels,
417
- onRequestShowCalendar: onRequestShowCalendar,
418
- interaction: "disabled",
419
- children: generateDays()
420
- }));
421
- const dateInput = _react.screen.getByLabelText('Choose date');
422
- _react.fireEvent.click(dateInput);
423
- await _userEvent.default.type(dateInput, '{arrowup}{arrowdown}{space}January 5', {
424
- skipClick: true
425
- });
426
- await (0, _react.waitFor)(() => {
427
- expect(onRequestShowCalendar).not.toHaveBeenCalled();
428
- });
429
- });
430
- });
431
- describe('onRequestHideCalendar and onRequestValidateDate', () => {
432
- it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
433
- const onRequestHideCalendar = _vitest.vi.fn();
434
- const onRequestValidateDate = _vitest.vi.fn();
435
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
436
- renderLabel: "Choose date",
437
- renderWeekdayLabels: weekdayLabels,
438
- onRequestHideCalendar: onRequestHideCalendar,
439
- onRequestValidateDate: onRequestValidateDate,
440
- isShowingCalendar: true,
441
- children: generateDays()
442
- }));
443
- const dateInput = _react.screen.getByLabelText('Choose date');
444
- _react.fireEvent.blur(dateInput);
445
- await (0, _react.waitFor)(() => {
446
- expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
447
- expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
448
- });
449
- });
450
- it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
451
- const onRequestHideCalendar = _vitest.vi.fn();
452
- const onRequestValidateDate = _vitest.vi.fn();
453
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
454
- renderLabel: "Choose date",
455
- renderWeekdayLabels: weekdayLabels,
456
- onRequestHideCalendar: onRequestHideCalendar,
457
- onRequestValidateDate: onRequestValidateDate,
458
- isShowingCalendar: true,
459
- children: generateDays()
460
- }));
461
- const dateInput = _react.screen.getByLabelText('Choose date');
462
- await _userEvent.default.type(dateInput, '{esc}');
463
- await (0, _react.waitFor)(() => {
464
- expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
465
- expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
466
- });
467
- });
468
- it('should call onRequestHideCalendar and onRequestValidateDate when input receives enter event', async () => {
469
- const onRequestHideCalendar = _vitest.vi.fn();
470
- const onRequestValidateDate = _vitest.vi.fn();
471
- const days = generateDays();
472
- days[4] = _Calendar$Day || (_Calendar$Day = (0, _jsxRuntime.jsx)(_Calendar.Calendar.Day, {
473
- label: "4",
474
- date: "2019-09-28",
475
- isSelected: true,
476
- children: 4
477
- }, "4"));
478
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
479
- renderLabel: "Choose date",
480
- renderWeekdayLabels: weekdayLabels,
481
- onRequestHideCalendar: onRequestHideCalendar,
482
- onRequestValidateDate: onRequestValidateDate,
483
- isShowingCalendar: true,
484
- children: days
485
- }));
486
- const dateInput = _react.screen.getByLabelText('Choose date');
487
- await _userEvent.default.type(dateInput, '{enter}');
488
- await (0, _react.waitFor)(() => {
489
- expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
490
- expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
491
- });
492
- });
493
- });
494
- it('should render calendar navigation label', () => {
495
- const label = 'January 2019';
496
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
497
- renderLabel: "Choose date",
498
- renderWeekdayLabels: weekdayLabels,
499
- renderNavigationLabel: (0, _jsxRuntime.jsx)("div", {
500
- "data-testId": "label-id",
501
- children: label
502
- }),
503
- isShowingCalendar: true,
504
- children: generateDays()
505
- }));
506
- const navigationLabel = _react.screen.getByTestId('label-id');
507
- expect(navigationLabel).toBeInTheDocument();
508
- expect(navigationLabel).toHaveTextContent(label);
509
- });
510
- it('should render calendar weekday labels', async () => {
511
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
512
- renderLabel: "Choose date",
513
- renderWeekdayLabels: weekdayLabels,
514
- isShowingCalendar: true,
515
- children: generateDays()
516
- }));
517
- const calendar = await _react.screen.findByRole('listbox');
518
- const headers = calendar.querySelectorAll('th');
519
- expect(headers.length).toEqual(7);
520
- weekdayLabels.forEach(label => {
521
- expect(calendar).toHaveTextContent(label);
522
- });
523
- });
524
- it('should render all focusable elements in calendar with tabIndex="-1"', async () => {
525
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
526
- renderLabel: "Choose date",
527
- renderWeekdayLabels: weekdayLabels,
528
- renderNextMonthButton: _button || (_button = (0, _jsxRuntime.jsx)("button", {
529
- "data-testId": "button-next",
530
- children: "next"
531
- })),
532
- renderPrevMonthButton: _button2 || (_button2 = (0, _jsxRuntime.jsx)("button", {
533
- "data-testId": "button-prev",
534
- children: "prev"
535
- })),
536
- isShowingCalendar: true,
537
- children: generateDays()
538
- }));
539
- const calendar = await _react.screen.findByRole('listbox');
540
- const calendarDays = calendar.querySelectorAll('button');
541
- const nextMonthButton = _react.screen.getByTestId('button-next');
542
- const prevMonthButton = _react.screen.getByTestId('button-prev');
543
- expect(nextMonthButton).toHaveAttribute('tabIndex', '-1');
544
- expect(prevMonthButton).toHaveAttribute('tabIndex', '-1');
545
- expect(calendarDays).toHaveLength(42);
546
- calendarDays.forEach(day => {
547
- expect(day).toHaveAttribute('tabIndex', '-1');
548
- });
549
- });
550
- it('should render days with the correct role', async () => {
551
- const days = generateDays();
552
- days[5] = _Calendar$Day2 || (_Calendar$Day2 = (0, _jsxRuntime.jsx)(_Calendar.Calendar.Day, {
553
- label: "5",
554
- date: "2019-09-28",
555
- id: "5",
556
- isOutsideMonth: true,
557
- children: "outside"
558
- }, "5"));
559
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
560
- renderLabel: "Choose date",
561
- renderWeekdayLabels: weekdayLabels,
562
- isShowingCalendar: true,
563
- children: days
564
- }));
565
- const calendar = await _react.screen.findByRole('listbox');
566
- const calendarDays = calendar.querySelectorAll('button');
567
- calendarDays.forEach(day => {
568
- if (day.textContent.includes('outside')) {
569
- expect(day).toHaveAttribute('role', 'presentation');
570
- } else {
571
- expect(day).toHaveAttribute('role', 'option');
572
- }
573
- });
574
- });
575
- it('should assign aria-selected to the selected date and link it to the input', async () => {
576
- const days = generateDays();
577
- days[7] = _Calendar$Day3 || (_Calendar$Day3 = (0, _jsxRuntime.jsx)(_Calendar.Calendar.Day, {
578
- label: "7",
579
- date: "2019-09-28",
580
- id: "selected-day-id",
581
- isSelected: true,
582
- children: "selected"
583
- }, "7"));
584
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
585
- renderLabel: "Choose date",
586
- renderWeekdayLabels: weekdayLabels,
587
- isShowingCalendar: true,
588
- children: days
589
- }));
590
- const calendar = await _react.screen.findByRole('listbox');
591
- const calendarDays = calendar.querySelectorAll('button');
592
- let selectedDayID = '';
593
- calendarDays.forEach(day => {
594
- if (day.textContent.includes('selected')) {
595
- selectedDayID = day.id;
596
- expect(day).toHaveAttribute('aria-selected', 'true');
597
- } else {
598
- expect(day).toHaveAttribute('aria-selected', 'false');
599
- }
600
- });
601
- const dateInput = _react.screen.getByLabelText('Choose date');
602
- expect(dateInput).toHaveAttribute('aria-activedescendant', selectedDayID);
603
- });
604
- });
605
- describe('with generated examples', () => {
606
- const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.DateInput, _DateInput.default);
607
- it.each(generatedComponents)('should be accessible with example: $description', async ({
608
- content
609
- }) => {
610
- const _render7 = (0, _react.render)(content),
611
- container = _render7.container;
612
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
613
- expect(axeCheck).toBe(true);
614
- });
615
- });
616
- describe('with minimal config', () => {
617
- it('should render 44 buttons (a calendar) when clicked', async () => {
618
- const onChange = _vitest.vi.fn();
619
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.DateInput, {
620
- renderLabel: "Choose date",
621
- assistiveText: "Type a date or use arrow keys to navigate date picker.",
622
- width: "20rem",
623
- isInline: true,
624
- value: '2023-11-23',
625
- onChange: onChange,
626
- currentDate: "2023-12-23",
627
- disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11'],
628
- disabledDateErrorMessage: "disabled date",
629
- invalidDateErrorMessage: "invalid date"
630
- }));
631
- const dateInput = _react.screen.getByLabelText('Choose date');
632
- _react.fireEvent.click(dateInput);
633
- const calendarTable = document.querySelector('table');
634
- const calendarDays = calendarTable.querySelectorAll('button');
635
- const calendarWrapper = document.querySelector('[id^="Selectable_"][id$="-list"]');
636
- const calendarButtons = calendarWrapper.querySelectorAll('button');
637
- await (0, _react.waitFor)(() => {
638
- expect(calendarButtons).toHaveLength(44);
639
- expect(calendarDays).toHaveLength(42);
640
- });
641
- });
642
- });
643
- });