@instructure/ui-time-select 10.16.1-snapshot-0 → 10.16.1
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/TimeSelect/__new-tests__/TimeSelect.test.js +29 -26
- package/es/TimeSelect/index.js +15 -11
- package/lib/TimeSelect/__new-tests__/TimeSelect.test.js +58 -56
- package/lib/TimeSelect/index.js +15 -12
- package/package.json +13 -13
- package/src/TimeSelect/__new-tests__/TimeSelect.test.tsx +1 -1
- package/src/TimeSelect/index.tsx +1 -1
- package/src/TimeSelect/props.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TimeSelect/index.d.ts +5 -5
- package/types/TimeSelect/index.d.ts.map +1 -1
- package/types/TimeSelect/props.d.ts +1 -1
- package/types/TimeSelect/props.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
|
-
## [10.16.1
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-time-select
|
|
9
9
|
|
|
@@ -22,7 +22,7 @@ var _TimeSelect, _TimeSelect2, _TimeSelect3, _TimeSelect4, _TimeSelect5, _TimeSe
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
27
27
|
import { vi } from 'vitest';
|
|
28
28
|
import userEvent from '@testing-library/user-event';
|
|
@@ -35,6 +35,7 @@ import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
|
35
35
|
import { ApplyLocale } from '@instructure/ui-i18n';
|
|
36
36
|
import { TimeSelect } from '../index';
|
|
37
37
|
import TimeSelectExamples from '../__examples__/TimeSelect.examples';
|
|
38
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
38
39
|
describe('<TimeSelect />', () => {
|
|
39
40
|
let consoleWarningMock;
|
|
40
41
|
let consoleErrorMock;
|
|
@@ -49,7 +50,7 @@ describe('<TimeSelect />', () => {
|
|
|
49
50
|
});
|
|
50
51
|
it('should fire onFocus when input gains focus', async () => {
|
|
51
52
|
const onFocus = vi.fn();
|
|
52
|
-
render(
|
|
53
|
+
render(_jsx(TimeSelect, {
|
|
53
54
|
renderLabel: "Choose a time",
|
|
54
55
|
onFocus: onFocus
|
|
55
56
|
}));
|
|
@@ -62,7 +63,7 @@ describe('<TimeSelect />', () => {
|
|
|
62
63
|
it('should render a default value', async () => {
|
|
63
64
|
const defaultValue = moment.tz('1986-05-17T18:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
64
65
|
const onChange = vi.fn();
|
|
65
|
-
render(
|
|
66
|
+
render(_jsx(TimeSelect, {
|
|
66
67
|
renderLabel: "Choose a time",
|
|
67
68
|
onChange: onChange,
|
|
68
69
|
timezone: "US/Eastern",
|
|
@@ -74,7 +75,7 @@ describe('<TimeSelect />', () => {
|
|
|
74
75
|
it('should display value when both defaultValue and value are set', async () => {
|
|
75
76
|
const value = moment.tz('1986-05-17T18:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
76
77
|
const defaultValue = moment.tz('1986-05-25T19:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
77
|
-
render(
|
|
78
|
+
render(_jsx(TimeSelect, {
|
|
78
79
|
renderLabel: "Choose a time",
|
|
79
80
|
timezone: "US/Eastern",
|
|
80
81
|
value: value.toISOString(),
|
|
@@ -84,7 +85,7 @@ describe('<TimeSelect />', () => {
|
|
|
84
85
|
expect(input).toHaveValue(value.format('LT'));
|
|
85
86
|
});
|
|
86
87
|
it('should default to the first option if defaultToFirstOption is true', async () => {
|
|
87
|
-
render(_TimeSelect || (_TimeSelect =
|
|
88
|
+
render(_TimeSelect || (_TimeSelect = _jsx(TimeSelect, {
|
|
88
89
|
renderLabel: "Choose a time",
|
|
89
90
|
defaultToFirstOption: true
|
|
90
91
|
})));
|
|
@@ -93,7 +94,7 @@ describe('<TimeSelect />', () => {
|
|
|
93
94
|
});
|
|
94
95
|
it('should use the specified timezone', async () => {
|
|
95
96
|
const value = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'fr', 'UTC');
|
|
96
|
-
render(
|
|
97
|
+
render(_jsx(TimeSelect, {
|
|
97
98
|
renderLabel: "Choose a time",
|
|
98
99
|
locale: "fr",
|
|
99
100
|
timezone: "Africa/Nairobi" // UTC + 3
|
|
@@ -107,7 +108,7 @@ describe('<TimeSelect />', () => {
|
|
|
107
108
|
const value = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'fr',
|
|
108
109
|
// 24-hour clock
|
|
109
110
|
'UTC');
|
|
110
|
-
render(
|
|
111
|
+
render(_jsx(TimeSelect, {
|
|
111
112
|
renderLabel: "Choose a time",
|
|
112
113
|
locale: "en" // 12-hour clock
|
|
113
114
|
,
|
|
@@ -122,7 +123,7 @@ describe('<TimeSelect />', () => {
|
|
|
122
123
|
);
|
|
123
124
|
const valueWinter = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'en', 'UTC' // no time offset
|
|
124
125
|
);
|
|
125
|
-
const _render = render(
|
|
126
|
+
const _render = render(_jsx(TimeSelect, {
|
|
126
127
|
renderLabel: "Choose a time",
|
|
127
128
|
locale: "en",
|
|
128
129
|
timezone: "Europe/London" // summer time offset
|
|
@@ -132,7 +133,7 @@ describe('<TimeSelect />', () => {
|
|
|
132
133
|
rerender = _render.rerender;
|
|
133
134
|
const input = screen.getByRole('combobox');
|
|
134
135
|
expect(input).toHaveValue('2:00 PM');
|
|
135
|
-
rerender(
|
|
136
|
+
rerender(_jsx(TimeSelect, {
|
|
136
137
|
renderLabel: "Choose a time",
|
|
137
138
|
locale: "en",
|
|
138
139
|
timezone: "Europe/London" // summer time offset
|
|
@@ -147,15 +148,17 @@ describe('<TimeSelect />', () => {
|
|
|
147
148
|
// 12-hour clock format
|
|
148
149
|
'UTC' // no time offset
|
|
149
150
|
);
|
|
150
|
-
render(
|
|
151
|
+
render(_jsx(ApplyLocale, {
|
|
151
152
|
locale: "fr" // 24-hour clock format
|
|
152
153
|
,
|
|
153
154
|
timezone: "Africa/Nairobi" // UTC + 3
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
,
|
|
156
|
+
children: _jsx(TimeSelect, {
|
|
157
|
+
renderLabel: "Choose a time",
|
|
158
|
+
step: 15,
|
|
159
|
+
value: value.toISOString()
|
|
160
|
+
})
|
|
161
|
+
}));
|
|
159
162
|
const input = screen.getByRole('combobox');
|
|
160
163
|
expect(input).toHaveValue('20:30');
|
|
161
164
|
});
|
|
@@ -163,7 +166,7 @@ describe('<TimeSelect />', () => {
|
|
|
163
166
|
const onChange = vi.fn();
|
|
164
167
|
const onKeyDown = vi.fn();
|
|
165
168
|
const handleInputChange = vi.fn();
|
|
166
|
-
render(
|
|
169
|
+
render(_jsx(TimeSelect, {
|
|
167
170
|
renderLabel: "Choose a time",
|
|
168
171
|
allowNonStepInput: true,
|
|
169
172
|
locale: "en_AU",
|
|
@@ -189,7 +192,7 @@ describe('<TimeSelect />', () => {
|
|
|
189
192
|
// 2:00 PM in US/Eastern
|
|
190
193
|
moment.ISO_8601, 'en', 'US/Eastern');
|
|
191
194
|
const onChange = vi.fn();
|
|
192
|
-
render(
|
|
195
|
+
render(_jsx(TimeSelect, {
|
|
193
196
|
allowClearingSelection: true,
|
|
194
197
|
renderLabel: "Choose a time",
|
|
195
198
|
allowNonStepInput: true,
|
|
@@ -215,7 +218,7 @@ describe('<TimeSelect />', () => {
|
|
|
215
218
|
const onChange = vi.fn();
|
|
216
219
|
const onKeyDown = vi.fn();
|
|
217
220
|
const handleInputChange = vi.fn();
|
|
218
|
-
render(
|
|
221
|
+
render(_jsx(TimeSelect, {
|
|
219
222
|
renderLabel: "Choose a time",
|
|
220
223
|
allowNonStepInput: true,
|
|
221
224
|
locale: "en_AU",
|
|
@@ -243,7 +246,7 @@ describe('<TimeSelect />', () => {
|
|
|
243
246
|
const onChange = vi.fn();
|
|
244
247
|
const onKeyDown = vi.fn();
|
|
245
248
|
const handleInputChange = vi.fn();
|
|
246
|
-
render(
|
|
249
|
+
render(_jsx(TimeSelect, {
|
|
247
250
|
renderLabel: "Choose a time",
|
|
248
251
|
allowNonStepInput: true,
|
|
249
252
|
locale: "en_AU",
|
|
@@ -268,7 +271,7 @@ describe('<TimeSelect />', () => {
|
|
|
268
271
|
});
|
|
269
272
|
describe('input', () => {
|
|
270
273
|
it('should render with a custom id if given', async () => {
|
|
271
|
-
render(_TimeSelect2 || (_TimeSelect2 =
|
|
274
|
+
render(_TimeSelect2 || (_TimeSelect2 = _jsx(TimeSelect, {
|
|
272
275
|
renderLabel: "Choose a time",
|
|
273
276
|
id: "timeSelect"
|
|
274
277
|
})));
|
|
@@ -276,7 +279,7 @@ describe('<TimeSelect />', () => {
|
|
|
276
279
|
expect(input).toHaveAttribute('id', 'timeSelect');
|
|
277
280
|
});
|
|
278
281
|
it('should render readonly when interaction="readonly"', async () => {
|
|
279
|
-
render(_TimeSelect3 || (_TimeSelect3 =
|
|
282
|
+
render(_TimeSelect3 || (_TimeSelect3 = _jsx(TimeSelect, {
|
|
280
283
|
renderLabel: "Choose a time",
|
|
281
284
|
interaction: "readonly"
|
|
282
285
|
})));
|
|
@@ -285,7 +288,7 @@ describe('<TimeSelect />', () => {
|
|
|
285
288
|
expect(input).not.toHaveAttribute('disabled');
|
|
286
289
|
});
|
|
287
290
|
it('should render disabled when interaction="disabled"', async () => {
|
|
288
|
-
render(_TimeSelect4 || (_TimeSelect4 =
|
|
291
|
+
render(_TimeSelect4 || (_TimeSelect4 = _jsx(TimeSelect, {
|
|
289
292
|
renderLabel: "Choose a time",
|
|
290
293
|
interaction: "disabled"
|
|
291
294
|
})));
|
|
@@ -294,7 +297,7 @@ describe('<TimeSelect />', () => {
|
|
|
294
297
|
expect(input).not.toHaveAttribute('readonly');
|
|
295
298
|
});
|
|
296
299
|
it('should render required when isRequired is true', async () => {
|
|
297
|
-
render(_TimeSelect5 || (_TimeSelect5 =
|
|
300
|
+
render(_TimeSelect5 || (_TimeSelect5 = _jsx(TimeSelect, {
|
|
298
301
|
renderLabel: "Choose a time",
|
|
299
302
|
isRequired: true
|
|
300
303
|
})));
|
|
@@ -302,7 +305,7 @@ describe('<TimeSelect />', () => {
|
|
|
302
305
|
expect(input).toHaveAttribute('required');
|
|
303
306
|
});
|
|
304
307
|
it('should allow custom props to pass through', async () => {
|
|
305
|
-
render(_TimeSelect6 || (_TimeSelect6 =
|
|
308
|
+
render(_TimeSelect6 || (_TimeSelect6 = _jsx(TimeSelect, {
|
|
306
309
|
renderLabel: "Choose a time",
|
|
307
310
|
"data-custom-attr": "true"
|
|
308
311
|
})));
|
|
@@ -311,7 +314,7 @@ describe('<TimeSelect />', () => {
|
|
|
311
314
|
});
|
|
312
315
|
it('should provide a ref to the input element', async () => {
|
|
313
316
|
const inputRef = vi.fn();
|
|
314
|
-
render(
|
|
317
|
+
render(_jsx(TimeSelect, {
|
|
315
318
|
renderLabel: "Choose a time",
|
|
316
319
|
inputRef: inputRef
|
|
317
320
|
}));
|
|
@@ -322,7 +325,7 @@ describe('<TimeSelect />', () => {
|
|
|
322
325
|
describe('list', () => {
|
|
323
326
|
it('should provide a ref to the list element', async () => {
|
|
324
327
|
const listRef = vi.fn();
|
|
325
|
-
render(
|
|
328
|
+
render(_jsx(TimeSelect, {
|
|
326
329
|
renderLabel: "Choose a time",
|
|
327
330
|
listRef: listRef
|
|
328
331
|
}));
|
package/es/TimeSelect/index.js
CHANGED
|
@@ -25,12 +25,13 @@ var _dec, _dec2, _class, _TimeSelect;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import
|
|
28
|
+
import { Component } from 'react';
|
|
29
29
|
import { ApplyLocaleContext, Locale, DateTime } from '@instructure/ui-i18n';
|
|
30
30
|
import { getInteraction, passthroughProps, callRenderProp, withDeterministicId } from '@instructure/ui-react-utils';
|
|
31
31
|
import { testable } from '@instructure/ui-testable';
|
|
32
32
|
import { Select } from '@instructure/ui-select';
|
|
33
33
|
import { allowedProps, propTypes } from './props';
|
|
34
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
34
35
|
/**
|
|
35
36
|
---
|
|
36
37
|
category: components
|
|
@@ -419,20 +420,21 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
419
420
|
return filteredOptions.map(option => {
|
|
420
421
|
const id = option.id,
|
|
421
422
|
label = option.label;
|
|
422
|
-
return
|
|
423
|
+
return _jsx(Select.Option, {
|
|
423
424
|
id: id,
|
|
424
|
-
key: id,
|
|
425
425
|
isHighlighted: id === highlightedOptionId,
|
|
426
|
-
isSelected: id === selectedOptionId
|
|
427
|
-
|
|
426
|
+
isSelected: id === selectedOptionId,
|
|
427
|
+
children: label
|
|
428
|
+
}, id);
|
|
428
429
|
});
|
|
429
430
|
}
|
|
430
431
|
renderEmptyOption() {
|
|
431
|
-
return
|
|
432
|
+
return _jsx(Select.Option, {
|
|
432
433
|
id: this._emptyOptionId,
|
|
433
434
|
isHighlighted: false,
|
|
434
|
-
isSelected: false
|
|
435
|
-
|
|
435
|
+
isSelected: false,
|
|
436
|
+
children: callRenderProp(this.props.renderEmptyOption)
|
|
437
|
+
});
|
|
436
438
|
}
|
|
437
439
|
render() {
|
|
438
440
|
const _this$props12 = this.props,
|
|
@@ -465,7 +467,7 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
465
467
|
const _this$state5 = this.state,
|
|
466
468
|
inputValue = _this$state5.inputValue,
|
|
467
469
|
isShowingOptions = _this$state5.isShowingOptions;
|
|
468
|
-
return
|
|
470
|
+
return _jsx(Select, {
|
|
469
471
|
mountNode: mountNode,
|
|
470
472
|
renderLabel: renderLabel,
|
|
471
473
|
inputValue: inputValue,
|
|
@@ -493,8 +495,10 @@ let TimeSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class
|
|
|
493
495
|
onRequestHighlightOption: this.handleHighlightOption,
|
|
494
496
|
onRequestSelectOption: this.handleSelectOption,
|
|
495
497
|
onInputChange: this.handleInputChange,
|
|
496
|
-
onKeyDown: this.onKeyDown
|
|
497
|
-
|
|
498
|
+
onKeyDown: this.onKeyDown,
|
|
499
|
+
...passthroughProps(rest),
|
|
500
|
+
children: isShowingOptions && this.renderOptions()
|
|
501
|
+
});
|
|
498
502
|
}
|
|
499
503
|
}, _TimeSelect.displayName = "TimeSelect", _TimeSelect.componentId = 'TimeSelect', _TimeSelect.allowedProps = allowedProps, _TimeSelect.propTypes = propTypes, _TimeSelect.defaultProps = {
|
|
500
504
|
defaultToFirstOption: false,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _vitest = require("vitest");
|
|
7
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
7
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
@@ -12,6 +11,7 @@ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
|
12
11
|
var _ApplyLocale = require("@instructure/ui-i18n/lib/ApplyLocale");
|
|
13
12
|
var _index = require("../index");
|
|
14
13
|
var _TimeSelect7 = _interopRequireDefault(require("../__examples__/TimeSelect.examples"));
|
|
14
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
15
15
|
var _TimeSelect, _TimeSelect2, _TimeSelect3, _TimeSelect4, _TimeSelect5, _TimeSelect6;
|
|
16
16
|
/*
|
|
17
17
|
* The MIT License (MIT)
|
|
@@ -51,72 +51,72 @@ describe('<TimeSelect />', () => {
|
|
|
51
51
|
});
|
|
52
52
|
it('should fire onFocus when input gains focus', async () => {
|
|
53
53
|
const onFocus = _vitest.vi.fn();
|
|
54
|
-
(0,
|
|
54
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
55
55
|
renderLabel: "Choose a time",
|
|
56
56
|
onFocus: onFocus
|
|
57
57
|
}));
|
|
58
|
-
const input =
|
|
58
|
+
const input = _react.screen.getByRole('combobox');
|
|
59
59
|
input.focus();
|
|
60
|
-
await (0,
|
|
60
|
+
await (0, _react.waitFor)(() => {
|
|
61
61
|
expect(onFocus).toHaveBeenCalled();
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
it('should render a default value', async () => {
|
|
65
65
|
const defaultValue = _momentTimezone.default.tz('1986-05-17T18:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
66
66
|
const onChange = _vitest.vi.fn();
|
|
67
|
-
(0,
|
|
67
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
68
68
|
renderLabel: "Choose a time",
|
|
69
69
|
onChange: onChange,
|
|
70
70
|
timezone: "US/Eastern",
|
|
71
71
|
defaultValue: defaultValue.toISOString()
|
|
72
72
|
}));
|
|
73
|
-
const input =
|
|
73
|
+
const input = _react.screen.getByRole('combobox');
|
|
74
74
|
expect(input).toHaveValue('2:00 PM');
|
|
75
75
|
});
|
|
76
76
|
it('should display value when both defaultValue and value are set', async () => {
|
|
77
77
|
const value = _momentTimezone.default.tz('1986-05-17T18:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
78
78
|
const defaultValue = _momentTimezone.default.tz('1986-05-25T19:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
79
|
-
(0,
|
|
79
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
80
80
|
renderLabel: "Choose a time",
|
|
81
81
|
timezone: "US/Eastern",
|
|
82
82
|
value: value.toISOString(),
|
|
83
83
|
defaultValue: defaultValue.toISOString()
|
|
84
84
|
}));
|
|
85
|
-
const input =
|
|
85
|
+
const input = _react.screen.getByRole('combobox');
|
|
86
86
|
expect(input).toHaveValue(value.format('LT'));
|
|
87
87
|
});
|
|
88
88
|
it('should default to the first option if defaultToFirstOption is true', async () => {
|
|
89
|
-
(0,
|
|
89
|
+
(0, _react.render)(_TimeSelect || (_TimeSelect = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
90
90
|
renderLabel: "Choose a time",
|
|
91
91
|
defaultToFirstOption: true
|
|
92
92
|
})));
|
|
93
|
-
const input =
|
|
93
|
+
const input = _react.screen.getByRole('combobox');
|
|
94
94
|
expect(input).toHaveValue('12:00 AM');
|
|
95
95
|
});
|
|
96
96
|
it('should use the specified timezone', async () => {
|
|
97
97
|
const value = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'fr', 'UTC');
|
|
98
|
-
(0,
|
|
98
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
99
99
|
renderLabel: "Choose a time",
|
|
100
100
|
locale: "fr",
|
|
101
101
|
timezone: "Africa/Nairobi" // UTC + 3
|
|
102
102
|
,
|
|
103
103
|
value: value.toISOString()
|
|
104
104
|
}));
|
|
105
|
-
const input =
|
|
105
|
+
const input = _react.screen.getByRole('combobox');
|
|
106
106
|
expect(input).toHaveValue('16:00');
|
|
107
107
|
});
|
|
108
108
|
it('should use the specified locale', async () => {
|
|
109
109
|
const value = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'fr',
|
|
110
110
|
// 24-hour clock
|
|
111
111
|
'UTC');
|
|
112
|
-
(0,
|
|
112
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
113
113
|
renderLabel: "Choose a time",
|
|
114
114
|
locale: "en" // 12-hour clock
|
|
115
115
|
,
|
|
116
116
|
timezone: "UTC",
|
|
117
117
|
value: value.toISOString()
|
|
118
118
|
}));
|
|
119
|
-
const input =
|
|
119
|
+
const input = _react.screen.getByRole('combobox');
|
|
120
120
|
expect(input).toHaveValue('1:00 PM');
|
|
121
121
|
});
|
|
122
122
|
it('should handle winter and summer time based on timezone', async () => {
|
|
@@ -124,7 +124,7 @@ describe('<TimeSelect />', () => {
|
|
|
124
124
|
);
|
|
125
125
|
const valueWinter = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'UTC' // no time offset
|
|
126
126
|
);
|
|
127
|
-
const _render = (0,
|
|
127
|
+
const _render = (0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
128
128
|
renderLabel: "Choose a time",
|
|
129
129
|
locale: "en",
|
|
130
130
|
timezone: "Europe/London" // summer time offset
|
|
@@ -132,16 +132,16 @@ describe('<TimeSelect />', () => {
|
|
|
132
132
|
value: valueSummer.toISOString()
|
|
133
133
|
})),
|
|
134
134
|
rerender = _render.rerender;
|
|
135
|
-
const input =
|
|
135
|
+
const input = _react.screen.getByRole('combobox');
|
|
136
136
|
expect(input).toHaveValue('2:00 PM');
|
|
137
|
-
rerender(
|
|
137
|
+
rerender((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
138
138
|
renderLabel: "Choose a time",
|
|
139
139
|
locale: "en",
|
|
140
140
|
timezone: "Europe/London" // summer time offset
|
|
141
141
|
,
|
|
142
142
|
value: valueWinter.toISOString()
|
|
143
143
|
}));
|
|
144
|
-
const inputUpdated =
|
|
144
|
+
const inputUpdated = _react.screen.getByRole('combobox');
|
|
145
145
|
expect(inputUpdated).toHaveValue('1:00 PM');
|
|
146
146
|
});
|
|
147
147
|
it('should read locale and timezone from context', async () => {
|
|
@@ -149,23 +149,25 @@ describe('<TimeSelect />', () => {
|
|
|
149
149
|
// 12-hour clock format
|
|
150
150
|
'UTC' // no time offset
|
|
151
151
|
);
|
|
152
|
-
(0,
|
|
152
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_ApplyLocale.ApplyLocale, {
|
|
153
153
|
locale: "fr" // 24-hour clock format
|
|
154
154
|
,
|
|
155
155
|
timezone: "Africa/Nairobi" // UTC + 3
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
,
|
|
157
|
+
children: (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
158
|
+
renderLabel: "Choose a time",
|
|
159
|
+
step: 15,
|
|
160
|
+
value: value.toISOString()
|
|
161
|
+
})
|
|
162
|
+
}));
|
|
163
|
+
const input = _react.screen.getByRole('combobox');
|
|
162
164
|
expect(input).toHaveValue('20:30');
|
|
163
165
|
});
|
|
164
166
|
it('adding event listeners does not break functionality', async () => {
|
|
165
167
|
const onChange = _vitest.vi.fn();
|
|
166
168
|
const onKeyDown = _vitest.vi.fn();
|
|
167
169
|
const handleInputChange = _vitest.vi.fn();
|
|
168
|
-
(0,
|
|
170
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
169
171
|
renderLabel: "Choose a time",
|
|
170
172
|
allowNonStepInput: true,
|
|
171
173
|
locale: "en_AU",
|
|
@@ -174,9 +176,9 @@ describe('<TimeSelect />', () => {
|
|
|
174
176
|
onInputChange: handleInputChange,
|
|
175
177
|
onKeyDown: onKeyDown
|
|
176
178
|
}));
|
|
177
|
-
const input =
|
|
179
|
+
const input = _react.screen.getByRole('combobox');
|
|
178
180
|
await _userEvent.default.type(input, '7:45 PM');
|
|
179
|
-
|
|
181
|
+
_react.fireEvent.blur(input); // sends onChange event
|
|
180
182
|
|
|
181
183
|
expect(onChange).toHaveBeenCalledWith(expect.anything(), {
|
|
182
184
|
inputText: '7:45 PM',
|
|
@@ -191,7 +193,7 @@ describe('<TimeSelect />', () => {
|
|
|
191
193
|
// 2:00 PM in US/Eastern
|
|
192
194
|
_momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
193
195
|
const onChange = _vitest.vi.fn();
|
|
194
|
-
(0,
|
|
196
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
195
197
|
allowClearingSelection: true,
|
|
196
198
|
renderLabel: "Choose a time",
|
|
197
199
|
allowNonStepInput: true,
|
|
@@ -200,9 +202,9 @@ describe('<TimeSelect />', () => {
|
|
|
200
202
|
defaultValue: defaultValue.toISOString(),
|
|
201
203
|
onChange: onChange
|
|
202
204
|
}));
|
|
203
|
-
const input =
|
|
205
|
+
const input = _react.screen.getByRole('combobox');
|
|
204
206
|
await _userEvent.default.type(input, '{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}');
|
|
205
|
-
|
|
207
|
+
_react.fireEvent.blur(input); // sends onChange event
|
|
206
208
|
|
|
207
209
|
expect(onChange).toHaveBeenCalledWith(expect.anything(), {
|
|
208
210
|
inputText: '',
|
|
@@ -217,7 +219,7 @@ describe('<TimeSelect />', () => {
|
|
|
217
219
|
const onChange = _vitest.vi.fn();
|
|
218
220
|
const onKeyDown = _vitest.vi.fn();
|
|
219
221
|
const handleInputChange = _vitest.vi.fn();
|
|
220
|
-
(0,
|
|
222
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
221
223
|
renderLabel: "Choose a time",
|
|
222
224
|
allowNonStepInput: true,
|
|
223
225
|
locale: "en_AU",
|
|
@@ -227,9 +229,9 @@ describe('<TimeSelect />', () => {
|
|
|
227
229
|
onInputChange: handleInputChange,
|
|
228
230
|
onKeyDown: onKeyDown
|
|
229
231
|
}));
|
|
230
|
-
const input =
|
|
232
|
+
const input = _react.screen.getByRole('combobox');
|
|
231
233
|
await _userEvent.default.type(input, '{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}7:45 PM');
|
|
232
|
-
|
|
234
|
+
_react.fireEvent.blur(input); // sends onChange event
|
|
233
235
|
expect(onChange).toHaveBeenCalledWith(expect.anything(), {
|
|
234
236
|
inputText: '7:45 PM',
|
|
235
237
|
value: '1986-05-17T23:45:00.000Z'
|
|
@@ -245,7 +247,7 @@ describe('<TimeSelect />', () => {
|
|
|
245
247
|
const onChange = _vitest.vi.fn();
|
|
246
248
|
const onKeyDown = _vitest.vi.fn();
|
|
247
249
|
const handleInputChange = _vitest.vi.fn();
|
|
248
|
-
(0,
|
|
250
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
249
251
|
renderLabel: "Choose a time",
|
|
250
252
|
allowNonStepInput: true,
|
|
251
253
|
locale: "en_AU",
|
|
@@ -255,11 +257,11 @@ describe('<TimeSelect />', () => {
|
|
|
255
257
|
onInputChange: handleInputChange,
|
|
256
258
|
onKeyDown: onKeyDown
|
|
257
259
|
}));
|
|
258
|
-
const input =
|
|
260
|
+
const input = _react.screen.getByRole('combobox');
|
|
259
261
|
await _userEvent.default.type(input, '{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}7:45 PM');
|
|
260
|
-
|
|
262
|
+
_react.fireEvent.blur(input); // sends onChange event
|
|
261
263
|
await _userEvent.default.type(input, 'asdf');
|
|
262
|
-
|
|
264
|
+
_react.fireEvent.blur(input);
|
|
263
265
|
expect(onChange).toHaveBeenCalledWith(expect.anything(), {
|
|
264
266
|
inputText: '7:45 PM',
|
|
265
267
|
value: '1986-05-17T23:45:00.000Z'
|
|
@@ -270,68 +272,68 @@ describe('<TimeSelect />', () => {
|
|
|
270
272
|
});
|
|
271
273
|
describe('input', () => {
|
|
272
274
|
it('should render with a custom id if given', async () => {
|
|
273
|
-
(0,
|
|
275
|
+
(0, _react.render)(_TimeSelect2 || (_TimeSelect2 = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
274
276
|
renderLabel: "Choose a time",
|
|
275
277
|
id: "timeSelect"
|
|
276
278
|
})));
|
|
277
|
-
const input =
|
|
279
|
+
const input = _react.screen.getByRole('combobox');
|
|
278
280
|
expect(input).toHaveAttribute('id', 'timeSelect');
|
|
279
281
|
});
|
|
280
282
|
it('should render readonly when interaction="readonly"', async () => {
|
|
281
|
-
(0,
|
|
283
|
+
(0, _react.render)(_TimeSelect3 || (_TimeSelect3 = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
282
284
|
renderLabel: "Choose a time",
|
|
283
285
|
interaction: "readonly"
|
|
284
286
|
})));
|
|
285
|
-
const input =
|
|
287
|
+
const input = _react.screen.getByRole('combobox');
|
|
286
288
|
expect(input).toHaveAttribute('readonly');
|
|
287
289
|
expect(input).not.toHaveAttribute('disabled');
|
|
288
290
|
});
|
|
289
291
|
it('should render disabled when interaction="disabled"', async () => {
|
|
290
|
-
(0,
|
|
292
|
+
(0, _react.render)(_TimeSelect4 || (_TimeSelect4 = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
291
293
|
renderLabel: "Choose a time",
|
|
292
294
|
interaction: "disabled"
|
|
293
295
|
})));
|
|
294
|
-
const input =
|
|
296
|
+
const input = _react.screen.getByRole('combobox');
|
|
295
297
|
expect(input).toHaveAttribute('disabled');
|
|
296
298
|
expect(input).not.toHaveAttribute('readonly');
|
|
297
299
|
});
|
|
298
300
|
it('should render required when isRequired is true', async () => {
|
|
299
|
-
(0,
|
|
301
|
+
(0, _react.render)(_TimeSelect5 || (_TimeSelect5 = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
300
302
|
renderLabel: "Choose a time",
|
|
301
303
|
isRequired: true
|
|
302
304
|
})));
|
|
303
|
-
const input =
|
|
305
|
+
const input = _react.screen.getByRole('combobox');
|
|
304
306
|
expect(input).toHaveAttribute('required');
|
|
305
307
|
});
|
|
306
308
|
it('should allow custom props to pass through', async () => {
|
|
307
|
-
(0,
|
|
309
|
+
(0, _react.render)(_TimeSelect6 || (_TimeSelect6 = (0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
308
310
|
renderLabel: "Choose a time",
|
|
309
311
|
"data-custom-attr": "true"
|
|
310
312
|
})));
|
|
311
|
-
const input =
|
|
313
|
+
const input = _react.screen.getByRole('combobox');
|
|
312
314
|
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
|
313
315
|
});
|
|
314
316
|
it('should provide a ref to the input element', async () => {
|
|
315
317
|
const inputRef = _vitest.vi.fn();
|
|
316
|
-
(0,
|
|
318
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
317
319
|
renderLabel: "Choose a time",
|
|
318
320
|
inputRef: inputRef
|
|
319
321
|
}));
|
|
320
|
-
const input =
|
|
322
|
+
const input = _react.screen.getByRole('combobox');
|
|
321
323
|
expect(inputRef).toHaveBeenCalledWith(input);
|
|
322
324
|
});
|
|
323
325
|
});
|
|
324
326
|
describe('list', () => {
|
|
325
327
|
it('should provide a ref to the list element', async () => {
|
|
326
328
|
const listRef = _vitest.vi.fn();
|
|
327
|
-
(0,
|
|
329
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.TimeSelect, {
|
|
328
330
|
renderLabel: "Choose a time",
|
|
329
331
|
listRef: listRef
|
|
330
332
|
}));
|
|
331
|
-
const input =
|
|
333
|
+
const input = _react.screen.getByRole('combobox');
|
|
332
334
|
await _userEvent.default.click(input);
|
|
333
|
-
await (0,
|
|
334
|
-
const listbox =
|
|
335
|
+
await (0, _react.waitFor)(() => {
|
|
336
|
+
const listbox = _react.screen.getByRole('listbox');
|
|
335
337
|
expect(listRef).toHaveBeenCalledWith(listbox);
|
|
336
338
|
});
|
|
337
339
|
});
|
|
@@ -341,7 +343,7 @@ describe('<TimeSelect />', () => {
|
|
|
341
343
|
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
342
344
|
content
|
|
343
345
|
}) => {
|
|
344
|
-
const _render2 = (0,
|
|
346
|
+
const _render2 = (0, _react.render)(content),
|
|
345
347
|
container = _render2.container;
|
|
346
348
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
347
349
|
expect(axeCheck).toBe(true);
|