@instructure/ui-time-select 10.2.2-snapshot-14 → 10.2.2-snapshot-16
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 +265 -0
- package/lib/TimeSelect/__new-tests__/TimeSelect.test.js +267 -0
- package/package.json +18 -14
- package/src/TimeSelect/__new-tests__/TimeSelect.test.tsx +341 -0
- package/tsconfig.build.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TimeSelect/__new-tests__/TimeSelect.test.d.ts +2 -0
- package/types/TimeSelect/__new-tests__/TimeSelect.test.d.ts.map +1 -0
- package/es/TimeSelect/TimeSelectLocator.js +0 -38
- package/lib/TimeSelect/TimeSelectLocator.js +0 -44
- package/src/TimeSelect/TimeSelectLocator.ts +0 -39
- package/types/TimeSelect/TimeSelectLocator.d.ts +0 -443
- package/types/TimeSelect/TimeSelectLocator.d.ts.map +0 -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.2.2-snapshot-
|
|
6
|
+
## [10.2.2-snapshot-16](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-snapshot-16) (2024-09-13)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-time-select
|
|
9
9
|
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
var _TimeSelect, _TimeSelect2, _TimeSelect3, _TimeSelect4, _TimeSelect5, _TimeSelect6;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
27
|
+
import { vi } from 'vitest';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import moment from 'moment-timezone';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line no-restricted-imports
|
|
33
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
34
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
35
|
+
import { ApplyLocale } from '@instructure/ui-i18n';
|
|
36
|
+
import { TimeSelect } from '../index';
|
|
37
|
+
import TimeSelectExamples from '../__examples__/TimeSelect.examples';
|
|
38
|
+
describe('<TimeSelect />', () => {
|
|
39
|
+
let consoleWarningMock;
|
|
40
|
+
let consoleErrorMock;
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
// Mocking console to prevent test output pollution
|
|
43
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
44
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
45
|
+
});
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
consoleWarningMock.mockRestore();
|
|
48
|
+
consoleErrorMock.mockRestore();
|
|
49
|
+
});
|
|
50
|
+
it('should fire onFocus when input gains focus', async () => {
|
|
51
|
+
const onFocus = vi.fn();
|
|
52
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
53
|
+
renderLabel: "Choose a time",
|
|
54
|
+
onFocus: onFocus
|
|
55
|
+
}));
|
|
56
|
+
const input = screen.getByRole('combobox');
|
|
57
|
+
input.focus();
|
|
58
|
+
await waitFor(() => {
|
|
59
|
+
expect(onFocus).toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should render a default value', async () => {
|
|
63
|
+
const defaultValue = moment.tz('1986-05-17T18:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
64
|
+
const onChange = vi.fn();
|
|
65
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
66
|
+
renderLabel: "Choose a time",
|
|
67
|
+
onChange: onChange,
|
|
68
|
+
timezone: "US/Eastern",
|
|
69
|
+
defaultValue: defaultValue.toISOString()
|
|
70
|
+
}));
|
|
71
|
+
const input = screen.getByRole('combobox');
|
|
72
|
+
expect(input).toHaveValue('2:00 PM');
|
|
73
|
+
});
|
|
74
|
+
it('should display value when both defaultValue and value are set', async () => {
|
|
75
|
+
const value = moment.tz('1986-05-17T18:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
76
|
+
const defaultValue = moment.tz('1986-05-25T19:00:00.000Z', moment.ISO_8601, 'en', 'US/Eastern');
|
|
77
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
78
|
+
renderLabel: "Choose a time",
|
|
79
|
+
timezone: "US/Eastern",
|
|
80
|
+
value: value.toISOString(),
|
|
81
|
+
defaultValue: defaultValue.toISOString()
|
|
82
|
+
}));
|
|
83
|
+
const input = screen.getByRole('combobox');
|
|
84
|
+
expect(input).toHaveValue(value.format('LT'));
|
|
85
|
+
});
|
|
86
|
+
it('should default to the first option if defaultToFirstOption is true', async () => {
|
|
87
|
+
render(_TimeSelect || (_TimeSelect = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
88
|
+
renderLabel: "Choose a time",
|
|
89
|
+
defaultToFirstOption: true
|
|
90
|
+
})));
|
|
91
|
+
const input = screen.getByRole('combobox');
|
|
92
|
+
expect(input).toHaveValue('12:00 AM');
|
|
93
|
+
});
|
|
94
|
+
it('should use the specified timezone', async () => {
|
|
95
|
+
const value = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'fr', 'UTC');
|
|
96
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
97
|
+
renderLabel: "Choose a time",
|
|
98
|
+
locale: "fr",
|
|
99
|
+
timezone: "Africa/Nairobi" // UTC + 3
|
|
100
|
+
,
|
|
101
|
+
value: value.toISOString()
|
|
102
|
+
}));
|
|
103
|
+
const input = screen.getByRole('combobox');
|
|
104
|
+
expect(input).toHaveValue('16:00');
|
|
105
|
+
});
|
|
106
|
+
it('should use the specified locale', async () => {
|
|
107
|
+
const value = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'fr',
|
|
108
|
+
// 24-hour clock
|
|
109
|
+
'UTC');
|
|
110
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
111
|
+
renderLabel: "Choose a time",
|
|
112
|
+
locale: "en" // 12-hour clock
|
|
113
|
+
,
|
|
114
|
+
timezone: "UTC",
|
|
115
|
+
value: value.toISOString()
|
|
116
|
+
}));
|
|
117
|
+
const input = screen.getByRole('combobox');
|
|
118
|
+
expect(input).toHaveValue('1:00 PM');
|
|
119
|
+
});
|
|
120
|
+
it('should handle winter and summer time based on timezone', async () => {
|
|
121
|
+
const valueSummer = moment.tz('2024-07-11T13:00:00.000Z', moment.ISO_8601, 'en', 'UTC' // no time offset
|
|
122
|
+
);
|
|
123
|
+
const valueWinter = moment.tz('2024-01-11T13:00:00.000Z', moment.ISO_8601, 'en', 'UTC' // no time offset
|
|
124
|
+
);
|
|
125
|
+
const _render = render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
126
|
+
renderLabel: "Choose a time",
|
|
127
|
+
locale: "en",
|
|
128
|
+
timezone: "Europe/London" // summer time offset
|
|
129
|
+
,
|
|
130
|
+
value: valueSummer.toISOString()
|
|
131
|
+
})),
|
|
132
|
+
rerender = _render.rerender;
|
|
133
|
+
const input = screen.getByRole('combobox');
|
|
134
|
+
expect(input).toHaveValue('2:00 PM');
|
|
135
|
+
rerender( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
136
|
+
renderLabel: "Choose a time",
|
|
137
|
+
locale: "en",
|
|
138
|
+
timezone: "Europe/London" // summer time offset
|
|
139
|
+
,
|
|
140
|
+
value: valueWinter.toISOString()
|
|
141
|
+
}));
|
|
142
|
+
const inputUpdated = screen.getByRole('combobox');
|
|
143
|
+
expect(inputUpdated).toHaveValue('1:00 PM');
|
|
144
|
+
});
|
|
145
|
+
it('should read locale and timezone from context', async () => {
|
|
146
|
+
const value = moment.tz('2017-05-01T17:30Z', moment.ISO_8601, 'en',
|
|
147
|
+
// 12-hour clock format
|
|
148
|
+
'UTC' // no time offset
|
|
149
|
+
);
|
|
150
|
+
render( /*#__PURE__*/React.createElement(ApplyLocale, {
|
|
151
|
+
locale: "fr" // 24-hour clock format
|
|
152
|
+
,
|
|
153
|
+
timezone: "Africa/Nairobi" // UTC + 3
|
|
154
|
+
}, /*#__PURE__*/React.createElement(TimeSelect, {
|
|
155
|
+
renderLabel: "Choose a time",
|
|
156
|
+
step: 15,
|
|
157
|
+
value: value.toISOString()
|
|
158
|
+
})));
|
|
159
|
+
const input = screen.getByRole('combobox');
|
|
160
|
+
expect(input).toHaveValue('20:30');
|
|
161
|
+
});
|
|
162
|
+
it('adding event listeners does not break functionality', async () => {
|
|
163
|
+
const onChange = vi.fn();
|
|
164
|
+
const onKeyDown = vi.fn();
|
|
165
|
+
const handleInputChange = vi.fn();
|
|
166
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
167
|
+
renderLabel: "Choose a time",
|
|
168
|
+
allowNonStepInput: true,
|
|
169
|
+
locale: "en_AU",
|
|
170
|
+
timezone: "US/Eastern",
|
|
171
|
+
onChange: onChange,
|
|
172
|
+
onInputChange: handleInputChange,
|
|
173
|
+
onKeyDown: onKeyDown
|
|
174
|
+
}));
|
|
175
|
+
const input = screen.getByRole('combobox');
|
|
176
|
+
await userEvent.type(input, '7:45 PM');
|
|
177
|
+
fireEvent.blur(input); // sends onChange event
|
|
178
|
+
|
|
179
|
+
await waitFor(() => {
|
|
180
|
+
expect(onChange).toHaveBeenCalled();
|
|
181
|
+
expect(onKeyDown).toHaveBeenCalled();
|
|
182
|
+
expect(handleInputChange).toHaveBeenCalled();
|
|
183
|
+
expect(input).toHaveValue('7:45 PM');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe('input', () => {
|
|
187
|
+
it('should render with a custom id if given', async () => {
|
|
188
|
+
render(_TimeSelect2 || (_TimeSelect2 = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
189
|
+
renderLabel: "Choose a time",
|
|
190
|
+
id: "timeSelect"
|
|
191
|
+
})));
|
|
192
|
+
const input = screen.getByRole('combobox');
|
|
193
|
+
expect(input).toHaveAttribute('id', 'timeSelect');
|
|
194
|
+
});
|
|
195
|
+
it('should render readonly when interaction="readonly"', async () => {
|
|
196
|
+
render(_TimeSelect3 || (_TimeSelect3 = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
197
|
+
renderLabel: "Choose a time",
|
|
198
|
+
interaction: "readonly"
|
|
199
|
+
})));
|
|
200
|
+
const input = screen.getByRole('combobox');
|
|
201
|
+
expect(input).toHaveAttribute('readonly');
|
|
202
|
+
expect(input).not.toHaveAttribute('disabled');
|
|
203
|
+
});
|
|
204
|
+
it('should render disabled when interaction="disabled"', async () => {
|
|
205
|
+
render(_TimeSelect4 || (_TimeSelect4 = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
206
|
+
renderLabel: "Choose a time",
|
|
207
|
+
interaction: "disabled"
|
|
208
|
+
})));
|
|
209
|
+
const input = screen.getByRole('combobox');
|
|
210
|
+
expect(input).toHaveAttribute('disabled');
|
|
211
|
+
expect(input).not.toHaveAttribute('readonly');
|
|
212
|
+
});
|
|
213
|
+
it('should render required when isRequired is true', async () => {
|
|
214
|
+
render(_TimeSelect5 || (_TimeSelect5 = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
215
|
+
renderLabel: "Choose a time",
|
|
216
|
+
isRequired: true
|
|
217
|
+
})));
|
|
218
|
+
const input = screen.getByRole('combobox');
|
|
219
|
+
expect(input).toHaveAttribute('required');
|
|
220
|
+
});
|
|
221
|
+
it('should allow custom props to pass through', async () => {
|
|
222
|
+
render(_TimeSelect6 || (_TimeSelect6 = /*#__PURE__*/React.createElement(TimeSelect, {
|
|
223
|
+
renderLabel: "Choose a time",
|
|
224
|
+
"data-custom-attr": "true"
|
|
225
|
+
})));
|
|
226
|
+
const input = screen.getByRole('combobox');
|
|
227
|
+
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
|
228
|
+
});
|
|
229
|
+
it('should provide a ref to the input element', async () => {
|
|
230
|
+
const inputRef = vi.fn();
|
|
231
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
232
|
+
renderLabel: "Choose a time",
|
|
233
|
+
inputRef: inputRef
|
|
234
|
+
}));
|
|
235
|
+
const input = screen.getByRole('combobox');
|
|
236
|
+
expect(inputRef).toHaveBeenCalledWith(input);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
describe('list', () => {
|
|
240
|
+
it('should provide a ref to the list element', async () => {
|
|
241
|
+
const listRef = vi.fn();
|
|
242
|
+
render( /*#__PURE__*/React.createElement(TimeSelect, {
|
|
243
|
+
renderLabel: "Choose a time",
|
|
244
|
+
listRef: listRef
|
|
245
|
+
}));
|
|
246
|
+
const input = screen.getByRole('combobox');
|
|
247
|
+
await userEvent.click(input);
|
|
248
|
+
await waitFor(() => {
|
|
249
|
+
const listbox = screen.getByRole('listbox');
|
|
250
|
+
expect(listRef).toHaveBeenCalledWith(listbox);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
describe('with generated examples', () => {
|
|
255
|
+
const generatedComponents = generateA11yTests(TimeSelect, TimeSelectExamples);
|
|
256
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
257
|
+
content
|
|
258
|
+
}) => {
|
|
259
|
+
const _render2 = render(content),
|
|
260
|
+
container = _render2.container;
|
|
261
|
+
const axeCheck = await runAxeCheck(container);
|
|
262
|
+
expect(axeCheck).toBe(true);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _vitest = require("vitest");
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
9
|
+
require("@testing-library/jest-dom");
|
|
10
|
+
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
11
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
12
|
+
var _ApplyLocale = require("@instructure/ui-i18n/lib/ApplyLocale");
|
|
13
|
+
var _index = require("../index");
|
|
14
|
+
var _TimeSelect7 = _interopRequireDefault(require("../__examples__/TimeSelect.examples"));
|
|
15
|
+
var _TimeSelect, _TimeSelect2, _TimeSelect3, _TimeSelect4, _TimeSelect5, _TimeSelect6;
|
|
16
|
+
/*
|
|
17
|
+
* The MIT License (MIT)
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
* in the Software without restriction, including without limitation the rights
|
|
24
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
* furnished to do so, subject to the following conditions:
|
|
27
|
+
*
|
|
28
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
* copies or substantial portions of the Software.
|
|
30
|
+
*
|
|
31
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
* SOFTWARE.
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line no-restricted-imports
|
|
40
|
+
describe('<TimeSelect />', () => {
|
|
41
|
+
let consoleWarningMock;
|
|
42
|
+
let consoleErrorMock;
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
// Mocking console to prevent test output pollution
|
|
45
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
46
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
47
|
+
});
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
consoleWarningMock.mockRestore();
|
|
50
|
+
consoleErrorMock.mockRestore();
|
|
51
|
+
});
|
|
52
|
+
it('should fire onFocus when input gains focus', async () => {
|
|
53
|
+
const onFocus = _vitest.vi.fn();
|
|
54
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
55
|
+
renderLabel: "Choose a time",
|
|
56
|
+
onFocus: onFocus
|
|
57
|
+
}));
|
|
58
|
+
const input = _react2.screen.getByRole('combobox');
|
|
59
|
+
input.focus();
|
|
60
|
+
await (0, _react2.waitFor)(() => {
|
|
61
|
+
expect(onFocus).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('should render a default value', async () => {
|
|
65
|
+
const defaultValue = _momentTimezone.default.tz('1986-05-17T18:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
66
|
+
const onChange = _vitest.vi.fn();
|
|
67
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
68
|
+
renderLabel: "Choose a time",
|
|
69
|
+
onChange: onChange,
|
|
70
|
+
timezone: "US/Eastern",
|
|
71
|
+
defaultValue: defaultValue.toISOString()
|
|
72
|
+
}));
|
|
73
|
+
const input = _react2.screen.getByRole('combobox');
|
|
74
|
+
expect(input).toHaveValue('2:00 PM');
|
|
75
|
+
});
|
|
76
|
+
it('should display value when both defaultValue and value are set', async () => {
|
|
77
|
+
const value = _momentTimezone.default.tz('1986-05-17T18:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
78
|
+
const defaultValue = _momentTimezone.default.tz('1986-05-25T19:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'US/Eastern');
|
|
79
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
80
|
+
renderLabel: "Choose a time",
|
|
81
|
+
timezone: "US/Eastern",
|
|
82
|
+
value: value.toISOString(),
|
|
83
|
+
defaultValue: defaultValue.toISOString()
|
|
84
|
+
}));
|
|
85
|
+
const input = _react2.screen.getByRole('combobox');
|
|
86
|
+
expect(input).toHaveValue(value.format('LT'));
|
|
87
|
+
});
|
|
88
|
+
it('should default to the first option if defaultToFirstOption is true', async () => {
|
|
89
|
+
(0, _react2.render)(_TimeSelect || (_TimeSelect = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
90
|
+
renderLabel: "Choose a time",
|
|
91
|
+
defaultToFirstOption: true
|
|
92
|
+
})));
|
|
93
|
+
const input = _react2.screen.getByRole('combobox');
|
|
94
|
+
expect(input).toHaveValue('12:00 AM');
|
|
95
|
+
});
|
|
96
|
+
it('should use the specified timezone', async () => {
|
|
97
|
+
const value = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'fr', 'UTC');
|
|
98
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
99
|
+
renderLabel: "Choose a time",
|
|
100
|
+
locale: "fr",
|
|
101
|
+
timezone: "Africa/Nairobi" // UTC + 3
|
|
102
|
+
,
|
|
103
|
+
value: value.toISOString()
|
|
104
|
+
}));
|
|
105
|
+
const input = _react2.screen.getByRole('combobox');
|
|
106
|
+
expect(input).toHaveValue('16:00');
|
|
107
|
+
});
|
|
108
|
+
it('should use the specified locale', async () => {
|
|
109
|
+
const value = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'fr',
|
|
110
|
+
// 24-hour clock
|
|
111
|
+
'UTC');
|
|
112
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
113
|
+
renderLabel: "Choose a time",
|
|
114
|
+
locale: "en" // 12-hour clock
|
|
115
|
+
,
|
|
116
|
+
timezone: "UTC",
|
|
117
|
+
value: value.toISOString()
|
|
118
|
+
}));
|
|
119
|
+
const input = _react2.screen.getByRole('combobox');
|
|
120
|
+
expect(input).toHaveValue('1:00 PM');
|
|
121
|
+
});
|
|
122
|
+
it('should handle winter and summer time based on timezone', async () => {
|
|
123
|
+
const valueSummer = _momentTimezone.default.tz('2024-07-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'UTC' // no time offset
|
|
124
|
+
);
|
|
125
|
+
const valueWinter = _momentTimezone.default.tz('2024-01-11T13:00:00.000Z', _momentTimezone.default.ISO_8601, 'en', 'UTC' // no time offset
|
|
126
|
+
);
|
|
127
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
128
|
+
renderLabel: "Choose a time",
|
|
129
|
+
locale: "en",
|
|
130
|
+
timezone: "Europe/London" // summer time offset
|
|
131
|
+
,
|
|
132
|
+
value: valueSummer.toISOString()
|
|
133
|
+
})),
|
|
134
|
+
rerender = _render.rerender;
|
|
135
|
+
const input = _react2.screen.getByRole('combobox');
|
|
136
|
+
expect(input).toHaveValue('2:00 PM');
|
|
137
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
138
|
+
renderLabel: "Choose a time",
|
|
139
|
+
locale: "en",
|
|
140
|
+
timezone: "Europe/London" // summer time offset
|
|
141
|
+
,
|
|
142
|
+
value: valueWinter.toISOString()
|
|
143
|
+
}));
|
|
144
|
+
const inputUpdated = _react2.screen.getByRole('combobox');
|
|
145
|
+
expect(inputUpdated).toHaveValue('1:00 PM');
|
|
146
|
+
});
|
|
147
|
+
it('should read locale and timezone from context', async () => {
|
|
148
|
+
const value = _momentTimezone.default.tz('2017-05-01T17:30Z', _momentTimezone.default.ISO_8601, 'en',
|
|
149
|
+
// 12-hour clock format
|
|
150
|
+
'UTC' // no time offset
|
|
151
|
+
);
|
|
152
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_ApplyLocale.ApplyLocale, {
|
|
153
|
+
locale: "fr" // 24-hour clock format
|
|
154
|
+
,
|
|
155
|
+
timezone: "Africa/Nairobi" // UTC + 3
|
|
156
|
+
}, /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
157
|
+
renderLabel: "Choose a time",
|
|
158
|
+
step: 15,
|
|
159
|
+
value: value.toISOString()
|
|
160
|
+
})));
|
|
161
|
+
const input = _react2.screen.getByRole('combobox');
|
|
162
|
+
expect(input).toHaveValue('20:30');
|
|
163
|
+
});
|
|
164
|
+
it('adding event listeners does not break functionality', async () => {
|
|
165
|
+
const onChange = _vitest.vi.fn();
|
|
166
|
+
const onKeyDown = _vitest.vi.fn();
|
|
167
|
+
const handleInputChange = _vitest.vi.fn();
|
|
168
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
169
|
+
renderLabel: "Choose a time",
|
|
170
|
+
allowNonStepInput: true,
|
|
171
|
+
locale: "en_AU",
|
|
172
|
+
timezone: "US/Eastern",
|
|
173
|
+
onChange: onChange,
|
|
174
|
+
onInputChange: handleInputChange,
|
|
175
|
+
onKeyDown: onKeyDown
|
|
176
|
+
}));
|
|
177
|
+
const input = _react2.screen.getByRole('combobox');
|
|
178
|
+
await _userEvent.default.type(input, '7:45 PM');
|
|
179
|
+
_react2.fireEvent.blur(input); // sends onChange event
|
|
180
|
+
|
|
181
|
+
await (0, _react2.waitFor)(() => {
|
|
182
|
+
expect(onChange).toHaveBeenCalled();
|
|
183
|
+
expect(onKeyDown).toHaveBeenCalled();
|
|
184
|
+
expect(handleInputChange).toHaveBeenCalled();
|
|
185
|
+
expect(input).toHaveValue('7:45 PM');
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe('input', () => {
|
|
189
|
+
it('should render with a custom id if given', async () => {
|
|
190
|
+
(0, _react2.render)(_TimeSelect2 || (_TimeSelect2 = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
191
|
+
renderLabel: "Choose a time",
|
|
192
|
+
id: "timeSelect"
|
|
193
|
+
})));
|
|
194
|
+
const input = _react2.screen.getByRole('combobox');
|
|
195
|
+
expect(input).toHaveAttribute('id', 'timeSelect');
|
|
196
|
+
});
|
|
197
|
+
it('should render readonly when interaction="readonly"', async () => {
|
|
198
|
+
(0, _react2.render)(_TimeSelect3 || (_TimeSelect3 = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
199
|
+
renderLabel: "Choose a time",
|
|
200
|
+
interaction: "readonly"
|
|
201
|
+
})));
|
|
202
|
+
const input = _react2.screen.getByRole('combobox');
|
|
203
|
+
expect(input).toHaveAttribute('readonly');
|
|
204
|
+
expect(input).not.toHaveAttribute('disabled');
|
|
205
|
+
});
|
|
206
|
+
it('should render disabled when interaction="disabled"', async () => {
|
|
207
|
+
(0, _react2.render)(_TimeSelect4 || (_TimeSelect4 = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
208
|
+
renderLabel: "Choose a time",
|
|
209
|
+
interaction: "disabled"
|
|
210
|
+
})));
|
|
211
|
+
const input = _react2.screen.getByRole('combobox');
|
|
212
|
+
expect(input).toHaveAttribute('disabled');
|
|
213
|
+
expect(input).not.toHaveAttribute('readonly');
|
|
214
|
+
});
|
|
215
|
+
it('should render required when isRequired is true', async () => {
|
|
216
|
+
(0, _react2.render)(_TimeSelect5 || (_TimeSelect5 = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
217
|
+
renderLabel: "Choose a time",
|
|
218
|
+
isRequired: true
|
|
219
|
+
})));
|
|
220
|
+
const input = _react2.screen.getByRole('combobox');
|
|
221
|
+
expect(input).toHaveAttribute('required');
|
|
222
|
+
});
|
|
223
|
+
it('should allow custom props to pass through', async () => {
|
|
224
|
+
(0, _react2.render)(_TimeSelect6 || (_TimeSelect6 = /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
225
|
+
renderLabel: "Choose a time",
|
|
226
|
+
"data-custom-attr": "true"
|
|
227
|
+
})));
|
|
228
|
+
const input = _react2.screen.getByRole('combobox');
|
|
229
|
+
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
|
230
|
+
});
|
|
231
|
+
it('should provide a ref to the input element', async () => {
|
|
232
|
+
const inputRef = _vitest.vi.fn();
|
|
233
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
234
|
+
renderLabel: "Choose a time",
|
|
235
|
+
inputRef: inputRef
|
|
236
|
+
}));
|
|
237
|
+
const input = _react2.screen.getByRole('combobox');
|
|
238
|
+
expect(inputRef).toHaveBeenCalledWith(input);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('list', () => {
|
|
242
|
+
it('should provide a ref to the list element', async () => {
|
|
243
|
+
const listRef = _vitest.vi.fn();
|
|
244
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.TimeSelect, {
|
|
245
|
+
renderLabel: "Choose a time",
|
|
246
|
+
listRef: listRef
|
|
247
|
+
}));
|
|
248
|
+
const input = _react2.screen.getByRole('combobox');
|
|
249
|
+
await _userEvent.default.click(input);
|
|
250
|
+
await (0, _react2.waitFor)(() => {
|
|
251
|
+
const listbox = _react2.screen.getByRole('listbox');
|
|
252
|
+
expect(listRef).toHaveBeenCalledWith(listbox);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
describe('with generated examples', () => {
|
|
257
|
+
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.TimeSelect, _TimeSelect7.default);
|
|
258
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
259
|
+
content
|
|
260
|
+
}) => {
|
|
261
|
+
const _render2 = (0, _react2.render)(content),
|
|
262
|
+
container = _render2.container;
|
|
263
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
264
|
+
expect(axeCheck).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-time-select",
|
|
3
|
-
"version": "10.2.2-snapshot-
|
|
3
|
+
"version": "10.2.2-snapshot-16",
|
|
4
4
|
"description": "A component for selecting time values.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,22 +24,26 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.24.5",
|
|
27
|
-
"@instructure/shared-types": "10.2.2-snapshot-
|
|
28
|
-
"@instructure/ui-form-field": "10.2.2-snapshot-
|
|
29
|
-
"@instructure/ui-i18n": "10.2.2-snapshot-
|
|
30
|
-
"@instructure/ui-position": "10.2.2-snapshot-
|
|
31
|
-
"@instructure/ui-prop-types": "10.2.2-snapshot-
|
|
32
|
-
"@instructure/ui-react-utils": "10.2.2-snapshot-
|
|
33
|
-
"@instructure/ui-select": "10.2.2-snapshot-
|
|
34
|
-
"@instructure/ui-
|
|
35
|
-
"@instructure/ui-
|
|
36
|
-
"@instructure/ui-utils": "10.2.2-snapshot-14",
|
|
27
|
+
"@instructure/shared-types": "10.2.2-snapshot-16",
|
|
28
|
+
"@instructure/ui-form-field": "10.2.2-snapshot-16",
|
|
29
|
+
"@instructure/ui-i18n": "10.2.2-snapshot-16",
|
|
30
|
+
"@instructure/ui-position": "10.2.2-snapshot-16",
|
|
31
|
+
"@instructure/ui-prop-types": "10.2.2-snapshot-16",
|
|
32
|
+
"@instructure/ui-react-utils": "10.2.2-snapshot-16",
|
|
33
|
+
"@instructure/ui-select": "10.2.2-snapshot-16",
|
|
34
|
+
"@instructure/ui-testable": "10.2.2-snapshot-16",
|
|
35
|
+
"@instructure/ui-utils": "10.2.2-snapshot-16",
|
|
37
36
|
"prop-types": "^15.8.1"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/ui-
|
|
42
|
-
"
|
|
39
|
+
"@instructure/ui-axe-check": "10.2.2-snapshot-16",
|
|
40
|
+
"@instructure/ui-babel-preset": "10.2.2-snapshot-16",
|
|
41
|
+
"@instructure/ui-test-utils": "10.2.2-snapshot-16",
|
|
42
|
+
"@testing-library/jest-dom": "^6.4.6",
|
|
43
|
+
"@testing-library/react": "^15.0.7",
|
|
44
|
+
"@testing-library/user-event": "^14.5.2",
|
|
45
|
+
"moment-timezone": "^0.5.45",
|
|
46
|
+
"vitest": "^2.0.2"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
49
|
"react": ">=16.8 <=18"
|