@instructure/ui-date-input 9.10.2 → 9.11.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 +19 -0
- package/es/DateInput/__new-tests__/DateInput.test.js +1 -1
- package/es/DateInput2/__new-tests__/DateInput2.test.js +301 -0
- package/lib/DateInput/__new-tests__/DateInput.test.js +1 -1
- package/lib/DateInput2/__new-tests__/DateInput2.test.js +305 -0
- package/package.json +20 -20
- package/src/DateInput/__new-tests__/DateInput.test.tsx +3 -1
- package/src/DateInput2/__new-tests__/DateInput2.test.tsx +360 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput2/__new-tests__/DateInput2.test.d.ts +2 -0
- package/types/DateInput2/__new-tests__/DateInput2.test.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,25 @@
|
|
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.11.1](https://github.com/instructure/instructure-ui/compare/v9.11.0...v9.11.1) (2025-03-11)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* fix FormFieldLabel not read on NVDA hover ([c29b6ab](https://github.com/instructure/instructure-ui/commit/c29b6ab989266c6a7875e3f0dbdee3efbf18606a))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# [9.11.0](https://github.com/instructure/instructure-ui/compare/v9.10.2...v9.11.0) (2025-02-12)
|
18
|
+
|
19
|
+
**Note:** Version bump only for package @instructure/ui-date-input
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
6
25
|
## [9.10.2](https://github.com/instructure/instructure-ui/compare/v9.10.1...v9.10.2) (2024-12-19)
|
7
26
|
|
8
27
|
**Note:** Version bump only for package @instructure/ui-date-input
|
@@ -263,7 +263,7 @@ describe('<DateInput />', () => {
|
|
263
263
|
onRequestShowCalendar: onRequestShowCalendar
|
264
264
|
}, generateDays())),
|
265
265
|
container = _render5.container;
|
266
|
-
const dateInput = container.querySelector(
|
266
|
+
const dateInput = container.querySelector('span[class$="-formFieldLayout__label"]');
|
267
267
|
expect(dateInput).toHaveTextContent('Choose date');
|
268
268
|
await userEvent.click(dateInput);
|
269
269
|
await waitFor(() => {
|
@@ -0,0 +1,301 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
var _DateInputExample, _DateInputExample2, _DateInputExample3;
|
3
|
+
/*
|
4
|
+
* The MIT License (MIT)
|
5
|
+
*
|
6
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
16
|
+
* copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
* SOFTWARE.
|
25
|
+
*/
|
26
|
+
import React, { useState } from 'react';
|
27
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
28
|
+
import { vi } from 'vitest';
|
29
|
+
import userEvent from '@testing-library/user-event';
|
30
|
+
import '@testing-library/jest-dom';
|
31
|
+
import { DateInput2 } from '../index';
|
32
|
+
const LABEL_TEXT = 'Choose a date';
|
33
|
+
const DateInputExample = () => {
|
34
|
+
const _useState = useState(''),
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
36
|
+
inputValue = _useState2[0],
|
37
|
+
setInputValue = _useState2[1];
|
38
|
+
return /*#__PURE__*/React.createElement(DateInput2, {
|
39
|
+
renderLabel: LABEL_TEXT,
|
40
|
+
screenReaderLabels: {
|
41
|
+
calendarIcon: 'Calendar',
|
42
|
+
nextMonthButton: 'Next month',
|
43
|
+
prevMonthButton: 'Previous month'
|
44
|
+
},
|
45
|
+
value: inputValue,
|
46
|
+
onChange: (_e, inputValue, _dateString) => {
|
47
|
+
setInputValue(inputValue);
|
48
|
+
}
|
49
|
+
});
|
50
|
+
};
|
51
|
+
describe('<DateInput2 />', () => {
|
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
|
+
});
|
63
|
+
it('should render an input', async () => {
|
64
|
+
const _render = render(_DateInputExample || (_DateInputExample = /*#__PURE__*/React.createElement(DateInputExample, null))),
|
65
|
+
container = _render.container;
|
66
|
+
const dateInput = container.querySelector('input');
|
67
|
+
expect(dateInput).toBeInTheDocument();
|
68
|
+
expect(dateInput).toHaveAttribute('type', 'text');
|
69
|
+
});
|
70
|
+
it('should render an input label', async () => {
|
71
|
+
const _render2 = render(_DateInputExample2 || (_DateInputExample2 = /*#__PURE__*/React.createElement(DateInputExample, null))),
|
72
|
+
container = _render2.container;
|
73
|
+
const label = container.querySelector('label');
|
74
|
+
expect(label).toBeInTheDocument();
|
75
|
+
expect(label).toHaveTextContent(LABEL_TEXT);
|
76
|
+
});
|
77
|
+
it('should render an input placeholder', async () => {
|
78
|
+
const placeholder = 'Placeholder';
|
79
|
+
render( /*#__PURE__*/React.createElement(DateInput2, {
|
80
|
+
renderLabel: "Choose a date",
|
81
|
+
screenReaderLabels: {
|
82
|
+
calendarIcon: 'Calendar',
|
83
|
+
nextMonthButton: 'Next month',
|
84
|
+
prevMonthButton: 'Previous month'
|
85
|
+
},
|
86
|
+
placeholder: placeholder,
|
87
|
+
value: ""
|
88
|
+
}));
|
89
|
+
const dateInput = screen.getByLabelText('Choose a date');
|
90
|
+
expect(dateInput).toHaveAttribute('placeholder', placeholder);
|
91
|
+
});
|
92
|
+
it('should render a calendar icon with screen reader label', async () => {
|
93
|
+
const iconLabel = 'Calendar icon Label';
|
94
|
+
const _render3 = render( /*#__PURE__*/React.createElement(DateInput2, {
|
95
|
+
renderLabel: "Choose a date",
|
96
|
+
screenReaderLabels: {
|
97
|
+
calendarIcon: iconLabel,
|
98
|
+
nextMonthButton: 'Next month',
|
99
|
+
prevMonthButton: 'Previous month'
|
100
|
+
},
|
101
|
+
value: ""
|
102
|
+
})),
|
103
|
+
container = _render3.container;
|
104
|
+
const calendarIcon = container.querySelector('svg[name="IconCalendarMonth"]');
|
105
|
+
const calendarLabel = screen.getByText(iconLabel);
|
106
|
+
expect(calendarIcon).toBeInTheDocument();
|
107
|
+
expect(calendarLabel).toBeInTheDocument();
|
108
|
+
});
|
109
|
+
it('should not show calendar table by default', async () => {
|
110
|
+
render(_DateInputExample3 || (_DateInputExample3 = /*#__PURE__*/React.createElement(DateInputExample, null)));
|
111
|
+
const calendarTable = screen.queryByRole('table');
|
112
|
+
expect(calendarTable).not.toBeInTheDocument();
|
113
|
+
});
|
114
|
+
it('should render navigation arrow buttons with screen reader labels', async () => {
|
115
|
+
const nextMonthLabel = 'Next month';
|
116
|
+
const prevMonthLabel = 'Previous month';
|
117
|
+
render( /*#__PURE__*/React.createElement(DateInput2, {
|
118
|
+
renderLabel: "Choose a date",
|
119
|
+
screenReaderLabels: {
|
120
|
+
calendarIcon: 'Calendar',
|
121
|
+
nextMonthButton: nextMonthLabel,
|
122
|
+
prevMonthButton: prevMonthLabel
|
123
|
+
},
|
124
|
+
value: ""
|
125
|
+
}));
|
126
|
+
const calendarButton = screen.getByRole('button');
|
127
|
+
await userEvent.click(calendarButton);
|
128
|
+
await waitFor(() => {
|
129
|
+
const prevMonthButton = screen.getByRole('button', {
|
130
|
+
name: prevMonthLabel
|
131
|
+
});
|
132
|
+
const nextMonthButton = screen.getByRole('button', {
|
133
|
+
name: nextMonthLabel
|
134
|
+
});
|
135
|
+
expect(prevMonthButton).toBeInTheDocument();
|
136
|
+
expect(nextMonthButton).toBeInTheDocument();
|
137
|
+
const prevButtonLabel = screen.getByText(prevMonthLabel);
|
138
|
+
const nextButtonLabel = screen.getByText(nextMonthLabel);
|
139
|
+
expect(prevButtonLabel).toBeInTheDocument();
|
140
|
+
expect(nextButtonLabel).toBeInTheDocument();
|
141
|
+
const prevMonthIcon = prevMonthButton.querySelector('svg[name="IconArrowOpenStart"]');
|
142
|
+
const nextMonthIcon = nextMonthButton.querySelector('svg[name="IconArrowOpenEnd"]');
|
143
|
+
expect(prevMonthIcon).toBeInTheDocument();
|
144
|
+
expect(nextMonthIcon).toBeInTheDocument();
|
145
|
+
});
|
146
|
+
});
|
147
|
+
it('should programmatically set and render the initial value', async () => {
|
148
|
+
const value = '26/03/2024';
|
149
|
+
render( /*#__PURE__*/React.createElement(DateInput2, {
|
150
|
+
renderLabel: "Choose a date",
|
151
|
+
screenReaderLabels: {
|
152
|
+
calendarIcon: 'Calendar',
|
153
|
+
nextMonthButton: 'Next month',
|
154
|
+
prevMonthButton: 'Previous month'
|
155
|
+
},
|
156
|
+
locale: "en-GB",
|
157
|
+
timezone: "UTC",
|
158
|
+
value: value
|
159
|
+
}));
|
160
|
+
const dateInput = screen.getByLabelText('Choose a date');
|
161
|
+
expect(dateInput).toHaveValue(value);
|
162
|
+
expect(dateInput).toBeInTheDocument();
|
163
|
+
});
|
164
|
+
it('should set interaction type to disabled', async () => {
|
165
|
+
const interactionDisabled = 'disabled';
|
166
|
+
const _render4 = render( /*#__PURE__*/React.createElement(DateInput2, {
|
167
|
+
renderLabel: "Choose a date",
|
168
|
+
screenReaderLabels: {
|
169
|
+
calendarIcon: 'Calendar',
|
170
|
+
nextMonthButton: 'Next month',
|
171
|
+
prevMonthButton: 'Previous month'
|
172
|
+
},
|
173
|
+
value: "",
|
174
|
+
interaction: interactionDisabled
|
175
|
+
})),
|
176
|
+
container = _render4.container;
|
177
|
+
const dateInput = container.querySelector('input');
|
178
|
+
expect(dateInput).toHaveAttribute(interactionDisabled);
|
179
|
+
});
|
180
|
+
it('should set interaction type to readonly', async () => {
|
181
|
+
const interactionReadOnly = 'readonly';
|
182
|
+
const _render5 = render( /*#__PURE__*/React.createElement(DateInput2, {
|
183
|
+
renderLabel: "Choose a date",
|
184
|
+
screenReaderLabels: {
|
185
|
+
calendarIcon: 'Calendar',
|
186
|
+
nextMonthButton: 'Next month',
|
187
|
+
prevMonthButton: 'Previous month'
|
188
|
+
},
|
189
|
+
value: "",
|
190
|
+
interaction: interactionReadOnly
|
191
|
+
})),
|
192
|
+
container = _render5.container;
|
193
|
+
const dateInput = container.querySelector('input');
|
194
|
+
const calendarButton = screen.getByRole('button');
|
195
|
+
expect(dateInput).toHaveAttribute(interactionReadOnly);
|
196
|
+
expect(calendarButton).toBeInTheDocument();
|
197
|
+
await userEvent.click(calendarButton);
|
198
|
+
await waitFor(() => {
|
199
|
+
const calendarTable = screen.queryByRole('table');
|
200
|
+
expect(calendarTable).not.toBeInTheDocument();
|
201
|
+
});
|
202
|
+
});
|
203
|
+
it('should set required', async () => {
|
204
|
+
const _render6 = render( /*#__PURE__*/React.createElement(DateInput2, {
|
205
|
+
renderLabel: "Choose a date",
|
206
|
+
screenReaderLabels: {
|
207
|
+
calendarIcon: 'Calendar',
|
208
|
+
nextMonthButton: 'Next month',
|
209
|
+
prevMonthButton: 'Previous month'
|
210
|
+
},
|
211
|
+
value: "",
|
212
|
+
isRequired: true
|
213
|
+
})),
|
214
|
+
container = _render6.container;
|
215
|
+
const dateInput = container.querySelector('input');
|
216
|
+
expect(dateInput).toHaveAttribute('required');
|
217
|
+
});
|
218
|
+
it('should call onBlur', async () => {
|
219
|
+
const onBlur = vi.fn();
|
220
|
+
render( /*#__PURE__*/React.createElement(DateInput2, {
|
221
|
+
renderLabel: "Choose a date",
|
222
|
+
screenReaderLabels: {
|
223
|
+
calendarIcon: 'Calendar',
|
224
|
+
nextMonthButton: 'Next month',
|
225
|
+
prevMonthButton: 'Previous month'
|
226
|
+
},
|
227
|
+
value: "",
|
228
|
+
onBlur: onBlur
|
229
|
+
}));
|
230
|
+
const dateInput = screen.getByLabelText('Choose a date');
|
231
|
+
fireEvent.blur(dateInput);
|
232
|
+
await waitFor(() => {
|
233
|
+
expect(onBlur).toHaveBeenCalled();
|
234
|
+
});
|
235
|
+
});
|
236
|
+
it('should validate if the invalidDateErrorMessage prop is provided', async () => {
|
237
|
+
const errorMsg = 'errorMsg';
|
238
|
+
const Example = () => {
|
239
|
+
const _useState3 = useState(''),
|
240
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
241
|
+
inputValue = _useState4[0],
|
242
|
+
setInputValue = _useState4[1];
|
243
|
+
return /*#__PURE__*/React.createElement(DateInput2, {
|
244
|
+
renderLabel: LABEL_TEXT,
|
245
|
+
screenReaderLabels: {
|
246
|
+
calendarIcon: 'Calendar',
|
247
|
+
nextMonthButton: 'Next month',
|
248
|
+
prevMonthButton: 'Previous month'
|
249
|
+
},
|
250
|
+
value: inputValue,
|
251
|
+
onChange: (_e, inputValue, _dateString) => {
|
252
|
+
setInputValue(inputValue);
|
253
|
+
},
|
254
|
+
invalidDateErrorMessage: errorMsg
|
255
|
+
});
|
256
|
+
};
|
257
|
+
render( /*#__PURE__*/React.createElement(Example, null));
|
258
|
+
expect(screen.queryByText(errorMsg)).not.toBeInTheDocument();
|
259
|
+
const dateInput = screen.getByLabelText(LABEL_TEXT);
|
260
|
+
await userEvent.click(dateInput);
|
261
|
+
await userEvent.type(dateInput, 'Not a date');
|
262
|
+
dateInput.blur();
|
263
|
+
await waitFor(() => {
|
264
|
+
expect(screen.getByText(errorMsg)).toBeInTheDocument();
|
265
|
+
});
|
266
|
+
});
|
267
|
+
it('should show form field messages', async () => {
|
268
|
+
const messages = [{
|
269
|
+
text: 'TypeLess'
|
270
|
+
}, {
|
271
|
+
type: 'error',
|
272
|
+
text: 'Error'
|
273
|
+
}, {
|
274
|
+
type: 'success',
|
275
|
+
text: 'Success'
|
276
|
+
}, {
|
277
|
+
type: 'hint',
|
278
|
+
text: 'Hint'
|
279
|
+
}, {
|
280
|
+
type: 'screenreader-only',
|
281
|
+
text: 'Screenreader'
|
282
|
+
}];
|
283
|
+
render( /*#__PURE__*/React.createElement(DateInput2, {
|
284
|
+
renderLabel: "Choose a date",
|
285
|
+
screenReaderLabels: {
|
286
|
+
calendarIcon: 'Calendar',
|
287
|
+
nextMonthButton: 'Next month',
|
288
|
+
prevMonthButton: 'Previous month'
|
289
|
+
},
|
290
|
+
value: "",
|
291
|
+
messages: messages
|
292
|
+
}));
|
293
|
+
expect(screen.getByText('TypeLess')).toBeVisible();
|
294
|
+
expect(screen.getByText('Error')).toBeVisible();
|
295
|
+
expect(screen.getByText('Success')).toBeVisible();
|
296
|
+
expect(screen.getByText('Hint')).toBeVisible();
|
297
|
+
const screenreaderMessage = screen.getByText('Screenreader');
|
298
|
+
expect(screenreaderMessage).toBeInTheDocument();
|
299
|
+
expect(screenreaderMessage).toHaveClass(/screenReaderContent/);
|
300
|
+
});
|
301
|
+
});
|
@@ -265,7 +265,7 @@ describe('<DateInput />', () => {
|
|
265
265
|
onRequestShowCalendar: onRequestShowCalendar
|
266
266
|
}, generateDays())),
|
267
267
|
container = _render5.container;
|
268
|
-
const dateInput = container.querySelector(
|
268
|
+
const dateInput = container.querySelector('span[class$="-formFieldLayout__label"]');
|
269
269
|
expect(dateInput).toHaveTextContent('Choose date');
|
270
270
|
await _userEvent.default.click(dateInput);
|
271
271
|
await (0, _react2.waitFor)(() => {
|
@@ -0,0 +1,305 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
5
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
6
|
+
var _react = _interopRequireWildcard(require("react"));
|
7
|
+
var _react2 = require("@testing-library/react");
|
8
|
+
var _vitest = require("vitest");
|
9
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
10
|
+
require("@testing-library/jest-dom");
|
11
|
+
var _index = require("../index");
|
12
|
+
var _DateInputExample, _DateInputExample2, _DateInputExample3;
|
13
|
+
/*
|
14
|
+
* The MIT License (MIT)
|
15
|
+
*
|
16
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
17
|
+
*
|
18
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
19
|
+
* of this software and associated documentation files (the "Software"), to deal
|
20
|
+
* in the Software without restriction, including without limitation the rights
|
21
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
22
|
+
* copies of the Software, and to permit persons to whom the Software is
|
23
|
+
* furnished to do so, subject to the following conditions:
|
24
|
+
*
|
25
|
+
* The above copyright notice and this permission notice shall be included in all
|
26
|
+
* copies or substantial portions of the Software.
|
27
|
+
*
|
28
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
29
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
30
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
31
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
32
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
33
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
34
|
+
* SOFTWARE.
|
35
|
+
*/
|
36
|
+
const LABEL_TEXT = 'Choose a date';
|
37
|
+
const DateInputExample = () => {
|
38
|
+
const _useState = (0, _react.useState)(''),
|
39
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
40
|
+
inputValue = _useState2[0],
|
41
|
+
setInputValue = _useState2[1];
|
42
|
+
return /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
43
|
+
renderLabel: LABEL_TEXT,
|
44
|
+
screenReaderLabels: {
|
45
|
+
calendarIcon: 'Calendar',
|
46
|
+
nextMonthButton: 'Next month',
|
47
|
+
prevMonthButton: 'Previous month'
|
48
|
+
},
|
49
|
+
value: inputValue,
|
50
|
+
onChange: (_e, inputValue, _dateString) => {
|
51
|
+
setInputValue(inputValue);
|
52
|
+
}
|
53
|
+
});
|
54
|
+
};
|
55
|
+
describe('<DateInput2 />', () => {
|
56
|
+
let consoleWarningMock;
|
57
|
+
let consoleErrorMock;
|
58
|
+
beforeEach(() => {
|
59
|
+
// Mocking console to prevent test output pollution
|
60
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
61
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
62
|
+
});
|
63
|
+
afterEach(() => {
|
64
|
+
consoleWarningMock.mockRestore();
|
65
|
+
consoleErrorMock.mockRestore();
|
66
|
+
});
|
67
|
+
it('should render an input', async () => {
|
68
|
+
const _render = (0, _react2.render)(_DateInputExample || (_DateInputExample = /*#__PURE__*/_react.default.createElement(DateInputExample, null))),
|
69
|
+
container = _render.container;
|
70
|
+
const dateInput = container.querySelector('input');
|
71
|
+
expect(dateInput).toBeInTheDocument();
|
72
|
+
expect(dateInput).toHaveAttribute('type', 'text');
|
73
|
+
});
|
74
|
+
it('should render an input label', async () => {
|
75
|
+
const _render2 = (0, _react2.render)(_DateInputExample2 || (_DateInputExample2 = /*#__PURE__*/_react.default.createElement(DateInputExample, null))),
|
76
|
+
container = _render2.container;
|
77
|
+
const label = container.querySelector('label');
|
78
|
+
expect(label).toBeInTheDocument();
|
79
|
+
expect(label).toHaveTextContent(LABEL_TEXT);
|
80
|
+
});
|
81
|
+
it('should render an input placeholder', async () => {
|
82
|
+
const placeholder = 'Placeholder';
|
83
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
84
|
+
renderLabel: "Choose a date",
|
85
|
+
screenReaderLabels: {
|
86
|
+
calendarIcon: 'Calendar',
|
87
|
+
nextMonthButton: 'Next month',
|
88
|
+
prevMonthButton: 'Previous month'
|
89
|
+
},
|
90
|
+
placeholder: placeholder,
|
91
|
+
value: ""
|
92
|
+
}));
|
93
|
+
const dateInput = _react2.screen.getByLabelText('Choose a date');
|
94
|
+
expect(dateInput).toHaveAttribute('placeholder', placeholder);
|
95
|
+
});
|
96
|
+
it('should render a calendar icon with screen reader label', async () => {
|
97
|
+
const iconLabel = 'Calendar icon Label';
|
98
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
99
|
+
renderLabel: "Choose a date",
|
100
|
+
screenReaderLabels: {
|
101
|
+
calendarIcon: iconLabel,
|
102
|
+
nextMonthButton: 'Next month',
|
103
|
+
prevMonthButton: 'Previous month'
|
104
|
+
},
|
105
|
+
value: ""
|
106
|
+
})),
|
107
|
+
container = _render3.container;
|
108
|
+
const calendarIcon = container.querySelector('svg[name="IconCalendarMonth"]');
|
109
|
+
const calendarLabel = _react2.screen.getByText(iconLabel);
|
110
|
+
expect(calendarIcon).toBeInTheDocument();
|
111
|
+
expect(calendarLabel).toBeInTheDocument();
|
112
|
+
});
|
113
|
+
it('should not show calendar table by default', async () => {
|
114
|
+
(0, _react2.render)(_DateInputExample3 || (_DateInputExample3 = /*#__PURE__*/_react.default.createElement(DateInputExample, null)));
|
115
|
+
const calendarTable = _react2.screen.queryByRole('table');
|
116
|
+
expect(calendarTable).not.toBeInTheDocument();
|
117
|
+
});
|
118
|
+
it('should render navigation arrow buttons with screen reader labels', async () => {
|
119
|
+
const nextMonthLabel = 'Next month';
|
120
|
+
const prevMonthLabel = 'Previous month';
|
121
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
122
|
+
renderLabel: "Choose a date",
|
123
|
+
screenReaderLabels: {
|
124
|
+
calendarIcon: 'Calendar',
|
125
|
+
nextMonthButton: nextMonthLabel,
|
126
|
+
prevMonthButton: prevMonthLabel
|
127
|
+
},
|
128
|
+
value: ""
|
129
|
+
}));
|
130
|
+
const calendarButton = _react2.screen.getByRole('button');
|
131
|
+
await _userEvent.default.click(calendarButton);
|
132
|
+
await (0, _react2.waitFor)(() => {
|
133
|
+
const prevMonthButton = _react2.screen.getByRole('button', {
|
134
|
+
name: prevMonthLabel
|
135
|
+
});
|
136
|
+
const nextMonthButton = _react2.screen.getByRole('button', {
|
137
|
+
name: nextMonthLabel
|
138
|
+
});
|
139
|
+
expect(prevMonthButton).toBeInTheDocument();
|
140
|
+
expect(nextMonthButton).toBeInTheDocument();
|
141
|
+
const prevButtonLabel = _react2.screen.getByText(prevMonthLabel);
|
142
|
+
const nextButtonLabel = _react2.screen.getByText(nextMonthLabel);
|
143
|
+
expect(prevButtonLabel).toBeInTheDocument();
|
144
|
+
expect(nextButtonLabel).toBeInTheDocument();
|
145
|
+
const prevMonthIcon = prevMonthButton.querySelector('svg[name="IconArrowOpenStart"]');
|
146
|
+
const nextMonthIcon = nextMonthButton.querySelector('svg[name="IconArrowOpenEnd"]');
|
147
|
+
expect(prevMonthIcon).toBeInTheDocument();
|
148
|
+
expect(nextMonthIcon).toBeInTheDocument();
|
149
|
+
});
|
150
|
+
});
|
151
|
+
it('should programmatically set and render the initial value', async () => {
|
152
|
+
const value = '26/03/2024';
|
153
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
154
|
+
renderLabel: "Choose a date",
|
155
|
+
screenReaderLabels: {
|
156
|
+
calendarIcon: 'Calendar',
|
157
|
+
nextMonthButton: 'Next month',
|
158
|
+
prevMonthButton: 'Previous month'
|
159
|
+
},
|
160
|
+
locale: "en-GB",
|
161
|
+
timezone: "UTC",
|
162
|
+
value: value
|
163
|
+
}));
|
164
|
+
const dateInput = _react2.screen.getByLabelText('Choose a date');
|
165
|
+
expect(dateInput).toHaveValue(value);
|
166
|
+
expect(dateInput).toBeInTheDocument();
|
167
|
+
});
|
168
|
+
it('should set interaction type to disabled', async () => {
|
169
|
+
const interactionDisabled = 'disabled';
|
170
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
171
|
+
renderLabel: "Choose a date",
|
172
|
+
screenReaderLabels: {
|
173
|
+
calendarIcon: 'Calendar',
|
174
|
+
nextMonthButton: 'Next month',
|
175
|
+
prevMonthButton: 'Previous month'
|
176
|
+
},
|
177
|
+
value: "",
|
178
|
+
interaction: interactionDisabled
|
179
|
+
})),
|
180
|
+
container = _render4.container;
|
181
|
+
const dateInput = container.querySelector('input');
|
182
|
+
expect(dateInput).toHaveAttribute(interactionDisabled);
|
183
|
+
});
|
184
|
+
it('should set interaction type to readonly', async () => {
|
185
|
+
const interactionReadOnly = 'readonly';
|
186
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
187
|
+
renderLabel: "Choose a date",
|
188
|
+
screenReaderLabels: {
|
189
|
+
calendarIcon: 'Calendar',
|
190
|
+
nextMonthButton: 'Next month',
|
191
|
+
prevMonthButton: 'Previous month'
|
192
|
+
},
|
193
|
+
value: "",
|
194
|
+
interaction: interactionReadOnly
|
195
|
+
})),
|
196
|
+
container = _render5.container;
|
197
|
+
const dateInput = container.querySelector('input');
|
198
|
+
const calendarButton = _react2.screen.getByRole('button');
|
199
|
+
expect(dateInput).toHaveAttribute(interactionReadOnly);
|
200
|
+
expect(calendarButton).toBeInTheDocument();
|
201
|
+
await _userEvent.default.click(calendarButton);
|
202
|
+
await (0, _react2.waitFor)(() => {
|
203
|
+
const calendarTable = _react2.screen.queryByRole('table');
|
204
|
+
expect(calendarTable).not.toBeInTheDocument();
|
205
|
+
});
|
206
|
+
});
|
207
|
+
it('should set required', async () => {
|
208
|
+
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
209
|
+
renderLabel: "Choose a date",
|
210
|
+
screenReaderLabels: {
|
211
|
+
calendarIcon: 'Calendar',
|
212
|
+
nextMonthButton: 'Next month',
|
213
|
+
prevMonthButton: 'Previous month'
|
214
|
+
},
|
215
|
+
value: "",
|
216
|
+
isRequired: true
|
217
|
+
})),
|
218
|
+
container = _render6.container;
|
219
|
+
const dateInput = container.querySelector('input');
|
220
|
+
expect(dateInput).toHaveAttribute('required');
|
221
|
+
});
|
222
|
+
it('should call onBlur', async () => {
|
223
|
+
const onBlur = _vitest.vi.fn();
|
224
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
225
|
+
renderLabel: "Choose a date",
|
226
|
+
screenReaderLabels: {
|
227
|
+
calendarIcon: 'Calendar',
|
228
|
+
nextMonthButton: 'Next month',
|
229
|
+
prevMonthButton: 'Previous month'
|
230
|
+
},
|
231
|
+
value: "",
|
232
|
+
onBlur: onBlur
|
233
|
+
}));
|
234
|
+
const dateInput = _react2.screen.getByLabelText('Choose a date');
|
235
|
+
_react2.fireEvent.blur(dateInput);
|
236
|
+
await (0, _react2.waitFor)(() => {
|
237
|
+
expect(onBlur).toHaveBeenCalled();
|
238
|
+
});
|
239
|
+
});
|
240
|
+
it('should validate if the invalidDateErrorMessage prop is provided', async () => {
|
241
|
+
const errorMsg = 'errorMsg';
|
242
|
+
const Example = () => {
|
243
|
+
const _useState3 = (0, _react.useState)(''),
|
244
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
245
|
+
inputValue = _useState4[0],
|
246
|
+
setInputValue = _useState4[1];
|
247
|
+
return /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
248
|
+
renderLabel: LABEL_TEXT,
|
249
|
+
screenReaderLabels: {
|
250
|
+
calendarIcon: 'Calendar',
|
251
|
+
nextMonthButton: 'Next month',
|
252
|
+
prevMonthButton: 'Previous month'
|
253
|
+
},
|
254
|
+
value: inputValue,
|
255
|
+
onChange: (_e, inputValue, _dateString) => {
|
256
|
+
setInputValue(inputValue);
|
257
|
+
},
|
258
|
+
invalidDateErrorMessage: errorMsg
|
259
|
+
});
|
260
|
+
};
|
261
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(Example, null));
|
262
|
+
expect(_react2.screen.queryByText(errorMsg)).not.toBeInTheDocument();
|
263
|
+
const dateInput = _react2.screen.getByLabelText(LABEL_TEXT);
|
264
|
+
await _userEvent.default.click(dateInput);
|
265
|
+
await _userEvent.default.type(dateInput, 'Not a date');
|
266
|
+
dateInput.blur();
|
267
|
+
await (0, _react2.waitFor)(() => {
|
268
|
+
expect(_react2.screen.getByText(errorMsg)).toBeInTheDocument();
|
269
|
+
});
|
270
|
+
});
|
271
|
+
it('should show form field messages', async () => {
|
272
|
+
const messages = [{
|
273
|
+
text: 'TypeLess'
|
274
|
+
}, {
|
275
|
+
type: 'error',
|
276
|
+
text: 'Error'
|
277
|
+
}, {
|
278
|
+
type: 'success',
|
279
|
+
text: 'Success'
|
280
|
+
}, {
|
281
|
+
type: 'hint',
|
282
|
+
text: 'Hint'
|
283
|
+
}, {
|
284
|
+
type: 'screenreader-only',
|
285
|
+
text: 'Screenreader'
|
286
|
+
}];
|
287
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
|
288
|
+
renderLabel: "Choose a date",
|
289
|
+
screenReaderLabels: {
|
290
|
+
calendarIcon: 'Calendar',
|
291
|
+
nextMonthButton: 'Next month',
|
292
|
+
prevMonthButton: 'Previous month'
|
293
|
+
},
|
294
|
+
value: "",
|
295
|
+
messages: messages
|
296
|
+
}));
|
297
|
+
expect(_react2.screen.getByText('TypeLess')).toBeVisible();
|
298
|
+
expect(_react2.screen.getByText('Error')).toBeVisible();
|
299
|
+
expect(_react2.screen.getByText('Success')).toBeVisible();
|
300
|
+
expect(_react2.screen.getByText('Hint')).toBeVisible();
|
301
|
+
const screenreaderMessage = _react2.screen.getByText('Screenreader');
|
302
|
+
expect(screenreaderMessage).toBeInTheDocument();
|
303
|
+
expect(screenreaderMessage).toHaveClass(/screenReaderContent/);
|
304
|
+
});
|
305
|
+
});
|