@instructure/ui-date-input 8.55.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 +8 -0
- package/es/DateInput/__new-tests__/DateInput.test.js +563 -60
- package/lib/DateInput/__new-tests__/DateInput.test.js +564 -61
- package/package.json +20 -18
- package/src/DateInput/__new-tests__/DateInput.test.tsx +817 -60
- package/tsconfig.build.json +6 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/DateInput/DateInputLocator.js +0 -42
- package/es/DateInput/locator.js +0 -26
- package/lib/DateInput/DateInputLocator.js +0 -49
- package/lib/DateInput/locator.js +0 -37
- package/src/DateInput/DateInputLocator.ts +0 -43
- package/src/DateInput/locator.ts +0 -27
- package/types/DateInput/DateInputLocator.d.ts +0 -1271
- package/types/DateInput/DateInputLocator.d.ts.map +0 -1
- package/types/DateInput/locator.d.ts +0 -4
- package/types/DateInput/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [8.55.1-snapshot-3](https://github.com/instructure/instructure-ui/compare/v8.55.0...v8.55.1-snapshot-3) (2024-04-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-date-input
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [8.55.0](https://github.com/instructure/instructure-ui/compare/v8.54.0...v8.55.0) (2024-04-09)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-date-input
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
|
|
1
2
|
/*
|
|
2
3
|
* The MIT License (MIT)
|
|
3
4
|
*
|
|
@@ -21,69 +22,571 @@
|
|
|
21
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
23
|
* SOFTWARE.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
27
|
+
import userEvent from '@testing-library/user-event';
|
|
27
28
|
import '@testing-library/jest-dom';
|
|
28
|
-
// import DateInput from '../index'
|
|
29
29
|
|
|
30
|
+
// eslint-disable-next-line no-restricted-imports
|
|
31
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
33
|
+
import { Calendar } from '@instructure/ui-calendar';
|
|
34
|
+
import Examples from '../__examples__/DateInput.examples';
|
|
35
|
+
import { DateInput } from '../index';
|
|
30
36
|
describe('<DateInput />', () => {
|
|
37
|
+
const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
38
|
+
const generateDays = (count = Calendar.DAY_COUNT) => {
|
|
39
|
+
const days = [];
|
|
40
|
+
const date = new Date('2019-07-28');
|
|
41
|
+
while (days.length < count) {
|
|
42
|
+
days.push( /*#__PURE__*/React.createElement(Calendar.Day, {
|
|
43
|
+
key: date.toISOString(),
|
|
44
|
+
date: date.toISOString(),
|
|
45
|
+
label: date.toISOString()
|
|
46
|
+
}, date.getDate()));
|
|
47
|
+
date.setDate(date.getDate() + 1);
|
|
48
|
+
}
|
|
49
|
+
return days;
|
|
50
|
+
};
|
|
51
|
+
it('should render an input and a calendar', async () => {
|
|
52
|
+
const _render = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
53
|
+
renderLabel: "date-input",
|
|
54
|
+
renderWeekdayLabels: weekdayLabels,
|
|
55
|
+
isShowingCalendar: true
|
|
56
|
+
}, generateDays())),
|
|
57
|
+
container = _render.container,
|
|
58
|
+
findByRole = _render.findByRole;
|
|
59
|
+
const dateInput = container.querySelector('input');
|
|
60
|
+
expect(dateInput).toBeInTheDocument();
|
|
61
|
+
expect(dateInput).toHaveAttribute('type', 'text');
|
|
62
|
+
await userEvent.click(dateInput);
|
|
63
|
+
const calendarTable = await findByRole('listbox');
|
|
64
|
+
const calendarWrapper = await document.querySelector('[id^="Selectable_"][id$="-list"]');
|
|
65
|
+
await waitFor(() => {
|
|
66
|
+
expect(calendarWrapper).toBeInTheDocument();
|
|
67
|
+
expect(calendarTable).toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('input', () => {
|
|
71
|
+
it('should render a label', () => {
|
|
72
|
+
const labelText = 'label text';
|
|
73
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
74
|
+
renderLabel: labelText,
|
|
75
|
+
renderWeekdayLabels: weekdayLabels
|
|
76
|
+
}, generateDays()));
|
|
77
|
+
const dateInput = screen.getByLabelText('label text');
|
|
78
|
+
expect(dateInput).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
it('should set value', () => {
|
|
81
|
+
const value = 'January 5';
|
|
82
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
83
|
+
renderLabel: "Choose date",
|
|
84
|
+
value: value,
|
|
85
|
+
onChange: jest.fn(),
|
|
86
|
+
renderWeekdayLabels: weekdayLabels
|
|
87
|
+
}, generateDays()));
|
|
88
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
89
|
+
expect(dateInput).toHaveValue(value);
|
|
90
|
+
});
|
|
91
|
+
it('should call onChange with the updated value', async () => {
|
|
92
|
+
const onChange = jest.fn();
|
|
93
|
+
const value = 'May 18, 2022';
|
|
94
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
95
|
+
renderLabel: "Choose date",
|
|
96
|
+
renderWeekdayLabels: weekdayLabels,
|
|
97
|
+
onChange: onChange
|
|
98
|
+
}, generateDays()));
|
|
99
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
100
|
+
fireEvent.change(dateInput, {
|
|
101
|
+
target: {
|
|
102
|
+
value: value
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
fireEvent.keyDown(dateInput, {
|
|
106
|
+
key: 'Enter',
|
|
107
|
+
code: 'Enter'
|
|
108
|
+
});
|
|
109
|
+
fireEvent.blur(dateInput);
|
|
110
|
+
await waitFor(() => {
|
|
111
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(onChange.mock.calls[0][1].value).toEqual(expect.stringContaining(value));
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('should call onBlur', () => {
|
|
116
|
+
const onBlur = jest.fn();
|
|
117
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
118
|
+
renderLabel: "Choose date",
|
|
119
|
+
renderWeekdayLabels: weekdayLabels,
|
|
120
|
+
onBlur: onBlur
|
|
121
|
+
}, generateDays()));
|
|
122
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
123
|
+
fireEvent.blur(dateInput);
|
|
124
|
+
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
it('should correctly set interaction type', async () => {
|
|
127
|
+
const _render2 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
128
|
+
renderLabel: "Choose date",
|
|
129
|
+
renderWeekdayLabels: weekdayLabels,
|
|
130
|
+
interaction: "disabled"
|
|
131
|
+
}, generateDays())),
|
|
132
|
+
rerender = _render2.rerender;
|
|
133
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
134
|
+
expect(dateInput).toHaveAttribute('disabled');
|
|
135
|
+
rerender( /*#__PURE__*/React.createElement(DateInput, {
|
|
136
|
+
renderLabel: "Choose date",
|
|
137
|
+
renderWeekdayLabels: weekdayLabels,
|
|
138
|
+
interaction: "readonly"
|
|
139
|
+
}, generateDays()));
|
|
140
|
+
const dateInputAfterUpdate = screen.getByLabelText('Choose date');
|
|
141
|
+
await waitFor(() => {
|
|
142
|
+
expect(dateInputAfterUpdate).toHaveAttribute('readonly');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it('should correctly set disabled', () => {
|
|
146
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
147
|
+
renderLabel: "Choose date",
|
|
148
|
+
renderWeekdayLabels: weekdayLabels,
|
|
149
|
+
disabled: true
|
|
150
|
+
}, generateDays()));
|
|
151
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
152
|
+
expect(dateInput).toHaveAttribute('disabled');
|
|
153
|
+
});
|
|
154
|
+
it('should correctly set readOnly', () => {
|
|
155
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
156
|
+
renderLabel: "Choose date",
|
|
157
|
+
renderWeekdayLabels: weekdayLabels,
|
|
158
|
+
readOnly: true
|
|
159
|
+
}, generateDays()));
|
|
160
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
161
|
+
expect(dateInput).toHaveAttribute('readOnly');
|
|
162
|
+
});
|
|
163
|
+
it('should set placeholder', () => {
|
|
164
|
+
const placeholder = 'Start typing to choose a date';
|
|
165
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
166
|
+
renderLabel: "Choose date",
|
|
167
|
+
renderWeekdayLabels: weekdayLabels,
|
|
168
|
+
placeholder: placeholder
|
|
169
|
+
}, generateDays()));
|
|
170
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
171
|
+
expect(dateInput).toHaveAttribute('placeholder', placeholder);
|
|
172
|
+
});
|
|
173
|
+
it('should be requireable', () => {
|
|
174
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
175
|
+
renderLabel: "Choose date",
|
|
176
|
+
renderWeekdayLabels: weekdayLabels,
|
|
177
|
+
isRequired: true
|
|
178
|
+
}, generateDays()));
|
|
179
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
180
|
+
expect(dateInput).toHaveAttribute('required');
|
|
181
|
+
});
|
|
182
|
+
it('should provide inputRef', () => {
|
|
183
|
+
const inputRef = jest.fn();
|
|
184
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
185
|
+
renderLabel: "Choose date",
|
|
186
|
+
renderWeekdayLabels: weekdayLabels,
|
|
187
|
+
inputRef: inputRef
|
|
188
|
+
}, generateDays()));
|
|
189
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
190
|
+
expect(inputRef).toHaveBeenCalledWith(dateInput);
|
|
191
|
+
});
|
|
192
|
+
it('should render messages', () => {
|
|
193
|
+
const text = 'The selected date is invalid';
|
|
194
|
+
const _render3 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
195
|
+
renderLabel: "Choose date",
|
|
196
|
+
renderWeekdayLabels: weekdayLabels,
|
|
197
|
+
messages: [{
|
|
198
|
+
type: 'error',
|
|
199
|
+
text
|
|
200
|
+
}]
|
|
201
|
+
}, generateDays())),
|
|
202
|
+
container = _render3.container;
|
|
203
|
+
expect(container).toHaveTextContent(text);
|
|
204
|
+
});
|
|
205
|
+
it('should allow custom props to pass through', () => {
|
|
206
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
207
|
+
renderLabel: "Choose date",
|
|
208
|
+
renderWeekdayLabels: weekdayLabels,
|
|
209
|
+
"data-custom-attr": "custom value",
|
|
210
|
+
name: "my name"
|
|
211
|
+
}, generateDays()));
|
|
212
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
213
|
+
expect(dateInput).toHaveAttribute('data-custom-attr', 'custom value');
|
|
214
|
+
expect(dateInput).toHaveAttribute('name', 'my name');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
describe('Calendar', () => {
|
|
218
|
+
it('should show calendar when `isShowingCalendar` is set', async () => {
|
|
219
|
+
const _render4 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
220
|
+
renderLabel: "Choose date",
|
|
221
|
+
renderWeekdayLabels: weekdayLabels
|
|
222
|
+
}, generateDays())),
|
|
223
|
+
rerender = _render4.rerender,
|
|
224
|
+
queryByRole = _render4.queryByRole;
|
|
225
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
226
|
+
const calendarTable = await queryByRole('listbox');
|
|
227
|
+
const calendarWrapper = await document.querySelector('[id^="Selectable_"][id$="-list"]');
|
|
228
|
+
expect(dateInput).toBeInTheDocument();
|
|
229
|
+
expect(calendarTable).not.toBeInTheDocument();
|
|
230
|
+
expect(calendarWrapper).not.toBeInTheDocument();
|
|
231
|
+
rerender( /*#__PURE__*/React.createElement(DateInput, {
|
|
232
|
+
renderLabel: "Choose date",
|
|
233
|
+
renderWeekdayLabels: weekdayLabels,
|
|
234
|
+
isShowingCalendar: true
|
|
235
|
+
}, generateDays()));
|
|
236
|
+
const dateInputAfterUpdate = screen.getByLabelText('Choose date');
|
|
237
|
+
const calendarTableAfterUpdate = await queryByRole('listbox');
|
|
238
|
+
const calendarWrapperAfterUpdate = await document.querySelector('[id^="Selectable_"][id$="-list"]');
|
|
239
|
+
await waitFor(() => {
|
|
240
|
+
expect(dateInputAfterUpdate).toBeInTheDocument();
|
|
241
|
+
expect(calendarTableAfterUpdate).toBeInTheDocument();
|
|
242
|
+
expect(calendarWrapperAfterUpdate).toBeInTheDocument();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
describe('onRequestShowCalendar', () => {
|
|
246
|
+
it('should call onRequestShowCalendar when label is clicked', async () => {
|
|
247
|
+
const onRequestShowCalendar = jest.fn();
|
|
248
|
+
const _render5 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
249
|
+
renderLabel: "Choose date",
|
|
250
|
+
renderWeekdayLabels: weekdayLabels,
|
|
251
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
252
|
+
}, generateDays())),
|
|
253
|
+
container = _render5.container;
|
|
254
|
+
const dateInput = container.querySelector("[class$='-formFieldLabel']");
|
|
255
|
+
expect(dateInput).toHaveTextContent('Choose date');
|
|
256
|
+
await userEvent.click(dateInput);
|
|
257
|
+
await waitFor(() => {
|
|
258
|
+
expect(onRequestShowCalendar).toHaveBeenCalled();
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
it('should call onRequestShowCalendar when input is clicked', async () => {
|
|
262
|
+
const onRequestShowCalendar = jest.fn();
|
|
263
|
+
const _render6 = render( /*#__PURE__*/React.createElement(DateInput, {
|
|
264
|
+
renderLabel: "Choose date",
|
|
265
|
+
renderWeekdayLabels: weekdayLabels,
|
|
266
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
267
|
+
}, generateDays())),
|
|
268
|
+
container = _render6.container;
|
|
269
|
+
const dateInput = container.querySelector('input');
|
|
270
|
+
await userEvent.click(dateInput);
|
|
271
|
+
await waitFor(() => {
|
|
272
|
+
expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
it('should call onRequestShowCalendar when input receives space event', async () => {
|
|
276
|
+
const onRequestShowCalendar = jest.fn();
|
|
277
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
278
|
+
renderLabel: "Choose date",
|
|
279
|
+
renderWeekdayLabels: weekdayLabels,
|
|
280
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
281
|
+
}, generateDays()));
|
|
282
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
283
|
+
await userEvent.type(dateInput, '{space}');
|
|
284
|
+
await waitFor(() => {
|
|
285
|
+
expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
it('should not call onRequestShowCalendar when input receives space event if calendar is already showing', async () => {
|
|
289
|
+
const onRequestShowCalendar = jest.fn();
|
|
290
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
291
|
+
renderLabel: "Choose date",
|
|
292
|
+
renderWeekdayLabels: weekdayLabels,
|
|
293
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
|
294
|
+
isShowingCalendar: true
|
|
295
|
+
}, generateDays()));
|
|
296
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
297
|
+
await userEvent.type(dateInput, '{space}');
|
|
298
|
+
await waitFor(() => {
|
|
299
|
+
expect(onRequestShowCalendar).not.toHaveBeenCalled();
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
it('should call onRequestShowCalendar when input receives down arrow event', async () => {
|
|
303
|
+
const onRequestShowCalendar = jest.fn();
|
|
304
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
305
|
+
renderLabel: "Choose date",
|
|
306
|
+
renderWeekdayLabels: weekdayLabels,
|
|
307
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
308
|
+
}, generateDays()));
|
|
309
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
310
|
+
await userEvent.type(dateInput, '{arrowdown}');
|
|
311
|
+
await waitFor(() => {
|
|
312
|
+
expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
it('should not call onRequestShowCalendar when input receives down arrow event if calendar is already showing', async () => {
|
|
316
|
+
const onRequestShowCalendar = jest.fn();
|
|
317
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
318
|
+
renderLabel: "Choose date",
|
|
319
|
+
renderWeekdayLabels: weekdayLabels,
|
|
320
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
|
321
|
+
isShowingCalendar: true
|
|
322
|
+
}, generateDays()));
|
|
323
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
324
|
+
await userEvent.type(dateInput, '{arrowdown}');
|
|
325
|
+
await waitFor(() => {
|
|
326
|
+
expect(onRequestShowCalendar).not.toHaveBeenCalled();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
it('should call onRequestShowCalendar when input receives up arrow event', async () => {
|
|
330
|
+
const onRequestShowCalendar = jest.fn();
|
|
331
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
332
|
+
renderLabel: "Choose date",
|
|
333
|
+
renderWeekdayLabels: weekdayLabels,
|
|
334
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
335
|
+
}, generateDays()));
|
|
336
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
337
|
+
await userEvent.type(dateInput, '{arrowup}');
|
|
338
|
+
await waitFor(() => {
|
|
339
|
+
expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
it('should not call onRequestShowCalendar when input receives up arrow event if calendar is already showing', async () => {
|
|
343
|
+
const onRequestShowCalendar = jest.fn();
|
|
344
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
345
|
+
renderLabel: "Choose date",
|
|
346
|
+
renderWeekdayLabels: weekdayLabels,
|
|
347
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
|
348
|
+
isShowingCalendar: true
|
|
349
|
+
}, generateDays()));
|
|
350
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
351
|
+
await userEvent.type(dateInput, '{arrowup}');
|
|
352
|
+
await waitFor(() => {
|
|
353
|
+
expect(onRequestShowCalendar).not.toHaveBeenCalled();
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
it('should call onRequestShowCalendar when input receives onChange event', async () => {
|
|
357
|
+
const onRequestShowCalendar = jest.fn();
|
|
358
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
359
|
+
renderLabel: "Choose date",
|
|
360
|
+
renderWeekdayLabels: weekdayLabels,
|
|
361
|
+
onRequestShowCalendar: onRequestShowCalendar
|
|
362
|
+
}, generateDays()));
|
|
363
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
364
|
+
fireEvent.change(dateInput, {
|
|
365
|
+
target: {
|
|
366
|
+
value: 'January 5'
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
await waitFor(() => {
|
|
370
|
+
expect(onRequestShowCalendar).toHaveBeenCalledTimes(1);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
it('should not call onRequestShowCalendar when disabled', async () => {
|
|
374
|
+
const onRequestShowCalendar = jest.fn();
|
|
375
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
376
|
+
renderLabel: "Choose date",
|
|
377
|
+
renderWeekdayLabels: weekdayLabels,
|
|
378
|
+
onRequestShowCalendar: onRequestShowCalendar,
|
|
379
|
+
interaction: "disabled"
|
|
380
|
+
}, generateDays()));
|
|
381
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
382
|
+
fireEvent.click(dateInput);
|
|
383
|
+
await userEvent.type(dateInput, '{arrowup}{arrowdown}{space}January 5', {
|
|
384
|
+
skipClick: true
|
|
385
|
+
});
|
|
386
|
+
await waitFor(() => {
|
|
387
|
+
expect(onRequestShowCalendar).not.toHaveBeenCalled();
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
describe('onRequestHideCalendar and onRequestValidateDate', () => {
|
|
392
|
+
it('should call onRequestHideCalendar and onRequestValidateDate input receives onBlur event', async () => {
|
|
393
|
+
const onRequestHideCalendar = jest.fn();
|
|
394
|
+
const onRequestValidateDate = jest.fn();
|
|
395
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
396
|
+
renderLabel: "Choose date",
|
|
397
|
+
renderWeekdayLabels: weekdayLabels,
|
|
398
|
+
onRequestHideCalendar: onRequestHideCalendar,
|
|
399
|
+
onRequestValidateDate: onRequestValidateDate,
|
|
400
|
+
isShowingCalendar: true
|
|
401
|
+
}, generateDays()));
|
|
402
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
403
|
+
fireEvent.blur(dateInput);
|
|
404
|
+
await waitFor(() => {
|
|
405
|
+
expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
|
|
406
|
+
expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
it('should call onRequestHideCalendar and onRequestValidateDate when input receives esc event', async () => {
|
|
410
|
+
const onRequestHideCalendar = jest.fn();
|
|
411
|
+
const onRequestValidateDate = jest.fn();
|
|
412
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
413
|
+
renderLabel: "Choose date",
|
|
414
|
+
renderWeekdayLabels: weekdayLabels,
|
|
415
|
+
onRequestHideCalendar: onRequestHideCalendar,
|
|
416
|
+
onRequestValidateDate: onRequestValidateDate,
|
|
417
|
+
isShowingCalendar: true
|
|
418
|
+
}, generateDays()));
|
|
419
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
420
|
+
await userEvent.type(dateInput, '{esc}');
|
|
421
|
+
await waitFor(() => {
|
|
422
|
+
expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
|
|
423
|
+
expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
it('should call onRequestHideCalendar and onRequestValidateDate when input receives enter event', async () => {
|
|
427
|
+
const onRequestHideCalendar = jest.fn();
|
|
428
|
+
const onRequestValidateDate = jest.fn();
|
|
429
|
+
const days = generateDays();
|
|
430
|
+
days[4] = _Calendar$Day || (_Calendar$Day = /*#__PURE__*/React.createElement(Calendar.Day, {
|
|
431
|
+
key: "4",
|
|
432
|
+
label: "4",
|
|
433
|
+
date: "2019-09-28",
|
|
434
|
+
isSelected: true
|
|
435
|
+
}, 4));
|
|
436
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
437
|
+
renderLabel: "Choose date",
|
|
438
|
+
renderWeekdayLabels: weekdayLabels,
|
|
439
|
+
onRequestHideCalendar: onRequestHideCalendar,
|
|
440
|
+
onRequestValidateDate: onRequestValidateDate,
|
|
441
|
+
isShowingCalendar: true
|
|
442
|
+
}, days));
|
|
443
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
444
|
+
await userEvent.type(dateInput, '{enter}');
|
|
445
|
+
await waitFor(() => {
|
|
446
|
+
expect(onRequestHideCalendar).toHaveBeenCalledTimes(1);
|
|
447
|
+
expect(onRequestValidateDate).toHaveBeenCalledTimes(1);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
it('should render calendar navigation label', () => {
|
|
452
|
+
const label = 'January 2019';
|
|
453
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
454
|
+
renderLabel: "Choose date",
|
|
455
|
+
renderWeekdayLabels: weekdayLabels,
|
|
456
|
+
renderNavigationLabel: /*#__PURE__*/React.createElement("div", {
|
|
457
|
+
"data-testId": "label-id"
|
|
458
|
+
}, label),
|
|
459
|
+
isShowingCalendar: true
|
|
460
|
+
}, generateDays()));
|
|
461
|
+
const navigationLabel = screen.getByTestId('label-id');
|
|
462
|
+
expect(navigationLabel).toBeInTheDocument();
|
|
463
|
+
expect(navigationLabel).toHaveTextContent(label);
|
|
464
|
+
});
|
|
465
|
+
it('should render calendar weekday labels', async () => {
|
|
466
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
467
|
+
renderLabel: "Choose date",
|
|
468
|
+
renderWeekdayLabels: weekdayLabels,
|
|
469
|
+
isShowingCalendar: true
|
|
470
|
+
}, generateDays()));
|
|
471
|
+
const calendar = await screen.findByRole('listbox');
|
|
472
|
+
const headers = calendar.querySelectorAll('th');
|
|
473
|
+
expect(headers.length).toEqual(7);
|
|
474
|
+
weekdayLabels.forEach(label => {
|
|
475
|
+
expect(calendar).toHaveTextContent(label);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
it('should render all focusable elements in calendar with tabIndex="-1"', async () => {
|
|
479
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
480
|
+
renderLabel: "Choose date",
|
|
481
|
+
renderWeekdayLabels: weekdayLabels,
|
|
482
|
+
renderNextMonthButton: _button || (_button = /*#__PURE__*/React.createElement("button", {
|
|
483
|
+
"data-testId": "button-next"
|
|
484
|
+
}, "next")),
|
|
485
|
+
renderPrevMonthButton: _button2 || (_button2 = /*#__PURE__*/React.createElement("button", {
|
|
486
|
+
"data-testId": "button-prev"
|
|
487
|
+
}, "prev")),
|
|
488
|
+
isShowingCalendar: true
|
|
489
|
+
}, generateDays()));
|
|
490
|
+
const calendar = await screen.findByRole('listbox');
|
|
491
|
+
const calendarDays = calendar.querySelectorAll('button');
|
|
492
|
+
const nextMonthButton = screen.getByTestId('button-next');
|
|
493
|
+
const prevMonthButton = screen.getByTestId('button-prev');
|
|
494
|
+
expect(nextMonthButton).toHaveAttribute('tabIndex', '-1');
|
|
495
|
+
expect(prevMonthButton).toHaveAttribute('tabIndex', '-1');
|
|
496
|
+
expect(calendarDays).toHaveLength(42);
|
|
497
|
+
calendarDays.forEach(day => {
|
|
498
|
+
expect(day).toHaveAttribute('tabIndex', '-1');
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
it('should render days with the correct role', async () => {
|
|
502
|
+
const days = generateDays();
|
|
503
|
+
days[5] = _Calendar$Day2 || (_Calendar$Day2 = /*#__PURE__*/React.createElement(Calendar.Day, {
|
|
504
|
+
key: "5",
|
|
505
|
+
label: "5",
|
|
506
|
+
date: "2019-09-28",
|
|
507
|
+
id: "5",
|
|
508
|
+
isOutsideMonth: true
|
|
509
|
+
}, "outside"));
|
|
510
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
511
|
+
renderLabel: "Choose date",
|
|
512
|
+
renderWeekdayLabels: weekdayLabels,
|
|
513
|
+
isShowingCalendar: true
|
|
514
|
+
}, days));
|
|
515
|
+
const calendar = await screen.findByRole('listbox');
|
|
516
|
+
const calendarDays = calendar.querySelectorAll('button');
|
|
517
|
+
calendarDays.forEach(day => {
|
|
518
|
+
if (day.textContent.includes('outside')) {
|
|
519
|
+
expect(day).toHaveAttribute('role', 'presentation');
|
|
520
|
+
} else {
|
|
521
|
+
expect(day).toHaveAttribute('role', 'option');
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
it('should assign aria-selected to the selected date and link it to the input', async () => {
|
|
526
|
+
const days = generateDays();
|
|
527
|
+
days[7] = _Calendar$Day3 || (_Calendar$Day3 = /*#__PURE__*/React.createElement(Calendar.Day, {
|
|
528
|
+
key: "7",
|
|
529
|
+
label: "7",
|
|
530
|
+
date: "2019-09-28",
|
|
531
|
+
id: "selected-day-id",
|
|
532
|
+
isSelected: true
|
|
533
|
+
}, "selected"));
|
|
534
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
535
|
+
renderLabel: "Choose date",
|
|
536
|
+
renderWeekdayLabels: weekdayLabels,
|
|
537
|
+
isShowingCalendar: true
|
|
538
|
+
}, days));
|
|
539
|
+
const calendar = await screen.findByRole('listbox');
|
|
540
|
+
const calendarDays = calendar.querySelectorAll('button');
|
|
541
|
+
let selectedDayID = '';
|
|
542
|
+
calendarDays.forEach(day => {
|
|
543
|
+
if (day.textContent.includes('selected')) {
|
|
544
|
+
selectedDayID = day.id;
|
|
545
|
+
expect(day).toHaveAttribute('aria-selected', 'true');
|
|
546
|
+
} else {
|
|
547
|
+
expect(day).toHaveAttribute('aria-selected', 'false');
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
551
|
+
expect(dateInput).toHaveAttribute('aria-activedescendant', selectedDayID);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
describe('with generated examples', () => {
|
|
555
|
+
const generatedComponents = generateA11yTests(DateInput, Examples);
|
|
556
|
+
it.each(generatedComponents)('should be accessible with example: $description', async ({
|
|
557
|
+
content
|
|
558
|
+
}) => {
|
|
559
|
+
const _render7 = render(content),
|
|
560
|
+
container = _render7.container;
|
|
561
|
+
const axeCheck = await runAxeCheck(container);
|
|
562
|
+
expect(axeCheck).toBe(true);
|
|
563
|
+
});
|
|
564
|
+
});
|
|
31
565
|
describe('with minimal config', () => {
|
|
32
|
-
it('should
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// expect(buttons.length).toEqual(44)
|
|
58
|
-
// })
|
|
59
|
-
// it('should select the correct day on Calendar when value is set', async () => {
|
|
60
|
-
// const onChange = jest.fn()
|
|
61
|
-
// render(
|
|
62
|
-
// <DateInput
|
|
63
|
-
// renderLabel="Choose a date"
|
|
64
|
-
// assistiveText="Type a date or use arrow keys to navigate date picker."
|
|
65
|
-
// width="20rem"
|
|
66
|
-
// isInline
|
|
67
|
-
// value={'2023-11-23'}
|
|
68
|
-
// onChange={onChange}
|
|
69
|
-
// currentDate="2023-11-25"
|
|
70
|
-
// disabledDates={['2023-12-22', '2023-12-12', '2023-12-11']}
|
|
71
|
-
// disabledDateErrorMessage="disabled date"
|
|
72
|
-
// invalidDateErrorMessage="invalid date"
|
|
73
|
-
// ></DateInput>
|
|
74
|
-
// )
|
|
75
|
-
// const inputField = screen.queryByRole('combobox')
|
|
76
|
-
// await act(async () => {
|
|
77
|
-
// await inputField?.click()
|
|
78
|
-
// })
|
|
79
|
-
// const selectedDay =
|
|
80
|
-
// screen.queryByText('23 November 2023')?.parentElement?.parentElement
|
|
81
|
-
// expect(selectedDay).toBeDefined()
|
|
82
|
-
// if (selectedDay) {
|
|
83
|
-
// expect(window.getComputedStyle(selectedDay)?.background).toBe(
|
|
84
|
-
// 'rgb(11, 135, 75)'
|
|
85
|
-
// )
|
|
86
|
-
// }
|
|
87
|
-
// })
|
|
566
|
+
it('should render 44 buttons (a calendar) when clicked', async () => {
|
|
567
|
+
const onChange = jest.fn();
|
|
568
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
569
|
+
renderLabel: "Choose date",
|
|
570
|
+
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
|
571
|
+
width: "20rem",
|
|
572
|
+
isInline: true,
|
|
573
|
+
value: '2023-11-23',
|
|
574
|
+
onChange: onChange,
|
|
575
|
+
currentDate: "2023-12-23",
|
|
576
|
+
disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11'],
|
|
577
|
+
disabledDateErrorMessage: "disabled date",
|
|
578
|
+
invalidDateErrorMessage: "invalid date"
|
|
579
|
+
}));
|
|
580
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
581
|
+
fireEvent.click(dateInput);
|
|
582
|
+
const calendarTable = document.querySelector('table');
|
|
583
|
+
const calendarDays = calendarTable.querySelectorAll('button');
|
|
584
|
+
const calendarWrapper = document.querySelector('[id^="Selectable_"][id$="-list"]');
|
|
585
|
+
const calendarButtons = calendarWrapper.querySelectorAll('button');
|
|
586
|
+
await waitFor(() => {
|
|
587
|
+
expect(calendarButtons).toHaveLength(44);
|
|
588
|
+
expect(calendarDays).toHaveLength(42);
|
|
589
|
+
});
|
|
590
|
+
});
|
|
88
591
|
});
|
|
89
592
|
});
|