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