@instructure/ui-date-input 9.2.1-snapshot-1 → 9.2.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/DateInput/__new-tests__/DateInput.test.js +33 -21
- package/lib/DateInput/__new-tests__/DateInput.test.js +33 -21
- package/package.json +21 -20
- package/src/DateInput/__new-tests__/DateInput.test.tsx +40 -21
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput/__new-tests__/DateInput.test.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [9.2.1-snapshot-
|
|
6
|
+
## [9.2.1-snapshot-3](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-3) (2024-07-12)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-date-input
|
|
9
9
|
|
|
@@ -24,6 +24,7 @@ var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
|
|
|
24
24
|
*/
|
|
25
25
|
import React from 'react';
|
|
26
26
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
27
|
+
import { vi } from 'vitest';
|
|
27
28
|
import userEvent from '@testing-library/user-event';
|
|
28
29
|
import '@testing-library/jest-dom';
|
|
29
30
|
|
|
@@ -48,6 +49,17 @@ describe('<DateInput />', () => {
|
|
|
48
49
|
}
|
|
49
50
|
return days;
|
|
50
51
|
};
|
|
52
|
+
let consoleWarningMock;
|
|
53
|
+
let consoleErrorMock;
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
// Mocking console to prevent test output pollution
|
|
56
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
57
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
58
|
+
});
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
consoleWarningMock.mockRestore();
|
|
61
|
+
consoleErrorMock.mockRestore();
|
|
62
|
+
});
|
|
51
63
|
it('should render an input and a calendar', async () => {
|
|
52
64
|
const _render = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
53
65
|
renderLabel: "date-input",
|
|
@@ -82,14 +94,14 @@ describe('<DateInput />', () => {
|
|
|
82
94
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
83
95
|
renderLabel: "Choose date",
|
|
84
96
|
value: value,
|
|
85
|
-
onChange:
|
|
97
|
+
onChange: vi.fn(),
|
|
86
98
|
renderWeekdayLabels: weekdayLabels
|
|
87
99
|
}, generateDays()));
|
|
88
100
|
const dateInput = screen.getByLabelText('Choose date');
|
|
89
101
|
expect(dateInput).toHaveValue(value);
|
|
90
102
|
});
|
|
91
103
|
it('should call onChange with the updated value', async () => {
|
|
92
|
-
const onChange =
|
|
104
|
+
const onChange = vi.fn();
|
|
93
105
|
const value = 'May 18, 2022';
|
|
94
106
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
95
107
|
renderLabel: "Choose date",
|
|
@@ -113,7 +125,7 @@ describe('<DateInput />', () => {
|
|
|
113
125
|
});
|
|
114
126
|
});
|
|
115
127
|
it('should call onBlur', () => {
|
|
116
|
-
const onBlur =
|
|
128
|
+
const onBlur = vi.fn();
|
|
117
129
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
118
130
|
renderLabel: "Choose date",
|
|
119
131
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -180,7 +192,7 @@ describe('<DateInput />', () => {
|
|
|
180
192
|
expect(dateInput).toHaveAttribute('required');
|
|
181
193
|
});
|
|
182
194
|
it('should provide inputRef', () => {
|
|
183
|
-
const inputRef =
|
|
195
|
+
const inputRef = vi.fn();
|
|
184
196
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
185
197
|
renderLabel: "Choose date",
|
|
186
198
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -244,7 +256,7 @@ describe('<DateInput />', () => {
|
|
|
244
256
|
});
|
|
245
257
|
describe('onRequestShowCalendar', () => {
|
|
246
258
|
it('should call onRequestShowCalendar when label is clicked', async () => {
|
|
247
|
-
const onRequestShowCalendar =
|
|
259
|
+
const onRequestShowCalendar = vi.fn();
|
|
248
260
|
const _render5 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
249
261
|
renderLabel: "Choose date",
|
|
250
262
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -259,7 +271,7 @@ describe('<DateInput />', () => {
|
|
|
259
271
|
});
|
|
260
272
|
});
|
|
261
273
|
it('should call onRequestShowCalendar when input is clicked', async () => {
|
|
262
|
-
const onRequestShowCalendar =
|
|
274
|
+
const onRequestShowCalendar = vi.fn();
|
|
263
275
|
const _render6 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
264
276
|
renderLabel: "Choose date",
|
|
265
277
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -273,7 +285,7 @@ describe('<DateInput />', () => {
|
|
|
273
285
|
});
|
|
274
286
|
});
|
|
275
287
|
it('should call onRequestShowCalendar when input receives space event', async () => {
|
|
276
|
-
const onRequestShowCalendar =
|
|
288
|
+
const onRequestShowCalendar = vi.fn();
|
|
277
289
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
278
290
|
renderLabel: "Choose date",
|
|
279
291
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -286,7 +298,7 @@ describe('<DateInput />', () => {
|
|
|
286
298
|
});
|
|
287
299
|
});
|
|
288
300
|
it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
|
|
289
|
-
const onRequestShowCalendar =
|
|
301
|
+
const onRequestShowCalendar = vi.fn();
|
|
290
302
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
291
303
|
renderLabel: "Choose date",
|
|
292
304
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -300,7 +312,7 @@ describe('<DateInput />', () => {
|
|
|
300
312
|
});
|
|
301
313
|
});
|
|
302
314
|
it('should call onRequestShowCalendar when input receives down arrow event', async () => {
|
|
303
|
-
const onRequestShowCalendar =
|
|
315
|
+
const onRequestShowCalendar = vi.fn();
|
|
304
316
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
305
317
|
renderLabel: "Choose date",
|
|
306
318
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -313,7 +325,7 @@ describe('<DateInput />', () => {
|
|
|
313
325
|
});
|
|
314
326
|
});
|
|
315
327
|
it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
|
|
316
|
-
const onRequestShowCalendar =
|
|
328
|
+
const onRequestShowCalendar = vi.fn();
|
|
317
329
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
318
330
|
renderLabel: "Choose date",
|
|
319
331
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -327,7 +339,7 @@ describe('<DateInput />', () => {
|
|
|
327
339
|
});
|
|
328
340
|
});
|
|
329
341
|
it('should call onRequestShowCalendar when input receives up arrow event', async () => {
|
|
330
|
-
const onRequestShowCalendar =
|
|
342
|
+
const onRequestShowCalendar = vi.fn();
|
|
331
343
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
332
344
|
renderLabel: "Choose date",
|
|
333
345
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -340,7 +352,7 @@ describe('<DateInput />', () => {
|
|
|
340
352
|
});
|
|
341
353
|
});
|
|
342
354
|
it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
|
|
343
|
-
const onRequestShowCalendar =
|
|
355
|
+
const onRequestShowCalendar = vi.fn();
|
|
344
356
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
345
357
|
renderLabel: "Choose date",
|
|
346
358
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -354,7 +366,7 @@ describe('<DateInput />', () => {
|
|
|
354
366
|
});
|
|
355
367
|
});
|
|
356
368
|
it('should call onRequestShowCalendar when input receives onChange event', async () => {
|
|
357
|
-
const onRequestShowCalendar =
|
|
369
|
+
const onRequestShowCalendar = vi.fn();
|
|
358
370
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
359
371
|
renderLabel: "Choose date",
|
|
360
372
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -371,7 +383,7 @@ describe('<DateInput />', () => {
|
|
|
371
383
|
});
|
|
372
384
|
});
|
|
373
385
|
it('should not call onRequestShowCalendar when disabled', async () => {
|
|
374
|
-
const onRequestShowCalendar =
|
|
386
|
+
const onRequestShowCalendar = vi.fn();
|
|
375
387
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
376
388
|
renderLabel: "Choose date",
|
|
377
389
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -390,8 +402,8 @@ describe('<DateInput />', () => {
|
|
|
390
402
|
});
|
|
391
403
|
describe('onRequestHideCalendar and onRequestValidateDate', () => {
|
|
392
404
|
it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
|
|
393
|
-
const onRequestHideCalendar =
|
|
394
|
-
const onRequestValidateDate =
|
|
405
|
+
const onRequestHideCalendar = vi.fn();
|
|
406
|
+
const onRequestValidateDate = vi.fn();
|
|
395
407
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
396
408
|
renderLabel: "Choose date",
|
|
397
409
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -407,8 +419,8 @@ describe('<DateInput />', () => {
|
|
|
407
419
|
});
|
|
408
420
|
});
|
|
409
421
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
|
|
410
|
-
const onRequestHideCalendar =
|
|
411
|
-
const onRequestValidateDate =
|
|
422
|
+
const onRequestHideCalendar = vi.fn();
|
|
423
|
+
const onRequestValidateDate = vi.fn();
|
|
412
424
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
413
425
|
renderLabel: "Choose date",
|
|
414
426
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -424,8 +436,8 @@ describe('<DateInput />', () => {
|
|
|
424
436
|
});
|
|
425
437
|
});
|
|
426
438
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives enter event', async () => {
|
|
427
|
-
const onRequestHideCalendar =
|
|
428
|
-
const onRequestValidateDate =
|
|
439
|
+
const onRequestHideCalendar = vi.fn();
|
|
440
|
+
const onRequestValidateDate = vi.fn();
|
|
429
441
|
const days = generateDays();
|
|
430
442
|
days[4] = _Calendar$Day || (_Calendar$Day = /*#__PURE__*/React.createElement(Calendar.Day, {
|
|
431
443
|
key: "4",
|
|
@@ -564,7 +576,7 @@ describe('<DateInput />', () => {
|
|
|
564
576
|
});
|
|
565
577
|
describe('with minimal config', () => {
|
|
566
578
|
it('should render 44 buttons (a calendar) when clicked', async () => {
|
|
567
|
-
const onChange =
|
|
579
|
+
const onChange = vi.fn();
|
|
568
580
|
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
569
581
|
renderLabel: "Choose date",
|
|
570
582
|
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
|
@@ -3,6 +3,7 @@
|
|
|
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 _vitest = require("vitest");
|
|
6
7
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
8
|
require("@testing-library/jest-dom");
|
|
8
9
|
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
@@ -50,6 +51,17 @@ describe('<DateInput />', () => {
|
|
|
50
51
|
}
|
|
51
52
|
return days;
|
|
52
53
|
};
|
|
54
|
+
let consoleWarningMock;
|
|
55
|
+
let consoleErrorMock;
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
// Mocking console to prevent test output pollution
|
|
58
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
59
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
60
|
+
});
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
consoleWarningMock.mockRestore();
|
|
63
|
+
consoleErrorMock.mockRestore();
|
|
64
|
+
});
|
|
53
65
|
it('should render an input and a calendar', async () => {
|
|
54
66
|
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
55
67
|
renderLabel: "date-input",
|
|
@@ -84,14 +96,14 @@ describe('<DateInput />', () => {
|
|
|
84
96
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
85
97
|
renderLabel: "Choose date",
|
|
86
98
|
value: value,
|
|
87
|
-
onChange:
|
|
99
|
+
onChange: _vitest.vi.fn(),
|
|
88
100
|
renderWeekdayLabels: weekdayLabels
|
|
89
101
|
}, generateDays()));
|
|
90
102
|
const dateInput = _react2.screen.getByLabelText('Choose date');
|
|
91
103
|
expect(dateInput).toHaveValue(value);
|
|
92
104
|
});
|
|
93
105
|
it('should call onChange with the updated value', async () => {
|
|
94
|
-
const onChange =
|
|
106
|
+
const onChange = _vitest.vi.fn();
|
|
95
107
|
const value = 'May 18, 2022';
|
|
96
108
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
97
109
|
renderLabel: "Choose date",
|
|
@@ -115,7 +127,7 @@ describe('<DateInput />', () => {
|
|
|
115
127
|
});
|
|
116
128
|
});
|
|
117
129
|
it('should call onBlur', () => {
|
|
118
|
-
const onBlur =
|
|
130
|
+
const onBlur = _vitest.vi.fn();
|
|
119
131
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
120
132
|
renderLabel: "Choose date",
|
|
121
133
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -182,7 +194,7 @@ describe('<DateInput />', () => {
|
|
|
182
194
|
expect(dateInput).toHaveAttribute('required');
|
|
183
195
|
});
|
|
184
196
|
it('should provide inputRef', () => {
|
|
185
|
-
const inputRef =
|
|
197
|
+
const inputRef = _vitest.vi.fn();
|
|
186
198
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
187
199
|
renderLabel: "Choose date",
|
|
188
200
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -246,7 +258,7 @@ describe('<DateInput />', () => {
|
|
|
246
258
|
});
|
|
247
259
|
describe('onRequestShowCalendar', () => {
|
|
248
260
|
it('should call onRequestShowCalendar when label is clicked', async () => {
|
|
249
|
-
const onRequestShowCalendar =
|
|
261
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
250
262
|
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
251
263
|
renderLabel: "Choose date",
|
|
252
264
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -261,7 +273,7 @@ describe('<DateInput />', () => {
|
|
|
261
273
|
});
|
|
262
274
|
});
|
|
263
275
|
it('should call onRequestShowCalendar when input is clicked', async () => {
|
|
264
|
-
const onRequestShowCalendar =
|
|
276
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
265
277
|
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
266
278
|
renderLabel: "Choose date",
|
|
267
279
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -275,7 +287,7 @@ describe('<DateInput />', () => {
|
|
|
275
287
|
});
|
|
276
288
|
});
|
|
277
289
|
it('should call onRequestShowCalendar when input receives space event', async () => {
|
|
278
|
-
const onRequestShowCalendar =
|
|
290
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
279
291
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
280
292
|
renderLabel: "Choose date",
|
|
281
293
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -288,7 +300,7 @@ describe('<DateInput />', () => {
|
|
|
288
300
|
});
|
|
289
301
|
});
|
|
290
302
|
it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
|
|
291
|
-
const onRequestShowCalendar =
|
|
303
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
292
304
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
293
305
|
renderLabel: "Choose date",
|
|
294
306
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -302,7 +314,7 @@ describe('<DateInput />', () => {
|
|
|
302
314
|
});
|
|
303
315
|
});
|
|
304
316
|
it('should call onRequestShowCalendar when input receives down arrow event', async () => {
|
|
305
|
-
const onRequestShowCalendar =
|
|
317
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
306
318
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
307
319
|
renderLabel: "Choose date",
|
|
308
320
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -315,7 +327,7 @@ describe('<DateInput />', () => {
|
|
|
315
327
|
});
|
|
316
328
|
});
|
|
317
329
|
it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
|
|
318
|
-
const onRequestShowCalendar =
|
|
330
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
319
331
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
320
332
|
renderLabel: "Choose date",
|
|
321
333
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -329,7 +341,7 @@ describe('<DateInput />', () => {
|
|
|
329
341
|
});
|
|
330
342
|
});
|
|
331
343
|
it('should call onRequestShowCalendar when input receives up arrow event', async () => {
|
|
332
|
-
const onRequestShowCalendar =
|
|
344
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
333
345
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
334
346
|
renderLabel: "Choose date",
|
|
335
347
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -342,7 +354,7 @@ describe('<DateInput />', () => {
|
|
|
342
354
|
});
|
|
343
355
|
});
|
|
344
356
|
it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
|
|
345
|
-
const onRequestShowCalendar =
|
|
357
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
346
358
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
347
359
|
renderLabel: "Choose date",
|
|
348
360
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -356,7 +368,7 @@ describe('<DateInput />', () => {
|
|
|
356
368
|
});
|
|
357
369
|
});
|
|
358
370
|
it('should call onRequestShowCalendar when input receives onChange event', async () => {
|
|
359
|
-
const onRequestShowCalendar =
|
|
371
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
360
372
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
361
373
|
renderLabel: "Choose date",
|
|
362
374
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -373,7 +385,7 @@ describe('<DateInput />', () => {
|
|
|
373
385
|
});
|
|
374
386
|
});
|
|
375
387
|
it('should not call onRequestShowCalendar when disabled', async () => {
|
|
376
|
-
const onRequestShowCalendar =
|
|
388
|
+
const onRequestShowCalendar = _vitest.vi.fn();
|
|
377
389
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
378
390
|
renderLabel: "Choose date",
|
|
379
391
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -392,8 +404,8 @@ describe('<DateInput />', () => {
|
|
|
392
404
|
});
|
|
393
405
|
describe('onRequestHideCalendar and onRequestValidateDate', () => {
|
|
394
406
|
it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
|
|
395
|
-
const onRequestHideCalendar =
|
|
396
|
-
const onRequestValidateDate =
|
|
407
|
+
const onRequestHideCalendar = _vitest.vi.fn();
|
|
408
|
+
const onRequestValidateDate = _vitest.vi.fn();
|
|
397
409
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
398
410
|
renderLabel: "Choose date",
|
|
399
411
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -409,8 +421,8 @@ describe('<DateInput />', () => {
|
|
|
409
421
|
});
|
|
410
422
|
});
|
|
411
423
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
|
|
412
|
-
const onRequestHideCalendar =
|
|
413
|
-
const onRequestValidateDate =
|
|
424
|
+
const onRequestHideCalendar = _vitest.vi.fn();
|
|
425
|
+
const onRequestValidateDate = _vitest.vi.fn();
|
|
414
426
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
415
427
|
renderLabel: "Choose date",
|
|
416
428
|
renderWeekdayLabels: weekdayLabels,
|
|
@@ -426,8 +438,8 @@ describe('<DateInput />', () => {
|
|
|
426
438
|
});
|
|
427
439
|
});
|
|
428
440
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives enter event', async () => {
|
|
429
|
-
const onRequestHideCalendar =
|
|
430
|
-
const onRequestValidateDate =
|
|
441
|
+
const onRequestHideCalendar = _vitest.vi.fn();
|
|
442
|
+
const onRequestValidateDate = _vitest.vi.fn();
|
|
431
443
|
const days = generateDays();
|
|
432
444
|
days[4] = _Calendar$Day || (_Calendar$Day = /*#__PURE__*/_react.default.createElement(_Calendar.Calendar.Day, {
|
|
433
445
|
key: "4",
|
|
@@ -566,7 +578,7 @@ describe('<DateInput />', () => {
|
|
|
566
578
|
});
|
|
567
579
|
describe('with minimal config', () => {
|
|
568
580
|
it('should render 44 buttons (a calendar) when clicked', async () => {
|
|
569
|
-
const onChange =
|
|
581
|
+
const onChange = _vitest.vi.fn();
|
|
570
582
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
571
583
|
renderLabel: "Choose date",
|
|
572
584
|
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-date-input",
|
|
3
|
-
"version": "9.2.1-snapshot-
|
|
3
|
+
"version": "9.2.1-snapshot-3",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,30 +23,31 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "9.2.1-snapshot-
|
|
27
|
-
"@instructure/ui-babel-preset": "9.2.1-snapshot-
|
|
28
|
-
"@instructure/ui-scripts": "9.2.1-snapshot-
|
|
29
|
-
"@instructure/ui-test-utils": "9.2.1-snapshot-
|
|
26
|
+
"@instructure/ui-axe-check": "9.2.1-snapshot-3",
|
|
27
|
+
"@instructure/ui-babel-preset": "9.2.1-snapshot-3",
|
|
28
|
+
"@instructure/ui-scripts": "9.2.1-snapshot-3",
|
|
29
|
+
"@instructure/ui-test-utils": "9.2.1-snapshot-3",
|
|
30
30
|
"@testing-library/jest-dom": "^6.4.5",
|
|
31
31
|
"@testing-library/react": "^15.0.7",
|
|
32
|
-
"@testing-library/user-event": "^14.5.2"
|
|
32
|
+
"@testing-library/user-event": "^14.5.2",
|
|
33
|
+
"vitest": "^1.6.0"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@babel/runtime": "^7.24.5",
|
|
36
|
-
"@instructure/emotion": "9.2.1-snapshot-
|
|
37
|
-
"@instructure/shared-types": "9.2.1-snapshot-
|
|
38
|
-
"@instructure/ui-calendar": "9.2.1-snapshot-
|
|
39
|
-
"@instructure/ui-form-field": "9.2.1-snapshot-
|
|
40
|
-
"@instructure/ui-i18n": "9.2.1-snapshot-
|
|
41
|
-
"@instructure/ui-icons": "9.2.1-snapshot-
|
|
42
|
-
"@instructure/ui-popover": "9.2.1-snapshot-
|
|
43
|
-
"@instructure/ui-position": "9.2.1-snapshot-
|
|
44
|
-
"@instructure/ui-prop-types": "9.2.1-snapshot-
|
|
45
|
-
"@instructure/ui-react-utils": "9.2.1-snapshot-
|
|
46
|
-
"@instructure/ui-selectable": "9.2.1-snapshot-
|
|
47
|
-
"@instructure/ui-testable": "9.2.1-snapshot-
|
|
48
|
-
"@instructure/ui-text-input": "9.2.1-snapshot-
|
|
49
|
-
"@instructure/ui-utils": "9.2.1-snapshot-
|
|
37
|
+
"@instructure/emotion": "9.2.1-snapshot-3",
|
|
38
|
+
"@instructure/shared-types": "9.2.1-snapshot-3",
|
|
39
|
+
"@instructure/ui-calendar": "9.2.1-snapshot-3",
|
|
40
|
+
"@instructure/ui-form-field": "9.2.1-snapshot-3",
|
|
41
|
+
"@instructure/ui-i18n": "9.2.1-snapshot-3",
|
|
42
|
+
"@instructure/ui-icons": "9.2.1-snapshot-3",
|
|
43
|
+
"@instructure/ui-popover": "9.2.1-snapshot-3",
|
|
44
|
+
"@instructure/ui-position": "9.2.1-snapshot-3",
|
|
45
|
+
"@instructure/ui-prop-types": "9.2.1-snapshot-3",
|
|
46
|
+
"@instructure/ui-react-utils": "9.2.1-snapshot-3",
|
|
47
|
+
"@instructure/ui-selectable": "9.2.1-snapshot-3",
|
|
48
|
+
"@instructure/ui-testable": "9.2.1-snapshot-3",
|
|
49
|
+
"@instructure/ui-text-input": "9.2.1-snapshot-3",
|
|
50
|
+
"@instructure/ui-utils": "9.2.1-snapshot-3",
|
|
50
51
|
"prop-types": "^15.8.1"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import React from 'react'
|
|
25
25
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
26
|
+
import { vi } from 'vitest'
|
|
26
27
|
import userEvent from '@testing-library/user-event'
|
|
27
28
|
import '@testing-library/jest-dom'
|
|
28
29
|
|
|
@@ -57,6 +58,24 @@ describe('<DateInput />', () => {
|
|
|
57
58
|
return days
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
62
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
// Mocking console to prevent test output pollution
|
|
66
|
+
consoleWarningMock = vi
|
|
67
|
+
.spyOn(console, 'warn')
|
|
68
|
+
.mockImplementation(() => {}) as any
|
|
69
|
+
consoleErrorMock = vi
|
|
70
|
+
.spyOn(console, 'error')
|
|
71
|
+
.mockImplementation(() => {}) as any
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
afterEach(() => {
|
|
75
|
+
consoleWarningMock.mockRestore()
|
|
76
|
+
consoleErrorMock.mockRestore()
|
|
77
|
+
})
|
|
78
|
+
|
|
60
79
|
it('should render an input and a calendar', async () => {
|
|
61
80
|
const { container, findByRole } = render(
|
|
62
81
|
<DateInput
|
|
@@ -105,7 +124,7 @@ describe('<DateInput />', () => {
|
|
|
105
124
|
<DateInput
|
|
106
125
|
renderLabel="Choose date"
|
|
107
126
|
value={value}
|
|
108
|
-
onChange={
|
|
127
|
+
onChange={vi.fn()}
|
|
109
128
|
renderWeekdayLabels={weekdayLabels}
|
|
110
129
|
>
|
|
111
130
|
{generateDays()}
|
|
@@ -117,7 +136,7 @@ describe('<DateInput />', () => {
|
|
|
117
136
|
})
|
|
118
137
|
|
|
119
138
|
it('should call onChange with the updated value', async () => {
|
|
120
|
-
const onChange =
|
|
139
|
+
const onChange = vi.fn()
|
|
121
140
|
const value = 'May 18, 2022'
|
|
122
141
|
|
|
123
142
|
render(
|
|
@@ -144,7 +163,7 @@ describe('<DateInput />', () => {
|
|
|
144
163
|
})
|
|
145
164
|
|
|
146
165
|
it('should call onBlur', () => {
|
|
147
|
-
const onBlur =
|
|
166
|
+
const onBlur = vi.fn()
|
|
148
167
|
|
|
149
168
|
render(
|
|
150
169
|
<DateInput
|
|
@@ -257,7 +276,7 @@ describe('<DateInput />', () => {
|
|
|
257
276
|
})
|
|
258
277
|
|
|
259
278
|
it('should provide inputRef', () => {
|
|
260
|
-
const inputRef =
|
|
279
|
+
const inputRef = vi.fn()
|
|
261
280
|
|
|
262
281
|
render(
|
|
263
282
|
<DateInput
|
|
@@ -351,7 +370,7 @@ describe('<DateInput />', () => {
|
|
|
351
370
|
|
|
352
371
|
describe('onRequestShowCalendar', () => {
|
|
353
372
|
it('should call onRequestShowCalendar when label is clicked', async () => {
|
|
354
|
-
const onRequestShowCalendar =
|
|
373
|
+
const onRequestShowCalendar = vi.fn()
|
|
355
374
|
|
|
356
375
|
const { container } = render(
|
|
357
376
|
<DateInput
|
|
@@ -374,7 +393,7 @@ describe('<DateInput />', () => {
|
|
|
374
393
|
})
|
|
375
394
|
|
|
376
395
|
it('should call onRequestShowCalendar when input is clicked', async () => {
|
|
377
|
-
const onRequestShowCalendar =
|
|
396
|
+
const onRequestShowCalendar = vi.fn()
|
|
378
397
|
|
|
379
398
|
const { container } = render(
|
|
380
399
|
<DateInput
|
|
@@ -395,7 +414,7 @@ describe('<DateInput />', () => {
|
|
|
395
414
|
})
|
|
396
415
|
|
|
397
416
|
it('should call onRequestShowCalendar when input receives space event', async () => {
|
|
398
|
-
const onRequestShowCalendar =
|
|
417
|
+
const onRequestShowCalendar = vi.fn()
|
|
399
418
|
|
|
400
419
|
render(
|
|
401
420
|
<DateInput
|
|
@@ -416,7 +435,7 @@ describe('<DateInput />', () => {
|
|
|
416
435
|
})
|
|
417
436
|
|
|
418
437
|
it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
|
|
419
|
-
const onRequestShowCalendar =
|
|
438
|
+
const onRequestShowCalendar = vi.fn()
|
|
420
439
|
|
|
421
440
|
render(
|
|
422
441
|
<DateInput
|
|
@@ -438,7 +457,7 @@ describe('<DateInput />', () => {
|
|
|
438
457
|
})
|
|
439
458
|
|
|
440
459
|
it('should call onRequestShowCalendar when input receives down arrow event', async () => {
|
|
441
|
-
const onRequestShowCalendar =
|
|
460
|
+
const onRequestShowCalendar = vi.fn()
|
|
442
461
|
|
|
443
462
|
render(
|
|
444
463
|
<DateInput
|
|
@@ -459,7 +478,7 @@ describe('<DateInput />', () => {
|
|
|
459
478
|
})
|
|
460
479
|
|
|
461
480
|
it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
|
|
462
|
-
const onRequestShowCalendar =
|
|
481
|
+
const onRequestShowCalendar = vi.fn()
|
|
463
482
|
|
|
464
483
|
render(
|
|
465
484
|
<DateInput
|
|
@@ -481,7 +500,7 @@ describe('<DateInput />', () => {
|
|
|
481
500
|
})
|
|
482
501
|
|
|
483
502
|
it('should call onRequestShowCalendar when input receives up arrow event', async () => {
|
|
484
|
-
const onRequestShowCalendar =
|
|
503
|
+
const onRequestShowCalendar = vi.fn()
|
|
485
504
|
|
|
486
505
|
render(
|
|
487
506
|
<DateInput
|
|
@@ -502,7 +521,7 @@ describe('<DateInput />', () => {
|
|
|
502
521
|
})
|
|
503
522
|
|
|
504
523
|
it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
|
|
505
|
-
const onRequestShowCalendar =
|
|
524
|
+
const onRequestShowCalendar = vi.fn()
|
|
506
525
|
|
|
507
526
|
render(
|
|
508
527
|
<DateInput
|
|
@@ -524,7 +543,7 @@ describe('<DateInput />', () => {
|
|
|
524
543
|
})
|
|
525
544
|
|
|
526
545
|
it('should call onRequestShowCalendar when input receives onChange event', async () => {
|
|
527
|
-
const onRequestShowCalendar =
|
|
546
|
+
const onRequestShowCalendar = vi.fn()
|
|
528
547
|
|
|
529
548
|
render(
|
|
530
549
|
<DateInput
|
|
@@ -545,7 +564,7 @@ describe('<DateInput />', () => {
|
|
|
545
564
|
})
|
|
546
565
|
|
|
547
566
|
it('should not call onRequestShowCalendar when disabled', async () => {
|
|
548
|
-
const onRequestShowCalendar =
|
|
567
|
+
const onRequestShowCalendar = vi.fn()
|
|
549
568
|
|
|
550
569
|
render(
|
|
551
570
|
<DateInput
|
|
@@ -575,8 +594,8 @@ describe('<DateInput />', () => {
|
|
|
575
594
|
|
|
576
595
|
describe('onRequestHideCalendar and onRequestValidateDate', () => {
|
|
577
596
|
it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
|
|
578
|
-
const onRequestHideCalendar =
|
|
579
|
-
const onRequestValidateDate =
|
|
597
|
+
const onRequestHideCalendar = vi.fn()
|
|
598
|
+
const onRequestValidateDate = vi.fn()
|
|
580
599
|
|
|
581
600
|
render(
|
|
582
601
|
<DateInput
|
|
@@ -600,8 +619,8 @@ describe('<DateInput />', () => {
|
|
|
600
619
|
})
|
|
601
620
|
|
|
602
621
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
|
|
603
|
-
const onRequestHideCalendar =
|
|
604
|
-
const onRequestValidateDate =
|
|
622
|
+
const onRequestHideCalendar = vi.fn()
|
|
623
|
+
const onRequestValidateDate = vi.fn()
|
|
605
624
|
|
|
606
625
|
render(
|
|
607
626
|
<DateInput
|
|
@@ -625,8 +644,8 @@ describe('<DateInput />', () => {
|
|
|
625
644
|
})
|
|
626
645
|
|
|
627
646
|
it('should call onRequestHideCalendar and onRequestValidateDate when input receives enter event', async () => {
|
|
628
|
-
const onRequestHideCalendar =
|
|
629
|
-
const onRequestValidateDate =
|
|
647
|
+
const onRequestHideCalendar = vi.fn()
|
|
648
|
+
const onRequestValidateDate = vi.fn()
|
|
630
649
|
|
|
631
650
|
const days = generateDays()
|
|
632
651
|
days[4] = (
|
|
@@ -811,7 +830,7 @@ describe('<DateInput />', () => {
|
|
|
811
830
|
|
|
812
831
|
describe('with minimal config', () => {
|
|
813
832
|
it('should render 44 buttons (a calendar) when clicked', async () => {
|
|
814
|
-
const onChange =
|
|
833
|
+
const onChange = vi.fn()
|
|
815
834
|
render(
|
|
816
835
|
<DateInput
|
|
817
836
|
renderLabel="Choose date"
|