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