@instructure/ui-calendar 10.16.1-snapshot-0 → 10.16.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 +1 -1
- package/es/Calendar/Day/__new-tests__/Day.test.js +89 -71
- package/es/Calendar/Day/index.js +13 -9
- package/es/Calendar/__new-tests__/Calendar.test.js +96 -62
- package/es/Calendar/index.js +94 -74
- package/lib/Calendar/Day/__new-tests__/Day.test.js +96 -78
- package/lib/Calendar/Day/index.js +12 -8
- package/lib/Calendar/__new-tests__/Calendar.test.js +112 -79
- package/lib/Calendar/index.js +93 -74
- package/package.json +20 -20
- package/src/Calendar/Day/__new-tests__/Day.test.tsx +16 -17
- package/src/Calendar/Day/index.tsx +1 -2
- package/src/Calendar/__new-tests__/Calendar.test.tsx +4 -8
- package/src/Calendar/index.tsx +4 -6
- package/src/Calendar/props.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Calendar/Day/__new-tests__/Day.test.d.ts.map +1 -1
- package/types/Calendar/Day/index.d.ts +1 -3
- package/types/Calendar/Day/index.d.ts.map +1 -1
- package/types/Calendar/index.d.ts +8 -10
- package/types/Calendar/index.d.ts.map +1 -1
- package/types/Calendar/props.d.ts +1 -1
- package/types/Calendar/props.d.ts.map +1 -1
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.16.1
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-calendar
|
|
9
9
|
|
|
@@ -23,7 +23,6 @@ var _Day, _Day2, _Day3, _Day4, _Day5, _Day6, _Day7, _Day8, _Day9, _Day10, _Day11
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import userEvent from '@testing-library/user-event';
|
|
29
28
|
import { vi } from 'vitest';
|
|
@@ -34,113 +33,126 @@ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11y
|
|
|
34
33
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
35
34
|
import { Day } from '../index';
|
|
36
35
|
import DayExamples from '../__examples__/Day.examples';
|
|
36
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
37
37
|
describe('Day', () => {
|
|
38
38
|
it('should render children', async () => {
|
|
39
|
-
const _render = render(_Day || (_Day =
|
|
39
|
+
const _render = render(_Day || (_Day = _jsx(Day, {
|
|
40
40
|
date: "2019-08-02",
|
|
41
|
-
label: "1 August 2019 Friday"
|
|
42
|
-
|
|
41
|
+
label: "1 August 2019 Friday",
|
|
42
|
+
children: "8"
|
|
43
|
+
}))),
|
|
43
44
|
rerender = _render.rerender;
|
|
44
45
|
const child = screen.getByText('8');
|
|
45
46
|
expect(child).toBeInTheDocument();
|
|
46
|
-
rerender(_Day2 || (_Day2 =
|
|
47
|
+
rerender(_Day2 || (_Day2 = _jsx(Day, {
|
|
47
48
|
date: "2019-08-02",
|
|
48
|
-
label: "1 August 2019 Friday"
|
|
49
|
-
|
|
49
|
+
label: "1 August 2019 Friday",
|
|
50
|
+
children: "31"
|
|
51
|
+
})));
|
|
50
52
|
const childUpdated = screen.getByText('31');
|
|
51
53
|
expect(childUpdated).toBeInTheDocument();
|
|
52
54
|
});
|
|
53
55
|
it('should have an accessible label', async () => {
|
|
54
56
|
const label = '1 August 2019 Friday';
|
|
55
|
-
const _render2 = render(
|
|
57
|
+
const _render2 = render(_jsx(Day, {
|
|
56
58
|
date: "2019-08-02",
|
|
57
|
-
label: label
|
|
58
|
-
|
|
59
|
+
label: label,
|
|
60
|
+
children: "8"
|
|
61
|
+
})),
|
|
59
62
|
container = _render2.container;
|
|
60
|
-
const screenReaderContent = container.querySelector('[class
|
|
63
|
+
const screenReaderContent = container.querySelector('[class*="-screenReaderContent"]');
|
|
61
64
|
expect(screenReaderContent).toBeInTheDocument();
|
|
62
65
|
expect(screenReaderContent).toHaveTextContent(label);
|
|
63
66
|
});
|
|
64
67
|
it('should set aria-current="date" when `isToday`', async () => {
|
|
65
|
-
const _render3 = render(_Day3 || (_Day3 =
|
|
68
|
+
const _render3 = render(_Day3 || (_Day3 = _jsx(Day, {
|
|
66
69
|
date: "2019-08-02",
|
|
67
70
|
label: "1 August 2019 Friday",
|
|
68
|
-
isToday: true
|
|
69
|
-
|
|
71
|
+
isToday: true,
|
|
72
|
+
children: "8"
|
|
73
|
+
}))),
|
|
70
74
|
container = _render3.container,
|
|
71
75
|
rerender = _render3.rerender;
|
|
72
|
-
const today = container.querySelector('[class
|
|
76
|
+
const today = container.querySelector('[class*="-calendarDay"]');
|
|
73
77
|
expect(today).toHaveAttribute('aria-current', 'date');
|
|
74
|
-
rerender(_Day4 || (_Day4 =
|
|
78
|
+
rerender(_Day4 || (_Day4 = _jsx(Day, {
|
|
75
79
|
date: "2019-08-02",
|
|
76
80
|
label: "1 August 2019 Friday",
|
|
77
|
-
isToday: false
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
isToday: false,
|
|
82
|
+
children: "8"
|
|
83
|
+
})));
|
|
84
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
80
85
|
expect(day).not.toHaveAttribute('aria-current', 'date');
|
|
81
86
|
});
|
|
82
87
|
it('should not set aria-selected without a role', async () => {
|
|
83
|
-
const _render4 = render(_Day5 || (_Day5 =
|
|
88
|
+
const _render4 = render(_Day5 || (_Day5 = _jsx(Day, {
|
|
84
89
|
date: "2019-08-02",
|
|
85
|
-
label: "1 August 2019 Friday"
|
|
86
|
-
|
|
90
|
+
label: "1 August 2019 Friday",
|
|
91
|
+
children: "8"
|
|
92
|
+
}))),
|
|
87
93
|
container = _render4.container,
|
|
88
94
|
rerender = _render4.rerender;
|
|
89
|
-
const day = container.querySelector('[class
|
|
95
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
90
96
|
expect(day).not.toHaveAttribute('aria-selected');
|
|
91
|
-
rerender(_Day6 || (_Day6 =
|
|
97
|
+
rerender(_Day6 || (_Day6 = _jsx(Day, {
|
|
92
98
|
date: "2019-08-02",
|
|
93
99
|
label: "1 August 2019 Friday",
|
|
94
|
-
isSelected: true
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
isSelected: true,
|
|
101
|
+
children: "8"
|
|
102
|
+
})));
|
|
103
|
+
const daySelected = container.querySelector('[class*="-calendarDay"]');
|
|
97
104
|
expect(daySelected).not.toHaveAttribute('aria-selected');
|
|
98
105
|
});
|
|
99
106
|
it('should set aria-selected="true/false" when `isSelected` and `role` is `option` or `gridcell`', async () => {
|
|
100
|
-
const _render5 = render(_Day7 || (_Day7 =
|
|
107
|
+
const _render5 = render(_Day7 || (_Day7 = _jsx(Day, {
|
|
101
108
|
date: "2019-08-02",
|
|
102
109
|
label: "1 August 2019 Friday",
|
|
103
|
-
role: "option"
|
|
104
|
-
|
|
110
|
+
role: "option",
|
|
111
|
+
children: "8"
|
|
112
|
+
}))),
|
|
105
113
|
container = _render5.container,
|
|
106
114
|
rerender = _render5.rerender;
|
|
107
|
-
const day = container.querySelector('[class
|
|
115
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
108
116
|
expect(day).toHaveAttribute('aria-selected', 'false');
|
|
109
|
-
rerender(_Day8 || (_Day8 =
|
|
117
|
+
rerender(_Day8 || (_Day8 = _jsx(Day, {
|
|
110
118
|
date: "2019-08-02",
|
|
111
119
|
label: "1 August 2019 Friday",
|
|
112
120
|
role: "option",
|
|
113
|
-
isSelected: true
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
isSelected: true,
|
|
122
|
+
children: "8"
|
|
123
|
+
})));
|
|
124
|
+
const daySelected = container.querySelector('[class*="-calendarDay"]');
|
|
116
125
|
expect(daySelected).toHaveAttribute('aria-selected', 'true');
|
|
117
|
-
rerender(_Day9 || (_Day9 =
|
|
126
|
+
rerender(_Day9 || (_Day9 = _jsx(Day, {
|
|
118
127
|
date: "2019-08-02",
|
|
119
128
|
label: "1 August 2019 Friday",
|
|
120
129
|
role: "gridcell",
|
|
121
|
-
isSelected: false
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
isSelected: false,
|
|
131
|
+
children: "8"
|
|
132
|
+
})));
|
|
133
|
+
const dayCell = container.querySelector('[class*="-calendarDay"]');
|
|
124
134
|
expect(dayCell).toHaveAttribute('aria-selected', 'false');
|
|
125
|
-
rerender(_Day10 || (_Day10 =
|
|
135
|
+
rerender(_Day10 || (_Day10 = _jsx(Day, {
|
|
126
136
|
date: "2019-08-02",
|
|
127
137
|
label: "1 August 2019 Friday",
|
|
128
138
|
role: "gridcell",
|
|
129
|
-
isSelected: true
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
isSelected: true,
|
|
140
|
+
children: "8"
|
|
141
|
+
})));
|
|
142
|
+
const dayCellSelected = container.querySelector('[class*="-calendarDay"]');
|
|
132
143
|
expect(dayCellSelected).toHaveAttribute('aria-selected', 'true');
|
|
133
144
|
});
|
|
134
145
|
it('should call onClick with date', async () => {
|
|
135
146
|
const onClick = vi.fn();
|
|
136
147
|
const date = '2019-08-02';
|
|
137
|
-
const _render6 = render(
|
|
148
|
+
const _render6 = render(_jsx(Day, {
|
|
138
149
|
date: date,
|
|
139
150
|
label: "1 August 2019 Friday",
|
|
140
|
-
onClick: onClick
|
|
141
|
-
|
|
151
|
+
onClick: onClick,
|
|
152
|
+
children: "8"
|
|
153
|
+
})),
|
|
142
154
|
container = _render6.container;
|
|
143
|
-
const day = container.querySelector('[class
|
|
155
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
144
156
|
await userEvent.click(day);
|
|
145
157
|
await waitFor(() => {
|
|
146
158
|
const args = onClick.mock.calls[0][1];
|
|
@@ -151,14 +163,15 @@ describe('Day', () => {
|
|
|
151
163
|
it('should call onKeyDown with date', async () => {
|
|
152
164
|
const onKeyDown = vi.fn();
|
|
153
165
|
const date = '2019-08-02';
|
|
154
|
-
const _render7 = render(
|
|
166
|
+
const _render7 = render(_jsx(Day, {
|
|
155
167
|
date: date,
|
|
156
168
|
label: "1 August 2019 Friday",
|
|
157
169
|
onKeyDown: onKeyDown,
|
|
158
|
-
onClick: () => {}
|
|
159
|
-
|
|
170
|
+
onClick: () => {},
|
|
171
|
+
children: "8"
|
|
172
|
+
})),
|
|
160
173
|
container = _render7.container;
|
|
161
|
-
const day = container.querySelector('[class
|
|
174
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
162
175
|
userEvent.type(day, '{enter}');
|
|
163
176
|
await waitFor(() => {
|
|
164
177
|
const args = onKeyDown.mock.calls[0][1];
|
|
@@ -168,14 +181,15 @@ describe('Day', () => {
|
|
|
168
181
|
});
|
|
169
182
|
it('should apply disabled when interaction is `disabled`', async () => {
|
|
170
183
|
const onClick = vi.fn();
|
|
171
|
-
const _render8 = render(
|
|
184
|
+
const _render8 = render(_jsx(Day, {
|
|
172
185
|
date: "2019-08-02",
|
|
173
186
|
label: "1 August 2019 Friday",
|
|
174
187
|
onClick: onClick,
|
|
175
|
-
interaction: "disabled"
|
|
176
|
-
|
|
188
|
+
interaction: "disabled",
|
|
189
|
+
children: "8"
|
|
190
|
+
})),
|
|
177
191
|
container = _render8.container;
|
|
178
|
-
const day = container.querySelector('[class
|
|
192
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
179
193
|
userEvent.click(day);
|
|
180
194
|
await waitFor(() => {
|
|
181
195
|
expect(onClick).not.toHaveBeenCalled();
|
|
@@ -187,44 +201,48 @@ describe('Day', () => {
|
|
|
187
201
|
const elementRef = el => {
|
|
188
202
|
element = el;
|
|
189
203
|
};
|
|
190
|
-
const _render9 = render(
|
|
204
|
+
const _render9 = render(_jsx(Day, {
|
|
191
205
|
date: "2019-08-02",
|
|
192
206
|
label: "1 August 2019 Friday",
|
|
193
|
-
elementRef: elementRef
|
|
194
|
-
|
|
207
|
+
elementRef: elementRef,
|
|
208
|
+
children: "8"
|
|
209
|
+
})),
|
|
195
210
|
container = _render9.container;
|
|
196
|
-
const day = container.querySelector('[class
|
|
211
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
197
212
|
expect(day).toEqual(element);
|
|
198
213
|
});
|
|
199
214
|
describe('element type', () => {
|
|
200
215
|
it('should render as a span by default', async () => {
|
|
201
|
-
const _render10 = render(_Day11 || (_Day11 =
|
|
216
|
+
const _render10 = render(_Day11 || (_Day11 = _jsx(Day, {
|
|
202
217
|
date: "2019-08-02",
|
|
203
|
-
label: "1 August 2019 Friday"
|
|
204
|
-
|
|
218
|
+
label: "1 August 2019 Friday",
|
|
219
|
+
children: "8"
|
|
220
|
+
}))),
|
|
205
221
|
container = _render10.container;
|
|
206
|
-
const day = container.querySelector('[class
|
|
222
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
207
223
|
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('SPAN');
|
|
208
224
|
});
|
|
209
225
|
it('should render as a button when onClick is provided', async () => {
|
|
210
|
-
const _render11 = render(
|
|
226
|
+
const _render11 = render(_jsx(Day, {
|
|
211
227
|
date: "2019-08-02",
|
|
212
228
|
label: "1 August 2019 Friday",
|
|
213
|
-
onClick: () => {}
|
|
214
|
-
|
|
229
|
+
onClick: () => {},
|
|
230
|
+
children: "8"
|
|
231
|
+
})),
|
|
215
232
|
container = _render11.container;
|
|
216
|
-
const day = container.querySelector('[class
|
|
233
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
217
234
|
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('BUTTON');
|
|
218
235
|
});
|
|
219
236
|
it('default elementTypes should be overwritten when `as` prop is set', async () => {
|
|
220
|
-
const _render12 = render(
|
|
237
|
+
const _render12 = render(_jsx(Day, {
|
|
221
238
|
date: "2019-08-02",
|
|
222
239
|
label: "1 August 2019 Friday",
|
|
223
240
|
onClick: () => {},
|
|
224
|
-
as: "li"
|
|
225
|
-
|
|
241
|
+
as: "li",
|
|
242
|
+
children: "8"
|
|
243
|
+
})),
|
|
226
244
|
container = _render12.container;
|
|
227
|
-
const day = container.querySelector('[class
|
|
245
|
+
const day = container.querySelector('[class*="-calendarDay"]');
|
|
228
246
|
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('LI');
|
|
229
247
|
});
|
|
230
248
|
});
|
package/es/Calendar/Day/index.js
CHANGED
|
@@ -25,16 +25,16 @@ var _dec, _dec2, _class, _Day;
|
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
/** @jsx jsx */
|
|
29
28
|
import { Component } from 'react';
|
|
30
29
|
import { View } from '@instructure/ui-view';
|
|
31
30
|
import { AccessibleContent } from '@instructure/ui-a11y-content';
|
|
32
31
|
import { omitProps, callRenderProp, getElementType } from '@instructure/ui-react-utils';
|
|
33
32
|
import { testable } from '@instructure/ui-testable';
|
|
34
|
-
import { withStyle
|
|
33
|
+
import { withStyle } from '@instructure/emotion';
|
|
35
34
|
import generateStyle from './styles';
|
|
36
35
|
import generateComponentTheme from './theme';
|
|
37
36
|
import { propTypes, allowedProps } from './props';
|
|
37
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
38
38
|
/**
|
|
39
39
|
---
|
|
40
40
|
parent: Calendar
|
|
@@ -114,7 +114,8 @@ let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = test
|
|
|
114
114
|
const elementType = this.elementType,
|
|
115
115
|
isDisabled = this.isDisabled;
|
|
116
116
|
const passthroughProps = View.omitViewProps(omitProps(props, Day.allowedProps), Day);
|
|
117
|
-
return
|
|
117
|
+
return _jsx(View, {
|
|
118
|
+
...passthroughProps,
|
|
118
119
|
as: elementType,
|
|
119
120
|
css: styles === null || styles === void 0 ? void 0 : styles.calendarDay,
|
|
120
121
|
display: "inline-block",
|
|
@@ -128,12 +129,15 @@ let Day = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = test
|
|
|
128
129
|
"aria-selected": this.shouldApplyAriaSelected() ? isSelected ? 'true' : 'false' : void 0,
|
|
129
130
|
onClick: onClick && this.handleClick,
|
|
130
131
|
onKeyDown: onKeyDown && this.handleKeyDown,
|
|
131
|
-
elementRef: this.handleElementRef
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
elementRef: this.handleElementRef,
|
|
133
|
+
children: _jsx("span", {
|
|
134
|
+
css: styles === null || styles === void 0 ? void 0 : styles.day,
|
|
135
|
+
children: _jsx(AccessibleContent, {
|
|
136
|
+
alt: label,
|
|
137
|
+
children: callRenderProp(children)
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
});
|
|
137
141
|
}
|
|
138
142
|
}, _Day.displayName = "Day", _Day.componentId = 'Calendar.Day', _Day.propTypes = propTypes, _Day.allowedProps = allowedProps, _Day.defaultProps = {
|
|
139
143
|
interaction: 'enabled',
|
|
@@ -22,7 +22,7 @@ var _Calendar, _Calendar2, _Calendar3, _Calendar4, _span, _button, _button2, _bu
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
27
27
|
import userEvent from '@testing-library/user-event';
|
|
28
28
|
import { vi } from 'vitest';
|
|
@@ -33,17 +33,18 @@ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11y
|
|
|
33
33
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
34
34
|
import CalendarExamples from '../__examples__/Calendar.examples';
|
|
35
35
|
import Calendar from '../index';
|
|
36
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
36
37
|
const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
37
38
|
const generateDays = (count = Calendar.DAY_COUNT) => {
|
|
38
39
|
const days = [];
|
|
39
40
|
const date = new Date('2019-07-28');
|
|
40
41
|
while (days.length < count) {
|
|
41
|
-
days.push(
|
|
42
|
-
key: date.toISOString(),
|
|
42
|
+
days.push(_jsx(Calendar.Day, {
|
|
43
43
|
date: date.toISOString(),
|
|
44
44
|
label: date.toISOString(),
|
|
45
|
-
isOutsideMonth: date.getMonth() !== 7
|
|
46
|
-
|
|
45
|
+
isOutsideMonth: date.getMonth() !== 7,
|
|
46
|
+
children: date.getDate()
|
|
47
|
+
}, date.toISOString()));
|
|
47
48
|
date.setDate(date.getDate() + 1);
|
|
48
49
|
}
|
|
49
50
|
return days;
|
|
@@ -62,18 +63,18 @@ describe('<Calendar />', () => {
|
|
|
62
63
|
});
|
|
63
64
|
describe('with minimal config', () => {
|
|
64
65
|
it('should render 44 buttons without config', async () => {
|
|
65
|
-
render(_Calendar || (_Calendar =
|
|
66
|
+
render(_Calendar || (_Calendar = _jsx(Calendar, {})));
|
|
66
67
|
const buttons = document.getElementsByTagName('button');
|
|
67
68
|
expect(buttons.length).toEqual(44);
|
|
68
69
|
});
|
|
69
70
|
it('should render proper week names by default', async () => {
|
|
70
|
-
const _render = render(_Calendar2 || (_Calendar2 =
|
|
71
|
+
const _render = render(_Calendar2 || (_Calendar2 = _jsx(Calendar, {}))),
|
|
71
72
|
container = _render.container;
|
|
72
73
|
const thead = container.querySelector('thead');
|
|
73
74
|
expect(thead).toHaveTextContent('SundaySuMondayMoTuesdayTuWednesdayWeThursdayThFridayFrSaturdaySa');
|
|
74
75
|
});
|
|
75
76
|
it('should render proper week names if locale is set', async () => {
|
|
76
|
-
const _render2 = render(_Calendar3 || (_Calendar3 =
|
|
77
|
+
const _render2 = render(_Calendar3 || (_Calendar3 = _jsx(Calendar, {
|
|
77
78
|
locale: "hu"
|
|
78
79
|
}))),
|
|
79
80
|
container = _render2.container;
|
|
@@ -81,7 +82,7 @@ describe('<Calendar />', () => {
|
|
|
81
82
|
expect(thead).toHaveTextContent('hétfőhkeddkszerdaszecsütörtökcspéntekpszombatszovasárnapv');
|
|
82
83
|
});
|
|
83
84
|
it('should disable days properly', async () => {
|
|
84
|
-
const _render3 = render(
|
|
85
|
+
const _render3 = render(_jsx(Calendar, {
|
|
85
86
|
currentDate: "2023-12-15",
|
|
86
87
|
disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11']
|
|
87
88
|
})),
|
|
@@ -94,7 +95,7 @@ describe('<Calendar />', () => {
|
|
|
94
95
|
});
|
|
95
96
|
it('should indicate selected day', async () => {
|
|
96
97
|
var _screen$queryByText, _screen$queryByText$p;
|
|
97
|
-
render(_Calendar4 || (_Calendar4 =
|
|
98
|
+
render(_Calendar4 || (_Calendar4 = _jsx(Calendar, {
|
|
98
99
|
currentDate: "2023-12-15",
|
|
99
100
|
selectedDate: "2023-12-22"
|
|
100
101
|
})));
|
|
@@ -107,25 +108,28 @@ describe('<Calendar />', () => {
|
|
|
107
108
|
});
|
|
108
109
|
});
|
|
109
110
|
it('should render children', async () => {
|
|
110
|
-
const _render4 = render(
|
|
111
|
-
renderWeekdayLabels: weekdayLabels
|
|
112
|
-
|
|
111
|
+
const _render4 = render(_jsx(Calendar, {
|
|
112
|
+
renderWeekdayLabels: weekdayLabels,
|
|
113
|
+
children: generateDays()
|
|
114
|
+
})),
|
|
113
115
|
container = _render4.container;
|
|
114
|
-
const calendarDays = container.querySelectorAll('span[class
|
|
116
|
+
const calendarDays = container.querySelectorAll('span[class*="-calendarDay__day"]');
|
|
115
117
|
expect(calendarDays.length).toEqual(Calendar.DAY_COUNT);
|
|
116
118
|
});
|
|
117
119
|
it(`should warn if the correct number of children are not provided`, async () => {
|
|
118
120
|
const count = Calendar.DAY_COUNT - 1;
|
|
119
|
-
render(
|
|
120
|
-
renderWeekdayLabels: weekdayLabels
|
|
121
|
-
|
|
121
|
+
render(_jsx(Calendar, {
|
|
122
|
+
renderWeekdayLabels: weekdayLabels,
|
|
123
|
+
children: generateDays(count)
|
|
124
|
+
}));
|
|
122
125
|
const expectedErrorMessage = `should have exactly ${Calendar.DAY_COUNT} children. ${count} provided.`;
|
|
123
126
|
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
124
127
|
});
|
|
125
128
|
it('should render weekday labels', async () => {
|
|
126
|
-
const _render5 = render(
|
|
127
|
-
renderWeekdayLabels: weekdayLabels
|
|
128
|
-
|
|
129
|
+
const _render5 = render(_jsx(Calendar, {
|
|
130
|
+
renderWeekdayLabels: weekdayLabels,
|
|
131
|
+
children: generateDays()
|
|
132
|
+
})),
|
|
129
133
|
container = _render5.container,
|
|
130
134
|
rerender = _render5.rerender;
|
|
131
135
|
const originalHeaders = container.querySelectorAll('th');
|
|
@@ -136,9 +140,10 @@ describe('<Calendar />', () => {
|
|
|
136
140
|
const functionalWeekdayLabels = [() => 'Sx', () => 'Mx', () => 'Tx', () => 'Wx', () => 'Tx', () => 'Fx', () => 'Sx'];
|
|
137
141
|
|
|
138
142
|
// Set prop: renderWeekdayLabels
|
|
139
|
-
rerender(
|
|
140
|
-
renderWeekdayLabels: functionalWeekdayLabels
|
|
141
|
-
|
|
143
|
+
rerender(_jsx(Calendar, {
|
|
144
|
+
renderWeekdayLabels: functionalWeekdayLabels,
|
|
145
|
+
children: generateDays()
|
|
146
|
+
}));
|
|
142
147
|
const updatedHeaders = container.querySelectorAll('th');
|
|
143
148
|
expect(updatedHeaders.length).toEqual(7);
|
|
144
149
|
functionalWeekdayLabels.forEach((functionalLabel, i) => {
|
|
@@ -146,16 +151,18 @@ describe('<Calendar />', () => {
|
|
|
146
151
|
});
|
|
147
152
|
});
|
|
148
153
|
it('should warn if 7 weekday labels are not provided', async () => {
|
|
149
|
-
render(
|
|
150
|
-
renderWeekdayLabels: []
|
|
151
|
-
|
|
154
|
+
render(_jsx(Calendar, {
|
|
155
|
+
renderWeekdayLabels: [],
|
|
156
|
+
children: generateDays()
|
|
157
|
+
}));
|
|
152
158
|
const expectedErrorMessage = '`renderWeekdayLabels` should be an array with 7 labels (one for each weekday). 0 provided.';
|
|
153
159
|
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
154
160
|
});
|
|
155
161
|
it('should format the weekday labels and days correctly', async () => {
|
|
156
|
-
const _render6 = render(
|
|
157
|
-
renderWeekdayLabels: weekdayLabels
|
|
158
|
-
|
|
162
|
+
const _render6 = render(_jsx(Calendar, {
|
|
163
|
+
renderWeekdayLabels: weekdayLabels,
|
|
164
|
+
children: generateDays()
|
|
165
|
+
})),
|
|
159
166
|
container = _render6.container;
|
|
160
167
|
const headerRow = container.querySelectorAll('thead > tr');
|
|
161
168
|
expect(headerRow.length).toEqual(1);
|
|
@@ -169,11 +176,18 @@ describe('<Calendar />', () => {
|
|
|
169
176
|
}
|
|
170
177
|
});
|
|
171
178
|
it('should render navigation label', async () => {
|
|
172
|
-
const navLabel = _span || (_span =
|
|
173
|
-
|
|
179
|
+
const navLabel = _span || (_span = _jsxs("span", {
|
|
180
|
+
children: [_jsx("div", {
|
|
181
|
+
children: "March"
|
|
182
|
+
}), _jsx("div", {
|
|
183
|
+
children: "2019"
|
|
184
|
+
})]
|
|
185
|
+
}));
|
|
186
|
+
const _render7 = render(_jsx(Calendar, {
|
|
174
187
|
renderWeekdayLabels: weekdayLabels,
|
|
175
|
-
renderNavigationLabel: navLabel
|
|
176
|
-
|
|
188
|
+
renderNavigationLabel: navLabel,
|
|
189
|
+
children: generateDays()
|
|
190
|
+
})),
|
|
177
191
|
rerender = _render7.rerender;
|
|
178
192
|
const month = screen.getByText('March');
|
|
179
193
|
const year = screen.getByText('2019');
|
|
@@ -181,38 +195,50 @@ describe('<Calendar />', () => {
|
|
|
181
195
|
expect(year).toBeInTheDocument();
|
|
182
196
|
|
|
183
197
|
// Set prop: renderNavigationLabel
|
|
184
|
-
rerender(
|
|
198
|
+
rerender(_jsx(Calendar, {
|
|
185
199
|
renderWeekdayLabels: weekdayLabels,
|
|
186
|
-
renderNavigationLabel: () => navLabel
|
|
187
|
-
|
|
200
|
+
renderNavigationLabel: () => navLabel,
|
|
201
|
+
children: generateDays()
|
|
202
|
+
}));
|
|
188
203
|
const updatedMonth = screen.getByText('March');
|
|
189
204
|
const updatedYear = screen.getByText('2019');
|
|
190
205
|
expect(updatedMonth).toBeInTheDocument();
|
|
191
206
|
expect(updatedYear).toBeInTheDocument();
|
|
192
207
|
});
|
|
193
208
|
it('should render next and prev buttons', async () => {
|
|
194
|
-
const _render8 = render(
|
|
195
|
-
renderWeekdayLabels: weekdayLabels
|
|
196
|
-
|
|
209
|
+
const _render8 = render(_jsx(Calendar, {
|
|
210
|
+
renderWeekdayLabels: weekdayLabels,
|
|
211
|
+
children: generateDays()
|
|
212
|
+
})),
|
|
197
213
|
rerender = _render8.rerender;
|
|
198
214
|
const defaultPrevButton = screen.getByText('Previous month');
|
|
199
215
|
const defaultNextButton = screen.getByText('Next month');
|
|
200
216
|
expect(defaultPrevButton).toBeInTheDocument();
|
|
201
217
|
expect(defaultNextButton).toBeInTheDocument();
|
|
202
|
-
rerender(
|
|
218
|
+
rerender(_jsx(Calendar, {
|
|
203
219
|
renderWeekdayLabels: weekdayLabels,
|
|
204
|
-
renderPrevMonthButton: _button || (_button =
|
|
205
|
-
|
|
206
|
-
|
|
220
|
+
renderPrevMonthButton: _button || (_button = _jsx("button", {
|
|
221
|
+
children: "test-prev"
|
|
222
|
+
})),
|
|
223
|
+
renderNextMonthButton: _button2 || (_button2 = _jsx("button", {
|
|
224
|
+
children: "test-next"
|
|
225
|
+
})),
|
|
226
|
+
children: generateDays()
|
|
227
|
+
}));
|
|
207
228
|
const customPrevButton = screen.getByText('test-prev');
|
|
208
229
|
const customNextButton = screen.getByText('test-next');
|
|
209
230
|
expect(customPrevButton).toBeInTheDocument();
|
|
210
231
|
expect(customNextButton).toBeInTheDocument();
|
|
211
|
-
rerender(
|
|
232
|
+
rerender(_jsx(Calendar, {
|
|
212
233
|
renderWeekdayLabels: weekdayLabels,
|
|
213
|
-
renderPrevMonthButton: () => _button3 || (_button3 =
|
|
214
|
-
|
|
215
|
-
|
|
234
|
+
renderPrevMonthButton: () => _button3 || (_button3 = _jsx("button", {
|
|
235
|
+
children: "func-test-prev"
|
|
236
|
+
})),
|
|
237
|
+
renderNextMonthButton: () => _button4 || (_button4 = _jsx("button", {
|
|
238
|
+
children: "func-test-next"
|
|
239
|
+
})),
|
|
240
|
+
children: generateDays()
|
|
241
|
+
}));
|
|
216
242
|
const funcPrevButton = screen.getByText('func-test-prev');
|
|
217
243
|
const funcNextButton = screen.getByText('func-test-next');
|
|
218
244
|
expect(funcPrevButton).toBeInTheDocument();
|
|
@@ -221,13 +247,18 @@ describe('<Calendar />', () => {
|
|
|
221
247
|
it('should call onRequestRenderNextMonth and onRequestRenderPrevMonth', async () => {
|
|
222
248
|
const onRequestRenderPrevMonth = vi.fn();
|
|
223
249
|
const onRequestRenderNextMonth = vi.fn();
|
|
224
|
-
render(
|
|
250
|
+
render(_jsx(Calendar, {
|
|
225
251
|
renderWeekdayLabels: weekdayLabels,
|
|
226
|
-
renderPrevMonthButton: _button5 || (_button5 =
|
|
227
|
-
|
|
252
|
+
renderPrevMonthButton: _button5 || (_button5 = _jsx("button", {
|
|
253
|
+
children: "prev month"
|
|
254
|
+
})),
|
|
255
|
+
renderNextMonthButton: _button6 || (_button6 = _jsx("button", {
|
|
256
|
+
children: "next month"
|
|
257
|
+
})),
|
|
228
258
|
onRequestRenderPrevMonth: onRequestRenderPrevMonth,
|
|
229
|
-
onRequestRenderNextMonth: onRequestRenderNextMonth
|
|
230
|
-
|
|
259
|
+
onRequestRenderNextMonth: onRequestRenderNextMonth,
|
|
260
|
+
children: generateDays()
|
|
261
|
+
}));
|
|
231
262
|
const prevButton = screen.getByText('prev month');
|
|
232
263
|
const nextButton = screen.getByText('next month');
|
|
233
264
|
expect(onRequestRenderPrevMonth).not.toHaveBeenCalled();
|
|
@@ -241,10 +272,11 @@ describe('<Calendar />', () => {
|
|
|
241
272
|
});
|
|
242
273
|
describe('when role="listbox"', () => {
|
|
243
274
|
it('should set role="listbox" on table root and role="presentation" on the correct elements', async () => {
|
|
244
|
-
const _render9 = render(
|
|
275
|
+
const _render9 = render(_jsx(Calendar, {
|
|
245
276
|
renderWeekdayLabels: weekdayLabels,
|
|
246
|
-
role: "listbox"
|
|
247
|
-
|
|
277
|
+
role: "listbox",
|
|
278
|
+
children: generateDays()
|
|
279
|
+
})),
|
|
248
280
|
container = _render9.container;
|
|
249
281
|
const table = container.querySelector('table');
|
|
250
282
|
expect(table).toHaveAttribute('role', 'listbox');
|
|
@@ -258,25 +290,27 @@ describe('<Calendar />', () => {
|
|
|
258
290
|
}
|
|
259
291
|
});
|
|
260
292
|
it("should link each day with it's weekday header via `aria-describedby`", async () => {
|
|
261
|
-
const _render10 = render(
|
|
293
|
+
const _render10 = render(_jsx(Calendar, {
|
|
262
294
|
renderWeekdayLabels: weekdayLabels,
|
|
263
|
-
role: "listbox"
|
|
264
|
-
|
|
295
|
+
role: "listbox",
|
|
296
|
+
children: generateDays()
|
|
297
|
+
})),
|
|
265
298
|
container = _render10.container;
|
|
266
299
|
const days = container.querySelectorAll('tbody > tr > td');
|
|
267
300
|
const headers = container.querySelectorAll('th');
|
|
268
301
|
days.forEach((dayTd, i) => {
|
|
269
302
|
const index = i % 7;
|
|
270
|
-
const day = dayTd.querySelector('span[class
|
|
303
|
+
const day = dayTd.querySelector('span[class*="-calendarDay"]');
|
|
271
304
|
expect(day).toHaveAttribute('aria-describedby', headers[index].getAttribute('id'));
|
|
272
305
|
});
|
|
273
306
|
});
|
|
274
307
|
});
|
|
275
308
|
it('should render root as designated by the `as` prop', async () => {
|
|
276
|
-
render(
|
|
309
|
+
render(_jsx(Calendar, {
|
|
277
310
|
renderWeekdayLabels: weekdayLabels,
|
|
278
|
-
as: "ul"
|
|
279
|
-
|
|
311
|
+
as: "ul",
|
|
312
|
+
children: generateDays()
|
|
313
|
+
}));
|
|
280
314
|
const calendar = screen.getByRole('list');
|
|
281
315
|
expect(calendar.tagName).toBe('UL');
|
|
282
316
|
expect(calendar).toHaveTextContent(weekdayLabels.join(''));
|