@instructure/ui-date-input 10.19.2-snapshot-3 → 10.19.2-snapshot-4

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