@instructure/ui-date-input 10.4.2-snapshot-10 → 10.4.2-snapshot-13

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 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.4.2-snapshot-10](https://github.com/instructure/instructure-ui/compare/v10.4.1...v10.4.2-snapshot-10) (2024-11-06)
6
+ ## [10.4.2-snapshot-13](https://github.com/instructure/instructure-ui/compare/v10.4.1...v10.4.2-snapshot-13) (2024-11-07)
7
7
 
8
8
 
9
9
  ### Bug Fixes
@@ -11,6 +11,11 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
  * **ui-date-input:** fix DateInput2 to update messages properly ([553a235](https://github.com/instructure/instructure-ui/commit/553a2351fc7f8c6d012d4001ff49c2450d29ee97))
12
12
 
13
13
 
14
+ ### Features
15
+
16
+ * **many:** add new form field error msg style + add asterisk for required fields ([9b03683](https://github.com/instructure/instructure-ui/commit/9b03683dadeef4c5deae2c60bea10686f143ff5d))
17
+
18
+
14
19
 
15
20
 
16
21
 
@@ -188,7 +188,7 @@ describe('<DateInput />', () => {
188
188
  renderWeekdayLabels: weekdayLabels,
189
189
  isRequired: true
190
190
  }, generateDays()));
191
- const dateInput = screen.getByLabelText('Choose date');
191
+ const dateInput = screen.getByLabelText('Choose date *');
192
192
  expect(dateInput).toHaveAttribute('required');
193
193
  });
194
194
  it('should provide inputRef', () => {
@@ -0,0 +1,313 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ var _DateInputExample, _DateInputExample2, _DateInputExample3, _DateInputExample4;
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 dateInput = container.querySelector('input');
74
+ const label = container.querySelector('label');
75
+ expect(label).toBeInTheDocument();
76
+ expect(label).toHaveTextContent(LABEL_TEXT);
77
+ expect(dateInput === null || dateInput === void 0 ? void 0 : dateInput.id).toBe(label === null || label === void 0 ? void 0 : label.htmlFor);
78
+ });
79
+ it('should render an input placeholder', async () => {
80
+ const placeholder = 'Placeholder';
81
+ render(/*#__PURE__*/React.createElement(DateInput2, {
82
+ renderLabel: "Choose a date",
83
+ screenReaderLabels: {
84
+ calendarIcon: 'Calendar',
85
+ nextMonthButton: 'Next month',
86
+ prevMonthButton: 'Previous month'
87
+ },
88
+ placeholder: placeholder,
89
+ value: ""
90
+ }));
91
+ const dateInput = screen.getByLabelText('Choose a date');
92
+ expect(dateInput).toHaveAttribute('placeholder', placeholder);
93
+ });
94
+ it('should render a calendar icon with screen reader label', async () => {
95
+ const iconLabel = 'Calendar icon Label';
96
+ const _render3 = render(/*#__PURE__*/React.createElement(DateInput2, {
97
+ renderLabel: "Choose a date",
98
+ screenReaderLabels: {
99
+ calendarIcon: iconLabel,
100
+ nextMonthButton: 'Next month',
101
+ prevMonthButton: 'Previous month'
102
+ },
103
+ value: ""
104
+ })),
105
+ container = _render3.container;
106
+ const calendarIcon = container.querySelector('svg[name="IconCalendarMonth"]');
107
+ const calendarLabel = screen.getByText(iconLabel);
108
+ expect(calendarIcon).toBeInTheDocument();
109
+ expect(calendarLabel).toBeInTheDocument();
110
+ });
111
+ it('should not show calendar table by default', async () => {
112
+ render(_DateInputExample3 || (_DateInputExample3 = /*#__PURE__*/React.createElement(DateInputExample, null)));
113
+ const calendarTable = screen.queryByRole('listbox');
114
+ expect(calendarTable).not.toBeInTheDocument();
115
+ });
116
+ it('should show calendar table when calendar button is clicked', async () => {
117
+ render(_DateInputExample4 || (_DateInputExample4 = /*#__PURE__*/React.createElement(DateInputExample, null)));
118
+ const calendarButton = screen.getByRole('button');
119
+ expect(calendarButton).toBeInTheDocument();
120
+ await userEvent.click(calendarButton);
121
+ await waitFor(() => {
122
+ const calendarTable = screen.queryByRole('listbox');
123
+ expect(calendarTable).toBeInTheDocument();
124
+ });
125
+ });
126
+ it('should render navigation arrow buttons with screen reader labels', async () => {
127
+ const nextMonthLabel = 'Next month';
128
+ const prevMonthLabel = 'Previous month';
129
+ render(/*#__PURE__*/React.createElement(DateInput2, {
130
+ renderLabel: "Choose a date",
131
+ screenReaderLabels: {
132
+ calendarIcon: 'Calendar',
133
+ nextMonthButton: nextMonthLabel,
134
+ prevMonthButton: prevMonthLabel
135
+ },
136
+ value: ""
137
+ }));
138
+ const calendarButton = screen.getByRole('button');
139
+ await userEvent.click(calendarButton);
140
+ await waitFor(() => {
141
+ const prevMonthButton = screen.getByRole('button', {
142
+ name: prevMonthLabel
143
+ });
144
+ const nextMonthButton = screen.getByRole('button', {
145
+ name: nextMonthLabel
146
+ });
147
+ expect(prevMonthButton).toBeInTheDocument();
148
+ expect(nextMonthButton).toBeInTheDocument();
149
+ const prevButtonLabel = screen.getByText(prevMonthLabel);
150
+ const nextButtonLabel = screen.getByText(nextMonthLabel);
151
+ expect(prevButtonLabel).toBeInTheDocument();
152
+ expect(nextButtonLabel).toBeInTheDocument();
153
+ const prevMonthIcon = prevMonthButton.querySelector('svg[name="IconArrowOpenStart"]');
154
+ const nextMonthIcon = nextMonthButton.querySelector('svg[name="IconArrowOpenEnd"]');
155
+ expect(prevMonthIcon).toBeInTheDocument();
156
+ expect(nextMonthIcon).toBeInTheDocument();
157
+ });
158
+ });
159
+ it('should programmatically set and render the initial value', async () => {
160
+ const value = '26/03/2024';
161
+ render(/*#__PURE__*/React.createElement(DateInput2, {
162
+ renderLabel: "Choose a date",
163
+ screenReaderLabels: {
164
+ calendarIcon: 'Calendar',
165
+ nextMonthButton: 'Next month',
166
+ prevMonthButton: 'Previous month'
167
+ },
168
+ locale: "en-GB",
169
+ timezone: "UTC",
170
+ value: value
171
+ }));
172
+ const dateInput = screen.getByLabelText('Choose a date');
173
+ expect(dateInput).toHaveValue(value);
174
+ expect(dateInput).toBeInTheDocument();
175
+ });
176
+ it('should set interaction type to disabled', async () => {
177
+ const interactionDisabled = 'disabled';
178
+ const _render4 = render(/*#__PURE__*/React.createElement(DateInput2, {
179
+ renderLabel: "Choose a date",
180
+ screenReaderLabels: {
181
+ calendarIcon: 'Calendar',
182
+ nextMonthButton: 'Next month',
183
+ prevMonthButton: 'Previous month'
184
+ },
185
+ value: "",
186
+ interaction: interactionDisabled
187
+ })),
188
+ container = _render4.container;
189
+ const dateInput = container.querySelector('input');
190
+ expect(dateInput).toHaveAttribute(interactionDisabled);
191
+ });
192
+ it('should set interaction type to readonly', async () => {
193
+ const interactionReadOnly = 'readonly';
194
+ const _render5 = render(/*#__PURE__*/React.createElement(DateInput2, {
195
+ renderLabel: "Choose a date",
196
+ screenReaderLabels: {
197
+ calendarIcon: 'Calendar',
198
+ nextMonthButton: 'Next month',
199
+ prevMonthButton: 'Previous month'
200
+ },
201
+ value: "",
202
+ interaction: interactionReadOnly
203
+ })),
204
+ container = _render5.container;
205
+ const dateInput = container.querySelector('input');
206
+ const calendarButton = screen.getByRole('button');
207
+ expect(dateInput).toHaveAttribute(interactionReadOnly);
208
+ expect(calendarButton).toBeInTheDocument();
209
+ await userEvent.click(calendarButton);
210
+ await waitFor(() => {
211
+ const calendarTable = screen.queryByRole('listbox');
212
+ expect(calendarTable).not.toBeInTheDocument();
213
+ });
214
+ });
215
+ it('should set required', async () => {
216
+ const _render6 = render(/*#__PURE__*/React.createElement(DateInput2, {
217
+ renderLabel: "Choose a date",
218
+ screenReaderLabels: {
219
+ calendarIcon: 'Calendar',
220
+ nextMonthButton: 'Next month',
221
+ prevMonthButton: 'Previous month'
222
+ },
223
+ value: "",
224
+ isRequired: true
225
+ })),
226
+ container = _render6.container;
227
+ const dateInput = container.querySelector('input');
228
+ expect(dateInput).toHaveAttribute('required');
229
+ });
230
+ it('should call onBlur', async () => {
231
+ const onBlur = vi.fn();
232
+ render(/*#__PURE__*/React.createElement(DateInput2, {
233
+ renderLabel: "Choose a date",
234
+ screenReaderLabels: {
235
+ calendarIcon: 'Calendar',
236
+ nextMonthButton: 'Next month',
237
+ prevMonthButton: 'Previous month'
238
+ },
239
+ value: "",
240
+ onBlur: onBlur
241
+ }));
242
+ const dateInput = screen.getByLabelText('Choose a date');
243
+ fireEvent.blur(dateInput);
244
+ await waitFor(() => {
245
+ expect(onBlur).toHaveBeenCalled();
246
+ });
247
+ });
248
+ it('should validate if the invalidDateErrorMessage prop is provided', async () => {
249
+ const errorMsg = 'errorMsg';
250
+ const Example = () => {
251
+ const _useState3 = useState(''),
252
+ _useState4 = _slicedToArray(_useState3, 2),
253
+ inputValue = _useState4[0],
254
+ setInputValue = _useState4[1];
255
+ return /*#__PURE__*/React.createElement(DateInput2, {
256
+ renderLabel: LABEL_TEXT,
257
+ screenReaderLabels: {
258
+ calendarIcon: 'Calendar',
259
+ nextMonthButton: 'Next month',
260
+ prevMonthButton: 'Previous month'
261
+ },
262
+ value: inputValue,
263
+ onChange: (_e, inputValue, _dateString) => {
264
+ setInputValue(inputValue);
265
+ },
266
+ invalidDateErrorMessage: errorMsg
267
+ });
268
+ };
269
+ render(/*#__PURE__*/React.createElement(Example, null));
270
+ expect(screen.queryByText(errorMsg)).not.toBeInTheDocument();
271
+ const dateInput = screen.getByLabelText(LABEL_TEXT);
272
+ await userEvent.click(dateInput);
273
+ await userEvent.type(dateInput, 'Not a date');
274
+ dateInput.blur();
275
+ await waitFor(() => {
276
+ expect(screen.getByText(errorMsg)).toBeInTheDocument();
277
+ });
278
+ });
279
+ it('should show form field messages', async () => {
280
+ const messages = [{
281
+ text: 'TypeLess'
282
+ }, {
283
+ type: 'error',
284
+ text: 'Error'
285
+ }, {
286
+ type: 'success',
287
+ text: 'Success'
288
+ }, {
289
+ type: 'hint',
290
+ text: 'Hint'
291
+ }, {
292
+ type: 'screenreader-only',
293
+ text: 'Screenreader'
294
+ }];
295
+ render(/*#__PURE__*/React.createElement(DateInput2, {
296
+ renderLabel: "Choose a date",
297
+ screenReaderLabels: {
298
+ calendarIcon: 'Calendar',
299
+ nextMonthButton: 'Next month',
300
+ prevMonthButton: 'Previous month'
301
+ },
302
+ value: "",
303
+ messages: messages
304
+ }));
305
+ expect(screen.getByText('TypeLess')).toBeVisible();
306
+ expect(screen.getByText('Error')).toBeVisible();
307
+ expect(screen.getByText('Success')).toBeVisible();
308
+ expect(screen.getByText('Hint')).toBeVisible();
309
+ const screenreaderMessage = screen.getByText('Screenreader');
310
+ expect(screenreaderMessage).toBeInTheDocument();
311
+ expect(screenreaderMessage).toHaveClass(/screenReaderContent/);
312
+ });
313
+ });
@@ -190,7 +190,7 @@ describe('<DateInput />', () => {
190
190
  renderWeekdayLabels: weekdayLabels,
191
191
  isRequired: true
192
192
  }, generateDays()));
193
- const dateInput = _react2.screen.getByLabelText('Choose date');
193
+ const dateInput = _react2.screen.getByLabelText('Choose date *');
194
194
  expect(dateInput).toHaveAttribute('required');
195
195
  });
196
196
  it('should provide inputRef', () => {
@@ -0,0 +1,317 @@
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, _DateInputExample4;
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 dateInput = container.querySelector('input');
78
+ const label = container.querySelector('label');
79
+ expect(label).toBeInTheDocument();
80
+ expect(label).toHaveTextContent(LABEL_TEXT);
81
+ expect(dateInput === null || dateInput === void 0 ? void 0 : dateInput.id).toBe(label === null || label === void 0 ? void 0 : label.htmlFor);
82
+ });
83
+ it('should render an input placeholder', async () => {
84
+ const placeholder = 'Placeholder';
85
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
86
+ renderLabel: "Choose a date",
87
+ screenReaderLabels: {
88
+ calendarIcon: 'Calendar',
89
+ nextMonthButton: 'Next month',
90
+ prevMonthButton: 'Previous month'
91
+ },
92
+ placeholder: placeholder,
93
+ value: ""
94
+ }));
95
+ const dateInput = _react2.screen.getByLabelText('Choose a date');
96
+ expect(dateInput).toHaveAttribute('placeholder', placeholder);
97
+ });
98
+ it('should render a calendar icon with screen reader label', async () => {
99
+ const iconLabel = 'Calendar icon Label';
100
+ const _render3 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
101
+ renderLabel: "Choose a date",
102
+ screenReaderLabels: {
103
+ calendarIcon: iconLabel,
104
+ nextMonthButton: 'Next month',
105
+ prevMonthButton: 'Previous month'
106
+ },
107
+ value: ""
108
+ })),
109
+ container = _render3.container;
110
+ const calendarIcon = container.querySelector('svg[name="IconCalendarMonth"]');
111
+ const calendarLabel = _react2.screen.getByText(iconLabel);
112
+ expect(calendarIcon).toBeInTheDocument();
113
+ expect(calendarLabel).toBeInTheDocument();
114
+ });
115
+ it('should not show calendar table by default', async () => {
116
+ (0, _react2.render)(_DateInputExample3 || (_DateInputExample3 = /*#__PURE__*/_react.default.createElement(DateInputExample, null)));
117
+ const calendarTable = _react2.screen.queryByRole('listbox');
118
+ expect(calendarTable).not.toBeInTheDocument();
119
+ });
120
+ it('should show calendar table when calendar button is clicked', async () => {
121
+ (0, _react2.render)(_DateInputExample4 || (_DateInputExample4 = /*#__PURE__*/_react.default.createElement(DateInputExample, null)));
122
+ const calendarButton = _react2.screen.getByRole('button');
123
+ expect(calendarButton).toBeInTheDocument();
124
+ await _userEvent.default.click(calendarButton);
125
+ await (0, _react2.waitFor)(() => {
126
+ const calendarTable = _react2.screen.queryByRole('listbox');
127
+ expect(calendarTable).toBeInTheDocument();
128
+ });
129
+ });
130
+ it('should render navigation arrow buttons with screen reader labels', async () => {
131
+ const nextMonthLabel = 'Next month';
132
+ const prevMonthLabel = 'Previous month';
133
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
134
+ renderLabel: "Choose a date",
135
+ screenReaderLabels: {
136
+ calendarIcon: 'Calendar',
137
+ nextMonthButton: nextMonthLabel,
138
+ prevMonthButton: prevMonthLabel
139
+ },
140
+ value: ""
141
+ }));
142
+ const calendarButton = _react2.screen.getByRole('button');
143
+ await _userEvent.default.click(calendarButton);
144
+ await (0, _react2.waitFor)(() => {
145
+ const prevMonthButton = _react2.screen.getByRole('button', {
146
+ name: prevMonthLabel
147
+ });
148
+ const nextMonthButton = _react2.screen.getByRole('button', {
149
+ name: nextMonthLabel
150
+ });
151
+ expect(prevMonthButton).toBeInTheDocument();
152
+ expect(nextMonthButton).toBeInTheDocument();
153
+ const prevButtonLabel = _react2.screen.getByText(prevMonthLabel);
154
+ const nextButtonLabel = _react2.screen.getByText(nextMonthLabel);
155
+ expect(prevButtonLabel).toBeInTheDocument();
156
+ expect(nextButtonLabel).toBeInTheDocument();
157
+ const prevMonthIcon = prevMonthButton.querySelector('svg[name="IconArrowOpenStart"]');
158
+ const nextMonthIcon = nextMonthButton.querySelector('svg[name="IconArrowOpenEnd"]');
159
+ expect(prevMonthIcon).toBeInTheDocument();
160
+ expect(nextMonthIcon).toBeInTheDocument();
161
+ });
162
+ });
163
+ it('should programmatically set and render the initial value', async () => {
164
+ const value = '26/03/2024';
165
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
166
+ renderLabel: "Choose a date",
167
+ screenReaderLabels: {
168
+ calendarIcon: 'Calendar',
169
+ nextMonthButton: 'Next month',
170
+ prevMonthButton: 'Previous month'
171
+ },
172
+ locale: "en-GB",
173
+ timezone: "UTC",
174
+ value: value
175
+ }));
176
+ const dateInput = _react2.screen.getByLabelText('Choose a date');
177
+ expect(dateInput).toHaveValue(value);
178
+ expect(dateInput).toBeInTheDocument();
179
+ });
180
+ it('should set interaction type to disabled', async () => {
181
+ const interactionDisabled = 'disabled';
182
+ const _render4 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
183
+ renderLabel: "Choose a date",
184
+ screenReaderLabels: {
185
+ calendarIcon: 'Calendar',
186
+ nextMonthButton: 'Next month',
187
+ prevMonthButton: 'Previous month'
188
+ },
189
+ value: "",
190
+ interaction: interactionDisabled
191
+ })),
192
+ container = _render4.container;
193
+ const dateInput = container.querySelector('input');
194
+ expect(dateInput).toHaveAttribute(interactionDisabled);
195
+ });
196
+ it('should set interaction type to readonly', async () => {
197
+ const interactionReadOnly = 'readonly';
198
+ const _render5 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
199
+ renderLabel: "Choose a date",
200
+ screenReaderLabels: {
201
+ calendarIcon: 'Calendar',
202
+ nextMonthButton: 'Next month',
203
+ prevMonthButton: 'Previous month'
204
+ },
205
+ value: "",
206
+ interaction: interactionReadOnly
207
+ })),
208
+ container = _render5.container;
209
+ const dateInput = container.querySelector('input');
210
+ const calendarButton = _react2.screen.getByRole('button');
211
+ expect(dateInput).toHaveAttribute(interactionReadOnly);
212
+ expect(calendarButton).toBeInTheDocument();
213
+ await _userEvent.default.click(calendarButton);
214
+ await (0, _react2.waitFor)(() => {
215
+ const calendarTable = _react2.screen.queryByRole('listbox');
216
+ expect(calendarTable).not.toBeInTheDocument();
217
+ });
218
+ });
219
+ it('should set required', async () => {
220
+ const _render6 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
221
+ renderLabel: "Choose a date",
222
+ screenReaderLabels: {
223
+ calendarIcon: 'Calendar',
224
+ nextMonthButton: 'Next month',
225
+ prevMonthButton: 'Previous month'
226
+ },
227
+ value: "",
228
+ isRequired: true
229
+ })),
230
+ container = _render6.container;
231
+ const dateInput = container.querySelector('input');
232
+ expect(dateInput).toHaveAttribute('required');
233
+ });
234
+ it('should call onBlur', async () => {
235
+ const onBlur = _vitest.vi.fn();
236
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
237
+ renderLabel: "Choose a date",
238
+ screenReaderLabels: {
239
+ calendarIcon: 'Calendar',
240
+ nextMonthButton: 'Next month',
241
+ prevMonthButton: 'Previous month'
242
+ },
243
+ value: "",
244
+ onBlur: onBlur
245
+ }));
246
+ const dateInput = _react2.screen.getByLabelText('Choose a date');
247
+ _react2.fireEvent.blur(dateInput);
248
+ await (0, _react2.waitFor)(() => {
249
+ expect(onBlur).toHaveBeenCalled();
250
+ });
251
+ });
252
+ it('should validate if the invalidDateErrorMessage prop is provided', async () => {
253
+ const errorMsg = 'errorMsg';
254
+ const Example = () => {
255
+ const _useState3 = (0, _react.useState)(''),
256
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
257
+ inputValue = _useState4[0],
258
+ setInputValue = _useState4[1];
259
+ return /*#__PURE__*/_react.default.createElement(_index.DateInput2, {
260
+ renderLabel: LABEL_TEXT,
261
+ screenReaderLabels: {
262
+ calendarIcon: 'Calendar',
263
+ nextMonthButton: 'Next month',
264
+ prevMonthButton: 'Previous month'
265
+ },
266
+ value: inputValue,
267
+ onChange: (_e, inputValue, _dateString) => {
268
+ setInputValue(inputValue);
269
+ },
270
+ invalidDateErrorMessage: errorMsg
271
+ });
272
+ };
273
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(Example, null));
274
+ expect(_react2.screen.queryByText(errorMsg)).not.toBeInTheDocument();
275
+ const dateInput = _react2.screen.getByLabelText(LABEL_TEXT);
276
+ await _userEvent.default.click(dateInput);
277
+ await _userEvent.default.type(dateInput, 'Not a date');
278
+ dateInput.blur();
279
+ await (0, _react2.waitFor)(() => {
280
+ expect(_react2.screen.getByText(errorMsg)).toBeInTheDocument();
281
+ });
282
+ });
283
+ it('should show form field messages', async () => {
284
+ const messages = [{
285
+ text: 'TypeLess'
286
+ }, {
287
+ type: 'error',
288
+ text: 'Error'
289
+ }, {
290
+ type: 'success',
291
+ text: 'Success'
292
+ }, {
293
+ type: 'hint',
294
+ text: 'Hint'
295
+ }, {
296
+ type: 'screenreader-only',
297
+ text: 'Screenreader'
298
+ }];
299
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.DateInput2, {
300
+ renderLabel: "Choose a date",
301
+ screenReaderLabels: {
302
+ calendarIcon: 'Calendar',
303
+ nextMonthButton: 'Next month',
304
+ prevMonthButton: 'Previous month'
305
+ },
306
+ value: "",
307
+ messages: messages
308
+ }));
309
+ expect(_react2.screen.getByText('TypeLess')).toBeVisible();
310
+ expect(_react2.screen.getByText('Error')).toBeVisible();
311
+ expect(_react2.screen.getByText('Success')).toBeVisible();
312
+ expect(_react2.screen.getByText('Hint')).toBeVisible();
313
+ const screenreaderMessage = _react2.screen.getByText('Screenreader');
314
+ expect(screenreaderMessage).toBeInTheDocument();
315
+ expect(screenreaderMessage).toHaveClass(/screenReaderContent/);
316
+ });
317
+ });