@instructure/ui-date-time-input 10.19.2-snapshot-3 → 10.19.2-snapshot-5

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,739 +0,0 @@
1
- var _DateTimeInput, _DateTimeInput2, _DateTimeInput3;
2
- /*
3
- * The MIT License (MIT)
4
- *
5
- * Copyright (c) 2018 - present Instructure, Inc.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
26
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import userEvent from '@testing-library/user-event';
29
- import '@testing-library/jest-dom';
30
- import { DateTimeInput } from '../index';
31
- import { ApplyLocale, DateTime } from '@instructure/ui-i18n';
32
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
33
- describe('<DateTimeInput />', () => {
34
- let consoleWarningMock;
35
- let consoleErrorMock;
36
- beforeEach(() => {
37
- // Mocking console to prevent test output pollution and expect for messages
38
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
39
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
40
- });
41
- afterEach(() => {
42
- consoleWarningMock.mockRestore();
43
- consoleErrorMock.mockRestore();
44
- });
45
- it('should use the default value', () => {
46
- const locale = 'en-US';
47
- const timezone = 'US/Eastern';
48
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
49
- render(_jsx(DateTimeInput, {
50
- description: "date_time",
51
- prevMonthLabel: "Previous month",
52
- nextMonthLabel: "Next month",
53
- dateRenderLabel: "date-input",
54
- timeRenderLabel: "time-input",
55
- invalidDateTimeMessage: "whoops",
56
- locale: locale,
57
- timezone: timezone,
58
- defaultValue: dateTime.toISOString()
59
- }));
60
- const dateInput = screen.getByLabelText('date-input');
61
- const timeInput = screen.getByLabelText('time-input');
62
- expect(dateInput).toHaveValue(dateTime.format('LL'));
63
- expect(timeInput).toHaveValue(dateTime.format('LT'));
64
- });
65
- it('should use the value', () => {
66
- const onChange = vi.fn();
67
- const locale = 'en-US';
68
- const timezone = 'US/Eastern';
69
- const dateTime = DateTime.parse('2017-05-01T23:30Z', locale, timezone);
70
- render(_jsx(DateTimeInput, {
71
- description: "date_time",
72
- prevMonthLabel: "Previous month",
73
- nextMonthLabel: "Next month",
74
- dateRenderLabel: "date-input",
75
- timeRenderLabel: "time-input",
76
- invalidDateTimeMessage: "whoops",
77
- locale: locale,
78
- timezone: timezone,
79
- value: dateTime.toISOString(),
80
- onChange: onChange
81
- }));
82
- const dateInput = screen.getByLabelText('date-input');
83
- const timeInput = screen.getByLabelText('time-input');
84
- expect(dateInput).toHaveValue(dateTime.format('LL'));
85
- expect(timeInput).toHaveValue(dateTime.format('LT'));
86
- });
87
- it('should prefer value to defaultValue', () => {
88
- const locale = 'en-US';
89
- const timezone = 'US/Eastern';
90
- const value = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
91
- const defaultValue = DateTime.parse('2016-04-01T17:00Z', locale, timezone);
92
- const onChange = vi.fn();
93
- render(_jsx(DateTimeInput, {
94
- description: "date_time",
95
- prevMonthLabel: "Previous month",
96
- nextMonthLabel: "Next month",
97
- dateRenderLabel: "date-input",
98
- timeRenderLabel: "time-input",
99
- invalidDateTimeMessage: "whoops",
100
- locale: locale,
101
- timezone: timezone,
102
- value: value.toISOString(),
103
- defaultValue: defaultValue.toISOString(),
104
- onChange: onChange
105
- }));
106
- const dateInput = screen.getByLabelText('date-input');
107
- const timeInput = screen.getByLabelText('time-input');
108
- expect(dateInput).toHaveValue(value.format('LL'));
109
- expect(timeInput).toHaveValue(value.format('LT'));
110
- });
111
- it('should set time to local midnight when only date is set', () => {
112
- const locale = 'en-US';
113
- const timezone = 'US/Eastern';
114
- const dateObj = DateTime.parse('2017-04-01T18:30Z', locale, timezone);
115
- const date = dateObj.toISOString().split('T')[0];
116
- render(_jsx(DateTimeInput, {
117
- description: "date_time",
118
- dateRenderLabel: "date-input",
119
- prevMonthLabel: "Previous month",
120
- nextMonthLabel: "Next month",
121
- timeRenderLabel: "time-input",
122
- invalidDateTimeMessage: "whoops",
123
- locale: locale,
124
- timezone: timezone,
125
- defaultValue: date
126
- }));
127
- const dateInput = screen.getByLabelText('date-input');
128
- const timeInput = screen.getByLabelText('time-input');
129
- expect(dateInput).toHaveValue(dateObj.format('LL'));
130
- expect(timeInput).toHaveValue('12:00 AM');
131
- });
132
- it('should call invalidDateTimeMessage if time is set w/o a date and is required', async () => {
133
- const invalidDateTimeMessage = vi.fn(_rawd => 'whoops');
134
- const _render = render(_jsx(DateTimeInput, {
135
- description: "date_time",
136
- dateRenderLabel: "date-input",
137
- prevMonthLabel: "Previous month",
138
- nextMonthLabel: "Next month",
139
- timeRenderLabel: "time-input",
140
- locale: "en-US",
141
- timezone: "US/Eastern",
142
- isRequired: true,
143
- invalidDateTimeMessage: invalidDateTimeMessage
144
- })),
145
- container = _render.container;
146
- const timeInput = screen.getByLabelText('time-input *');
147
- await userEvent.type(timeInput, '1:00 PM');
148
- fireEvent.blur(timeInput);
149
- await waitFor(() => {
150
- expect(container).toHaveTextContent('whoops');
151
- expect(invalidDateTimeMessage).toHaveBeenCalled();
152
- });
153
- });
154
- it('should not call invalidDateTimeMessage if time is set w/o a date', async () => {
155
- const invalidDateTimeMessage = vi.fn(_rawd => 'whoops');
156
- render(_jsx(DateTimeInput, {
157
- description: "date_time",
158
- dateRenderLabel: "date-input",
159
- prevMonthLabel: "Previous month",
160
- nextMonthLabel: "Next month",
161
- timeRenderLabel: "time-input",
162
- locale: "en-US",
163
- timezone: "US/Eastern",
164
- invalidDateTimeMessage: invalidDateTimeMessage
165
- }));
166
- const timeInput = screen.getByLabelText('time-input');
167
- await userEvent.type(timeInput, '1:00 PM{enter}');
168
- await waitFor(() => {
169
- const errorMessages = screen.queryByText('whoops');
170
- expect(errorMessages).not.toBeInTheDocument();
171
- expect(invalidDateTimeMessage).not.toHaveBeenCalled();
172
- });
173
- });
174
- it('should fire the onChange event when TimeInput value changes', async () => {
175
- const onChange = vi.fn();
176
- const locale = 'en-US';
177
- const timezone = 'US/Eastern';
178
- const defaultValue = DateTime.parse('2017-05-01T17:00', locale, timezone);
179
- render(_jsx(DateTimeInput, {
180
- description: "date_time",
181
- dateRenderLabel: "date-input",
182
- prevMonthLabel: "Previous month",
183
- nextMonthLabel: "Next month",
184
- timeRenderLabel: "time-input",
185
- invalidDateTimeMessage: "whoops",
186
- locale: locale,
187
- timezone: timezone,
188
- onChange: onChange,
189
- defaultValue: defaultValue.toISOString()
190
- }));
191
- const timeInput = screen.getByLabelText('time-input');
192
- fireEvent.change(timeInput, {
193
- target: {
194
- value: '3:00 AM'
195
- }
196
- });
197
- fireEvent.keyDown(timeInput, {
198
- key: 'Enter',
199
- code: 'Enter'
200
- });
201
- fireEvent.blur(timeInput);
202
- await waitFor(() => {
203
- expect(onChange).toHaveBeenCalled();
204
- expect(onChange.mock.calls[0][0].target.value).toMatch('3:00 AM');
205
- });
206
- });
207
- it('should show correct message when TimeInput value changes', () => {
208
- const _render2 = render(_DateTimeInput || (_DateTimeInput = _jsx(DateTimeInput, {
209
- description: "date_time",
210
- dateRenderLabel: "date-input",
211
- prevMonthLabel: "Previous month",
212
- nextMonthLabel: "Next month",
213
- timeRenderLabel: "time-input",
214
- invalidDateTimeMessage: "whoops",
215
- locale: "en-US",
216
- timezone: "US/Eastern",
217
- defaultValue: "2018-01-18T13:00"
218
- }))),
219
- container = _render2.container;
220
- const timeInput = screen.getByLabelText('time-input');
221
- fireEvent.change(timeInput, {
222
- target: {
223
- value: '5:00 PM'
224
- }
225
- });
226
- fireEvent.keyDown(timeInput, {
227
- key: 'Enter',
228
- code: 'Enter'
229
- });
230
- fireEvent.blur(timeInput);
231
- expect(container).toHaveTextContent('Thursday, January 18, 2018 5:00 PM');
232
- });
233
- it('should show the formatted date-time message', () => {
234
- const locale = 'en-US';
235
- const timezone = 'US/Eastern';
236
- const defaultValue = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
237
- const _render3 = render(_jsx(DateTimeInput, {
238
- description: "date_time",
239
- dateRenderLabel: "date-input",
240
- prevMonthLabel: "Previous month",
241
- nextMonthLabel: "Next month",
242
- timeRenderLabel: "time-input",
243
- invalidDateTimeMessage: "whoops",
244
- locale: locale,
245
- timezone: timezone,
246
- defaultValue: defaultValue.toISOString()
247
- })),
248
- container = _render3.container;
249
- expect(container).toHaveTextContent('Monday, May 1, 2017 1:30 PM');
250
- });
251
- it('should show the formatted date-time message in the proper locale', () => {
252
- const timezone = 'US/Eastern';
253
- const locale = 'fr';
254
- const defaultValue = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
255
- const _render4 = render(_jsx(DateTimeInput, {
256
- description: "date_time",
257
- dateRenderLabel: "date-input",
258
- prevMonthLabel: "Previous month",
259
- nextMonthLabel: "Next month",
260
- timeRenderLabel: "time-input",
261
- invalidDateTimeMessage: "whoops",
262
- locale: locale,
263
- timezone: timezone,
264
- defaultValue: defaultValue.toISOString()
265
- })),
266
- container = _render4.container;
267
- expect(container).toHaveTextContent('1 mai 2017 13:30');
268
- });
269
- it('should provide the html elements for date and time input', () => {
270
- let dref;
271
- let tref;
272
- render(_jsx(DateTimeInput, {
273
- description: "date_time",
274
- dateRenderLabel: "date-input",
275
- prevMonthLabel: "Previous month",
276
- nextMonthLabel: "Next month",
277
- timeRenderLabel: "time-input",
278
- invalidDateTimeMessage: "whoops",
279
- locale: "en-US",
280
- timezone: "US/Eastern",
281
- dateInputRef: el => {
282
- dref = el;
283
- },
284
- timeInputRef: el => {
285
- tref = el;
286
- }
287
- }));
288
- const dateInput = screen.getByLabelText('date-input');
289
- const timeInput = screen.getByLabelText('time-input');
290
- expect(dateInput).toEqual(dref);
291
- expect(timeInput).toEqual(tref);
292
- });
293
- it('should update message when value prop changes', () => {
294
- const onChange = vi.fn();
295
- const locale = 'en-US';
296
- const timezone = 'US/Eastern';
297
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
298
- const props = {
299
- description: 'date_time',
300
- prevMonthLabel: 'Previous month',
301
- nextMonthLabel: 'Next month',
302
- dateRenderLabel: 'date',
303
- timeRenderLabel: 'time',
304
- invalidDateTimeMessage: 'whoops',
305
- locale,
306
- timezone,
307
- value: dateTime.toISOString(),
308
- onChange
309
- };
310
- const _render5 = render(_jsx(DateTimeInput, {
311
- ...props
312
- })),
313
- container = _render5.container,
314
- rerender = _render5.rerender;
315
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
316
- rerender(_jsx(DateTimeInput, {
317
- ...props,
318
- value: "2018-03-29T16:30Z"
319
- }));
320
- expect(container).toHaveTextContent('March 29, 2018 12:30 PM');
321
- });
322
- it('should update message when locale changed', () => {
323
- const onChange = vi.fn();
324
- const locale = 'en-US';
325
- const timezone = 'US/Eastern';
326
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
327
- const props = {
328
- description: 'date_time',
329
- dateRenderLabel: 'date-input',
330
- prevMonthLabel: 'Previous month',
331
- nextMonthLabel: 'Next month',
332
- timeRenderLabel: 'time-input',
333
- invalidDateTimeMessage: 'whoops',
334
- locale,
335
- timezone,
336
- onChange,
337
- value: dateTime.toISOString()
338
- };
339
- const _render6 = render(_jsx(DateTimeInput, {
340
- ...props
341
- })),
342
- container = _render6.container,
343
- rerender = _render6.rerender;
344
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
345
- rerender(_jsx(DateTimeInput, {
346
- ...props,
347
- locale: "fr"
348
- }));
349
- expect(container).toHaveTextContent('1 mai 2017 13:30');
350
- });
351
- it('should update message when timezone changed', () => {
352
- const onChange = vi.fn();
353
- const locale = 'en-US';
354
- const timezone = 'US/Eastern';
355
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
356
- const props = {
357
- description: 'date_time',
358
- dateRenderLabel: 'date-input',
359
- prevMonthLabel: 'Previous month',
360
- nextMonthLabel: 'Next month',
361
- timeRenderLabel: 'time-input',
362
- invalidDateTimeMessage: 'whoops',
363
- locale,
364
- timezone,
365
- onChange,
366
- value: dateTime.toISOString()
367
- };
368
- const _render7 = render(_jsx(DateTimeInput, {
369
- ...props
370
- })),
371
- container = _render7.container,
372
- rerender = _render7.rerender;
373
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
374
- rerender(_jsx(DateTimeInput, {
375
- ...props,
376
- timezone: "Europe/Paris"
377
- }));
378
- expect(container).toHaveTextContent('May 1, 2017 7:30 PM');
379
- });
380
- it('should show error message if initial value is invalid', async () => {
381
- const _render8 = render(_DateTimeInput2 || (_DateTimeInput2 = _jsx(DateTimeInput, {
382
- description: "date_time",
383
- dateRenderLabel: "date-input",
384
- prevMonthLabel: "Previous month",
385
- nextMonthLabel: "Next month",
386
- timeRenderLabel: "time-input",
387
- invalidDateTimeMessage: "whoops",
388
- value: "totally not a date"
389
- }))),
390
- container = _render8.container;
391
- const dateInput = screen.getByLabelText('date-input');
392
- fireEvent.blur(dateInput);
393
- await waitFor(() => {
394
- expect(container).toHaveTextContent('whoops');
395
- });
396
- });
397
- it('should show error message if initial defaultValue is invalid', async () => {
398
- const _render9 = render(_DateTimeInput3 || (_DateTimeInput3 = _jsx(DateTimeInput, {
399
- description: "date_time",
400
- dateRenderLabel: "date-input",
401
- prevMonthLabel: "Previous month",
402
- nextMonthLabel: "Next month",
403
- timeRenderLabel: "time-input",
404
- invalidDateTimeMessage: "whoops",
405
- defaultValue: "totally not a date"
406
- }))),
407
- container = _render9.container;
408
- const dateInput = screen.getByLabelText('date-input');
409
- fireEvent.blur(dateInput);
410
- await waitFor(() => {
411
- expect(container).toHaveTextContent('whoops');
412
- });
413
- });
414
- it('should update error message when value is invalid', async () => {
415
- const locale = 'en-US';
416
- const timezone = 'US/Eastern';
417
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
418
- const props = {
419
- description: 'date_time',
420
- dateRenderLabel: 'date-input',
421
- prevMonthLabel: 'Previous month',
422
- nextMonthLabel: 'Next month',
423
- timeRenderLabel: 'time-input',
424
- invalidDateTimeMessage: 'whoops',
425
- locale,
426
- timezone,
427
- value: dateTime.toISOString()
428
- };
429
- const _render10 = render(_jsx(DateTimeInput, {
430
- ...props
431
- })),
432
- container = _render10.container,
433
- rerender = _render10.rerender;
434
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
435
- rerender(_jsx(DateTimeInput, {
436
- ...props,
437
- value: "A very invalid date"
438
- }));
439
- const dateInput = screen.getByLabelText('date-input');
440
- fireEvent.blur(dateInput);
441
- await waitFor(() => {
442
- expect(container).toHaveTextContent('whoops');
443
- });
444
- });
445
- it('should show supplied message', async () => {
446
- const locale = 'en-US';
447
- const timezone = 'US/Eastern';
448
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
449
- const props = {
450
- description: 'date_time',
451
- dateRenderLabel: 'date-input',
452
- prevMonthLabel: 'Previous month',
453
- nextMonthLabel: 'Next month',
454
- timeRenderLabel: 'time-input',
455
- invalidDateTimeMessage: 'whoops',
456
- locale,
457
- timezone,
458
- value: dateTime.toISOString()
459
- };
460
- const _render11 = render(_jsx(DateTimeInput, {
461
- ...props
462
- })),
463
- container = _render11.container,
464
- rerender = _render11.rerender;
465
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
466
- rerender(_jsx(DateTimeInput, {
467
- ...props,
468
- messages: [{
469
- text: 'message_text',
470
- type: 'success'
471
- }]
472
- }));
473
- const dateInput = screen.getByLabelText('date-input');
474
- fireEvent.blur(dateInput);
475
- await waitFor(() => {
476
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
477
- expect(container).toHaveTextContent('message_text');
478
- });
479
- });
480
- it('should not show built in message when `showMessages` is false', async () => {
481
- const locale = 'en-US';
482
- const timezone = 'US/Eastern';
483
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
484
- const props = {
485
- description: 'date_time',
486
- dateRenderLabel: 'date-input',
487
- prevMonthLabel: 'Previous month',
488
- nextMonthLabel: 'Next month',
489
- timeRenderLabel: 'time-input',
490
- invalidDateTimeMessage: 'whoops',
491
- locale,
492
- timezone,
493
- value: dateTime.toISOString()
494
- };
495
- const _render12 = render(_jsx(DateTimeInput, {
496
- ...props,
497
- showMessages: false
498
- })),
499
- container = _render12.container,
500
- rerender = _render12.rerender;
501
- expect(container).not.toHaveTextContent('2017');
502
- rerender(_jsx(DateTimeInput, {
503
- ...props,
504
- showMessages: false,
505
- messages: [{
506
- text: 'message_text',
507
- type: 'success'
508
- }]
509
- }));
510
- const dateInput = screen.getByLabelText('date-input');
511
- fireEvent.blur(dateInput);
512
- await waitFor(() => {
513
- expect(container).not.toHaveTextContent('2017');
514
- expect(container).toHaveTextContent('message_text');
515
- });
516
- rerender(_jsx(DateTimeInput, {
517
- ...props,
518
- messages: [{
519
- text: 'message_text',
520
- type: 'success'
521
- }],
522
- showMessages: true
523
- }));
524
- fireEvent.blur(screen.getByLabelText('date-input'));
525
- await waitFor(() => {
526
- expect(container).toHaveTextContent('2017');
527
- expect(container).toHaveTextContent('message_text');
528
- });
529
- });
530
- it('should read locale and timezone from context', () => {
531
- const onChange = vi.fn();
532
- const dateTime = DateTime.parse('2017-05-01T17:30Z', 'en-US', 'GMT');
533
- const _render13 = render(
534
- // Africa/Nairobi is GMT +3
535
- _jsx(ApplyLocale, {
536
- locale: "fr",
537
- timezone: "Africa/Nairobi",
538
- children: _jsx(DateTimeInput, {
539
- description: "date_time",
540
- dateRenderLabel: "date-input",
541
- prevMonthLabel: "Previous month",
542
- nextMonthLabel: "Next month",
543
- timeRenderLabel: "time-input",
544
- invalidDateTimeMessage: "whoops",
545
- value: dateTime.toISOString(),
546
- onChange: onChange
547
- })
548
- })),
549
- container = _render13.container;
550
- expect(container).toHaveTextContent('lundi 1 mai 2017 20:30');
551
- });
552
- it('should format date according to dateFormat', async () => {
553
- const onChange = vi.fn();
554
- const dateTime = DateTime.parse('2017-05-01T17:30Z', 'en-US', 'GMT');
555
- const props = {
556
- description: 'date_time',
557
- dateRenderLabel: 'date-input',
558
- prevMonthLabel: 'Previous month',
559
- nextMonthLabel: 'Next month',
560
- timeRenderLabel: 'time-input',
561
- invalidDateTimeMessage: 'whoops',
562
- value: dateTime.toISOString(),
563
- onChange
564
- };
565
- const _render14 = render(_jsx(DateTimeInput, {
566
- ...props,
567
- dateFormat: "l" // localized numeric date like 9/4/2017
568
- })),
569
- rerender = _render14.rerender;
570
- const dateInput = screen.getByLabelText('date-input');
571
- expect(dateInput).toHaveValue('5/1/2017');
572
- rerender(_jsx(DateTimeInput, {
573
- ...props,
574
- dateFormat: "yyyy MMMM"
575
- }));
576
- fireEvent.blur(screen.getByLabelText('date-input'));
577
- await waitFor(() => {
578
- expect(dateInput).toHaveValue('2017 May');
579
- });
580
- });
581
- it('should format bottom message according to messageFormat', async () => {
582
- const onChange = vi.fn();
583
- const dateTime = DateTime.parse('2017-05-01T17:30Z', 'en-US', 'GMT');
584
- const props = {
585
- description: 'date_time',
586
- dateRenderLabel: 'date-input',
587
- prevMonthLabel: 'Previous month',
588
- nextMonthLabel: 'Next month',
589
- timeRenderLabel: 'time-input',
590
- invalidDateTimeMessage: 'whoops',
591
- value: dateTime.toISOString(),
592
- onChange,
593
- locale: 'en-US',
594
- timezone: 'US/Eastern'
595
- };
596
- const _render15 = render(_jsx(DateTimeInput, {
597
- ...props
598
- })),
599
- container = _render15.container,
600
- rerender = _render15.rerender;
601
- expect(container).toHaveTextContent('Monday, May 1, 2017 1:30 PM');
602
- rerender(_jsx(DateTimeInput, {
603
- ...props,
604
- messageFormat: "l, LT"
605
- }));
606
- fireEvent.blur(screen.getByLabelText('date-input'));
607
- await waitFor(() => {
608
- expect(container).toHaveTextContent('5/1/2017, 1:30 PM');
609
- });
610
- });
611
- it('should update Date and Time inputs when value prop changes', async () => {
612
- const locale = 'en-US';
613
- const timezone = 'US/Eastern';
614
- const dateTime = DateTime.parse('2017-05-01T17:30Z', locale, timezone);
615
- const props = {
616
- description: 'date_time',
617
- dateRenderLabel: 'date-input',
618
- prevMonthLabel: 'Previous month',
619
- nextMonthLabel: 'Next month',
620
- timeRenderLabel: 'time-input',
621
- invalidDateTimeMessage: 'whoops',
622
- locale,
623
- timezone,
624
- value: dateTime.toISOString()
625
- };
626
- const _render16 = render(_jsx(DateTimeInput, {
627
- ...props
628
- })),
629
- container = _render16.container,
630
- rerender = _render16.rerender;
631
- expect(container).toHaveTextContent('May 1, 2017 1:30 PM');
632
- const newDateStr = '2022-03-29T19:00Z';
633
- const newDateTime = DateTime.parse(newDateStr, locale, timezone);
634
- rerender(_jsx(DateTimeInput, {
635
- ...props,
636
- value: newDateStr
637
- }));
638
- const dateInput = screen.getByLabelText('date-input');
639
- const timeInput = screen.getByLabelText('time-input');
640
- fireEvent.blur(dateInput);
641
- await waitFor(() => {
642
- expect(dateInput).toHaveValue(newDateTime.format('LL'));
643
- expect(timeInput).toHaveValue(newDateTime.format('LT'));
644
- });
645
- });
646
- it("should throw warning if initialTimeForNewDate prop's value is not HH:MM", async () => {
647
- const initialTimeForNewDate = 'WRONG_FORMAT';
648
- render(_jsx(DateTimeInput, {
649
- description: "date_time",
650
- dateRenderLabel: "date-input",
651
- prevMonthLabel: "Previous month",
652
- nextMonthLabel: "Next month",
653
- timeRenderLabel: "time-input",
654
- invalidDateTimeMessage: "whoops",
655
- locale: 'en-US',
656
- timezone: 'US/Eastern',
657
- initialTimeForNewDate: initialTimeForNewDate
658
- }));
659
- expect(consoleErrorMock.mock.calls[0][2]).toEqual(expect.stringContaining(`Invalid prop \`initialTimeForNewDate\` \`${initialTimeForNewDate}\` supplied to \`DateTimeInput\`, expected a HH:MM formatted string.`));
660
- });
661
- it("should throw warning if date select and initialTimeForNewDate prop's value is not HH:MM", async () => {
662
- const initialTimeForNewDate = 'WRONG_FORMAT';
663
- render(_jsx(DateTimeInput, {
664
- description: "date_time",
665
- dateRenderLabel: "date-input",
666
- prevMonthLabel: "Previous month",
667
- nextMonthLabel: "Next month",
668
- timeRenderLabel: "time-input",
669
- invalidDateTimeMessage: "whoops",
670
- locale: 'en-US',
671
- timezone: 'US/Eastern',
672
- initialTimeForNewDate: initialTimeForNewDate
673
- }));
674
- const dateInput = screen.getByLabelText('date-input');
675
- fireEvent.change(dateInput, {
676
- target: {
677
- value: 'May 1, 2017'
678
- }
679
- });
680
- fireEvent.keyDown(dateInput, {
681
- key: 'Enter',
682
- code: 'Enter'
683
- });
684
- fireEvent.blur(dateInput);
685
- await waitFor(() => {
686
- expect(consoleErrorMock.mock.calls[0][0]).toBe(`Warning: [DateTimeInput] initialTimeForNewDate prop is not in the correct format. Please use HH:MM format.`);
687
- });
688
- });
689
- it('should throw warning if initialTimeForNewDate prop hour and minute values are not in interval', async () => {
690
- const initialTimeForNewDate = '99:99';
691
- render(_jsx(DateTimeInput, {
692
- description: "date_time",
693
- dateRenderLabel: "date-input",
694
- prevMonthLabel: "Previous month",
695
- nextMonthLabel: "Next month",
696
- timeRenderLabel: "time-input",
697
- invalidDateTimeMessage: "whoops",
698
- locale: 'en-US',
699
- timezone: 'US/Eastern',
700
- initialTimeForNewDate: initialTimeForNewDate
701
- }));
702
- const dateInput = screen.getByLabelText('date-input');
703
- fireEvent.change(dateInput, {
704
- target: {
705
- value: 'May 1, 2017'
706
- }
707
- });
708
- fireEvent.keyDown(dateInput, {
709
- key: 'Enter',
710
- code: 'Enter'
711
- });
712
- fireEvent.blur(dateInput);
713
- await waitFor(() => {
714
- expect(consoleErrorMock.mock.calls[0][0]).toEqual(expect.stringContaining(`Warning: [DateTimeInput] 0 <= hour < 24 and 0 <= minute < 60 for initialTimeForNewDate prop.`));
715
- });
716
- });
717
- it('should initial render prefer defaultValue time over initialTimeForNewDate', async () => {
718
- const locale = 'en-US';
719
- const timezone = 'US/Eastern';
720
- const initialTimeForNewDate = '16:16';
721
- const defaultValue = '2018-01-18T13:30';
722
- const _render17 = render(_jsx(DateTimeInput, {
723
- description: "date_time",
724
- dateRenderLabel: "date-input",
725
- prevMonthLabel: "Previous month",
726
- nextMonthLabel: "Next month",
727
- timeRenderLabel: "time-input",
728
- invalidDateTimeMessage: "whoops",
729
- defaultValue: defaultValue,
730
- locale: locale,
731
- timezone: timezone,
732
- initialTimeForNewDate: initialTimeForNewDate
733
- })),
734
- container = _render17.container;
735
- const timeInput = screen.getByLabelText('time-input');
736
- expect(timeInput).toHaveValue('1:30 PM');
737
- expect(container).toHaveTextContent('Thursday, January 18, 2018 1:30 PM');
738
- });
739
- });