@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,353 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- var _DateInputExample, _DateInputExample2, _IconHeartLine, _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 { 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 { IconHeartLine } from '@instructure/ui-icons';
32
- import { DateInput2 } from '../index';
33
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
34
- const LABEL_TEXT = 'Choose a date';
35
- const DateInputExample = () => {
36
- const _useState = useState(''),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- inputValue = _useState2[0],
39
- setInputValue = _useState2[1];
40
- return _jsx(DateInput2, {
41
- renderLabel: LABEL_TEXT,
42
- screenReaderLabels: {
43
- calendarIcon: 'Calendar',
44
- nextMonthButton: 'Next month',
45
- prevMonthButton: 'Previous month'
46
- },
47
- value: inputValue,
48
- onChange: (_e, inputValue, _dateString) => {
49
- setInputValue(inputValue);
50
- }
51
- });
52
- };
53
- describe('<DateInput2 />', () => {
54
- let consoleWarningMock;
55
- let consoleErrorMock;
56
- beforeEach(() => {
57
- // Mocking console to prevent test output pollution
58
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
59
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
60
- });
61
- afterEach(() => {
62
- consoleWarningMock.mockRestore();
63
- consoleErrorMock.mockRestore();
64
- });
65
- it('should render an input', async () => {
66
- const _render = render(_DateInputExample || (_DateInputExample = _jsx(DateInputExample, {}))),
67
- container = _render.container;
68
- const dateInput = container.querySelector('input');
69
- expect(dateInput).toBeInTheDocument();
70
- expect(dateInput).toHaveAttribute('type', 'text');
71
- });
72
- it('should render an input label', async () => {
73
- const _render2 = render(_DateInputExample2 || (_DateInputExample2 = _jsx(DateInputExample, {}))),
74
- container = _render2.container;
75
- const label = container.querySelector('label');
76
- expect(label).toBeInTheDocument();
77
- expect(label).toHaveTextContent(LABEL_TEXT);
78
- });
79
- it('should render an input placeholder', async () => {
80
- const placeholder = 'Placeholder';
81
- render(_jsx(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(_jsx(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('refs should return the underlying component', async () => {
112
- const inputRef = vi.fn();
113
- const ref = {
114
- current: null
115
- };
116
- const _render4 = render(_jsx(DateInput2, {
117
- id: "dateInput2",
118
- inputRef: inputRef,
119
- ref: ref,
120
- renderLabel: LABEL_TEXT,
121
- screenReaderLabels: {
122
- calendarIcon: 'Calendar',
123
- nextMonthButton: 'Next month',
124
- prevMonthButton: 'Previous month'
125
- }
126
- })),
127
- container = _render4.container;
128
- const dateInput = container.querySelector('input');
129
- expect(inputRef).toHaveBeenCalledWith(dateInput);
130
- expect(ref.current.props.id).toBe('dateInput2');
131
- expect(dateInput).toBeInTheDocument();
132
- });
133
- it('should render a custom calendar icon with screen reader label', async () => {
134
- const iconLabel = 'Calendar icon Label';
135
- const _render5 = render(_jsx(DateInput2, {
136
- renderLabel: "Choose a date",
137
- screenReaderLabels: {
138
- calendarIcon: iconLabel,
139
- nextMonthButton: 'Next month',
140
- prevMonthButton: 'Previous month'
141
- },
142
- value: "",
143
- renderCalendarIcon: _IconHeartLine || (_IconHeartLine = _jsx(IconHeartLine, {}))
144
- })),
145
- container = _render5.container;
146
- const calendarIcon = container.querySelector('svg[name="IconHeart"]');
147
- const calendarLabel = screen.getByText(iconLabel);
148
- expect(calendarIcon).toBeInTheDocument();
149
- expect(calendarLabel).toBeInTheDocument();
150
- });
151
- it('should not show calendar table by default', async () => {
152
- render(_DateInputExample3 || (_DateInputExample3 = _jsx(DateInputExample, {})));
153
- const calendarTable = screen.queryByRole('table');
154
- expect(calendarTable).not.toBeInTheDocument();
155
- });
156
- it('should show calendar table when calendar button is clicked', async () => {
157
- render(_DateInputExample4 || (_DateInputExample4 = _jsx(DateInputExample, {})));
158
- const calendarButton = screen.getByRole('button');
159
- expect(calendarButton).toBeInTheDocument();
160
- await userEvent.click(calendarButton);
161
- await waitFor(() => {
162
- const calendarTable = screen.queryByRole('table');
163
- expect(calendarTable).toBeInTheDocument();
164
- });
165
- });
166
- it('should render navigation arrow buttons with screen reader labels', async () => {
167
- const nextMonthLabel = 'Next month';
168
- const prevMonthLabel = 'Previous month';
169
- render(_jsx(DateInput2, {
170
- renderLabel: "Choose a date",
171
- screenReaderLabels: {
172
- calendarIcon: 'Calendar',
173
- nextMonthButton: nextMonthLabel,
174
- prevMonthButton: prevMonthLabel
175
- },
176
- value: ""
177
- }));
178
- const calendarButton = screen.getByRole('button');
179
- await userEvent.click(calendarButton);
180
- await waitFor(() => {
181
- const prevMonthButton = screen.getByRole('button', {
182
- name: prevMonthLabel
183
- });
184
- const nextMonthButton = screen.getByRole('button', {
185
- name: nextMonthLabel
186
- });
187
- expect(prevMonthButton).toBeInTheDocument();
188
- expect(nextMonthButton).toBeInTheDocument();
189
- const prevButtonLabel = screen.getByText(prevMonthLabel);
190
- const nextButtonLabel = screen.getByText(nextMonthLabel);
191
- expect(prevButtonLabel).toBeInTheDocument();
192
- expect(nextButtonLabel).toBeInTheDocument();
193
- const prevMonthIcon = prevMonthButton.querySelector('svg[name="IconArrowOpenStart"]');
194
- const nextMonthIcon = nextMonthButton.querySelector('svg[name="IconArrowOpenEnd"]');
195
- expect(prevMonthIcon).toBeInTheDocument();
196
- expect(nextMonthIcon).toBeInTheDocument();
197
- });
198
- });
199
- it('should programmatically set and render the initial value', async () => {
200
- const value = '26/03/2024';
201
- render(_jsx(DateInput2, {
202
- renderLabel: "Choose a date",
203
- screenReaderLabels: {
204
- calendarIcon: 'Calendar',
205
- nextMonthButton: 'Next month',
206
- prevMonthButton: 'Previous month'
207
- },
208
- locale: "en-GB",
209
- timezone: "UTC",
210
- value: value
211
- }));
212
- const dateInput = screen.getByLabelText('Choose a date');
213
- expect(dateInput).toHaveValue(value);
214
- expect(dateInput).toBeInTheDocument();
215
- });
216
- it('should set interaction type to disabled', async () => {
217
- const interactionDisabled = 'disabled';
218
- const _render6 = render(_jsx(DateInput2, {
219
- renderLabel: "Choose a date",
220
- screenReaderLabels: {
221
- calendarIcon: 'Calendar',
222
- nextMonthButton: 'Next month',
223
- prevMonthButton: 'Previous month'
224
- },
225
- value: "",
226
- interaction: interactionDisabled
227
- })),
228
- container = _render6.container;
229
- const dateInput = container.querySelector('input');
230
- expect(dateInput).toHaveAttribute(interactionDisabled);
231
- });
232
- it('should set interaction type to readonly', async () => {
233
- const interactionReadOnly = 'readonly';
234
- const _render7 = render(_jsx(DateInput2, {
235
- renderLabel: "Choose a date",
236
- screenReaderLabels: {
237
- calendarIcon: 'Calendar',
238
- nextMonthButton: 'Next month',
239
- prevMonthButton: 'Previous month'
240
- },
241
- value: "",
242
- interaction: interactionReadOnly
243
- })),
244
- container = _render7.container;
245
- const dateInput = container.querySelector('input');
246
- const calendarButton = screen.getByRole('button');
247
- expect(dateInput).toHaveAttribute(interactionReadOnly);
248
- expect(calendarButton).toBeInTheDocument();
249
- await userEvent.click(calendarButton);
250
- await waitFor(() => {
251
- const calendarTable = screen.queryByRole('table');
252
- expect(calendarTable).not.toBeInTheDocument();
253
- });
254
- });
255
- it('should set required', async () => {
256
- const _render8 = render(_jsx(DateInput2, {
257
- renderLabel: "Choose a date",
258
- screenReaderLabels: {
259
- calendarIcon: 'Calendar',
260
- nextMonthButton: 'Next month',
261
- prevMonthButton: 'Previous month'
262
- },
263
- value: "",
264
- isRequired: true
265
- })),
266
- container = _render8.container;
267
- const dateInput = container.querySelector('input');
268
- expect(dateInput).toHaveAttribute('required');
269
- });
270
- it('should call onBlur', async () => {
271
- const onBlur = vi.fn();
272
- render(_jsx(DateInput2, {
273
- renderLabel: "Choose a date",
274
- screenReaderLabels: {
275
- calendarIcon: 'Calendar',
276
- nextMonthButton: 'Next month',
277
- prevMonthButton: 'Previous month'
278
- },
279
- value: "",
280
- onBlur: onBlur
281
- }));
282
- const dateInput = screen.getByLabelText('Choose a date');
283
- fireEvent.blur(dateInput);
284
- await waitFor(() => {
285
- expect(onBlur).toHaveBeenCalled();
286
- });
287
- });
288
- it('should validate if the invalidDateErrorMessage prop is provided', async () => {
289
- const errorMsg = 'errorMsg';
290
- const Example = () => {
291
- const _useState3 = useState(''),
292
- _useState4 = _slicedToArray(_useState3, 2),
293
- inputValue = _useState4[0],
294
- setInputValue = _useState4[1];
295
- return _jsx(DateInput2, {
296
- renderLabel: LABEL_TEXT,
297
- screenReaderLabels: {
298
- calendarIcon: 'Calendar',
299
- nextMonthButton: 'Next month',
300
- prevMonthButton: 'Previous month'
301
- },
302
- value: inputValue,
303
- onChange: (_e, inputValue, _dateString) => {
304
- setInputValue(inputValue);
305
- },
306
- invalidDateErrorMessage: errorMsg
307
- });
308
- };
309
- render(_jsx(Example, {}));
310
- expect(screen.queryByText(errorMsg)).not.toBeInTheDocument();
311
- const dateInput = screen.getByLabelText(LABEL_TEXT);
312
- await userEvent.click(dateInput);
313
- await userEvent.type(dateInput, 'Not a date');
314
- dateInput.blur();
315
- await waitFor(() => {
316
- expect(screen.getByText(errorMsg)).toBeInTheDocument();
317
- });
318
- });
319
- it('should show form field messages', async () => {
320
- const messages = [{
321
- text: 'TypeLess'
322
- }, {
323
- type: 'error',
324
- text: 'Error'
325
- }, {
326
- type: 'success',
327
- text: 'Success'
328
- }, {
329
- type: 'hint',
330
- text: 'Hint'
331
- }, {
332
- type: 'screenreader-only',
333
- text: 'Screenreader'
334
- }];
335
- render(_jsx(DateInput2, {
336
- renderLabel: "Choose a date",
337
- screenReaderLabels: {
338
- calendarIcon: 'Calendar',
339
- nextMonthButton: 'Next month',
340
- prevMonthButton: 'Previous month'
341
- },
342
- value: "",
343
- messages: messages
344
- }));
345
- expect(screen.getByText('TypeLess')).toBeVisible();
346
- expect(screen.getByText('Error')).toBeVisible();
347
- expect(screen.getByText('Success')).toBeVisible();
348
- expect(screen.getByText('Hint')).toBeVisible();
349
- const screenreaderMessage = screen.getByText('Screenreader');
350
- expect(screenreaderMessage).toBeInTheDocument();
351
- expect(screenreaderMessage).toHaveClass(/screenReaderContent/);
352
- });
353
- });