@instructure/ui-calendar 10.5.1-snapshot-0 → 10.5.1-snapshot-2
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 +242 -0
- package/es/Calendar/__new-tests__/Calendar.test.js +209 -2
- package/lib/Calendar/Day/__new-tests__/Day.test.js +243 -0
- package/lib/Calendar/__new-tests__/Calendar.test.js +207 -1
- package/package.json +21 -20
- package/src/Calendar/Day/__new-tests__/Day.test.tsx +303 -0
- package/src/Calendar/__new-tests__/Calendar.test.tsx +316 -2
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Calendar/Day/__new-tests__/Day.test.d.ts +2 -0
- package/types/Calendar/Day/__new-tests__/Day.test.d.ts.map +1 -0
- package/es/Calendar/CalendarLocator.js +0 -37
- package/es/Calendar/Day/DayLocator.js +0 -29
- package/es/Calendar/Day/locator.js +0 -27
- package/es/Calendar/locator.js +0 -26
- package/lib/Calendar/CalendarLocator.js +0 -48
- package/lib/Calendar/Day/DayLocator.js +0 -34
- package/lib/Calendar/Day/locator.js +0 -37
- package/lib/Calendar/locator.js +0 -37
- package/src/Calendar/CalendarLocator.ts +0 -39
- package/src/Calendar/Day/DayLocator.ts +0 -30
- package/src/Calendar/Day/locator.ts +0 -28
- package/src/Calendar/locator.ts +0 -27
- package/types/Calendar/CalendarLocator.d.ts +0 -1067
- package/types/Calendar/CalendarLocator.d.ts.map +0 -1
- package/types/Calendar/Day/DayLocator.d.ts +0 -310
- package/types/Calendar/Day/DayLocator.d.ts.map +0 -1
- package/types/Calendar/Day/locator.d.ts +0 -4
- package/types/Calendar/Day/locator.d.ts.map +0 -1
- package/types/Calendar/locator.d.ts +0 -4
- package/types/Calendar/locator.d.ts.map +0 -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.5.1-snapshot-
|
|
6
|
+
## [10.5.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.5.0...v10.5.1-snapshot-2) (2024-11-13)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-calendar
|
|
9
9
|
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
var _Day, _Day2, _Day3, _Day4, _Day5, _Day6, _Day7, _Day8, _Day9, _Day10, _Day11;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import { vi } from 'vitest';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line no-restricted-imports
|
|
33
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
34
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
35
|
+
import { Day } from '../index';
|
|
36
|
+
import DayExamples from '../__examples__/Day.examples';
|
|
37
|
+
describe('Day', () => {
|
|
38
|
+
it('should render children', async () => {
|
|
39
|
+
const _render = render(_Day || (_Day = /*#__PURE__*/React.createElement(Day, {
|
|
40
|
+
date: "2019-08-02",
|
|
41
|
+
label: "1 August 2019 Friday"
|
|
42
|
+
}, "8"))),
|
|
43
|
+
rerender = _render.rerender;
|
|
44
|
+
const child = screen.getByText('8');
|
|
45
|
+
expect(child).toBeInTheDocument();
|
|
46
|
+
rerender(_Day2 || (_Day2 = /*#__PURE__*/React.createElement(Day, {
|
|
47
|
+
date: "2019-08-02",
|
|
48
|
+
label: "1 August 2019 Friday"
|
|
49
|
+
}, "31")));
|
|
50
|
+
const childUpdated = screen.getByText('31');
|
|
51
|
+
expect(childUpdated).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
it('should have an accessible label', async () => {
|
|
54
|
+
const label = '1 August 2019 Friday';
|
|
55
|
+
const _render2 = render(/*#__PURE__*/React.createElement(Day, {
|
|
56
|
+
date: "2019-08-02",
|
|
57
|
+
label: label
|
|
58
|
+
}, "8")),
|
|
59
|
+
container = _render2.container;
|
|
60
|
+
const screenReaderContent = container.querySelector('[class$="-screenReaderContent"]');
|
|
61
|
+
expect(screenReaderContent).toBeInTheDocument();
|
|
62
|
+
expect(screenReaderContent).toHaveTextContent(label);
|
|
63
|
+
});
|
|
64
|
+
it('should set aria-current="date" when `isToday`', async () => {
|
|
65
|
+
const _render3 = render(_Day3 || (_Day3 = /*#__PURE__*/React.createElement(Day, {
|
|
66
|
+
date: "2019-08-02",
|
|
67
|
+
label: "1 August 2019 Friday",
|
|
68
|
+
isToday: true
|
|
69
|
+
}, "8"))),
|
|
70
|
+
container = _render3.container,
|
|
71
|
+
rerender = _render3.rerender;
|
|
72
|
+
const today = container.querySelector('[class$="-calendarDay"]');
|
|
73
|
+
expect(today).toHaveAttribute('aria-current', 'date');
|
|
74
|
+
rerender(_Day4 || (_Day4 = /*#__PURE__*/React.createElement(Day, {
|
|
75
|
+
date: "2019-08-02",
|
|
76
|
+
label: "1 August 2019 Friday",
|
|
77
|
+
isToday: false
|
|
78
|
+
}, "8")));
|
|
79
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
80
|
+
expect(day).not.toHaveAttribute('aria-current', 'date');
|
|
81
|
+
});
|
|
82
|
+
it('should not set aria-selected without a role', async () => {
|
|
83
|
+
const _render4 = render(_Day5 || (_Day5 = /*#__PURE__*/React.createElement(Day, {
|
|
84
|
+
date: "2019-08-02",
|
|
85
|
+
label: "1 August 2019 Friday"
|
|
86
|
+
}, "8"))),
|
|
87
|
+
container = _render4.container,
|
|
88
|
+
rerender = _render4.rerender;
|
|
89
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
90
|
+
expect(day).not.toHaveAttribute('aria-selected');
|
|
91
|
+
rerender(_Day6 || (_Day6 = /*#__PURE__*/React.createElement(Day, {
|
|
92
|
+
date: "2019-08-02",
|
|
93
|
+
label: "1 August 2019 Friday",
|
|
94
|
+
isSelected: true
|
|
95
|
+
}, "8")));
|
|
96
|
+
const daySelected = container.querySelector('[class$="-calendarDay"]');
|
|
97
|
+
expect(daySelected).not.toHaveAttribute('aria-selected');
|
|
98
|
+
});
|
|
99
|
+
it('should set aria-selected="true/false" when `isSelected` and `role` is `option` or `gridcell`', async () => {
|
|
100
|
+
const _render5 = render(_Day7 || (_Day7 = /*#__PURE__*/React.createElement(Day, {
|
|
101
|
+
date: "2019-08-02",
|
|
102
|
+
label: "1 August 2019 Friday",
|
|
103
|
+
role: "option"
|
|
104
|
+
}, "8"))),
|
|
105
|
+
container = _render5.container,
|
|
106
|
+
rerender = _render5.rerender;
|
|
107
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
108
|
+
expect(day).toHaveAttribute('aria-selected', 'false');
|
|
109
|
+
rerender(_Day8 || (_Day8 = /*#__PURE__*/React.createElement(Day, {
|
|
110
|
+
date: "2019-08-02",
|
|
111
|
+
label: "1 August 2019 Friday",
|
|
112
|
+
role: "option",
|
|
113
|
+
isSelected: true
|
|
114
|
+
}, "8")));
|
|
115
|
+
const daySelected = container.querySelector('[class$="-calendarDay"]');
|
|
116
|
+
expect(daySelected).toHaveAttribute('aria-selected', 'true');
|
|
117
|
+
rerender(_Day9 || (_Day9 = /*#__PURE__*/React.createElement(Day, {
|
|
118
|
+
date: "2019-08-02",
|
|
119
|
+
label: "1 August 2019 Friday",
|
|
120
|
+
role: "gridcell",
|
|
121
|
+
isSelected: false
|
|
122
|
+
}, "8")));
|
|
123
|
+
const dayCell = container.querySelector('[class$="-calendarDay"]');
|
|
124
|
+
expect(dayCell).toHaveAttribute('aria-selected', 'false');
|
|
125
|
+
rerender(_Day10 || (_Day10 = /*#__PURE__*/React.createElement(Day, {
|
|
126
|
+
date: "2019-08-02",
|
|
127
|
+
label: "1 August 2019 Friday",
|
|
128
|
+
role: "gridcell",
|
|
129
|
+
isSelected: true
|
|
130
|
+
}, "8")));
|
|
131
|
+
const dayCellSelected = container.querySelector('[class$="-calendarDay"]');
|
|
132
|
+
expect(dayCellSelected).toHaveAttribute('aria-selected', 'true');
|
|
133
|
+
});
|
|
134
|
+
it('should call onClick with date', async () => {
|
|
135
|
+
const onClick = vi.fn();
|
|
136
|
+
const date = '2019-08-02';
|
|
137
|
+
const _render6 = render(/*#__PURE__*/React.createElement(Day, {
|
|
138
|
+
date: date,
|
|
139
|
+
label: "1 August 2019 Friday",
|
|
140
|
+
onClick: onClick
|
|
141
|
+
}, "8")),
|
|
142
|
+
container = _render6.container;
|
|
143
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
144
|
+
await userEvent.click(day);
|
|
145
|
+
await waitFor(() => {
|
|
146
|
+
const args = onClick.mock.calls[0][1];
|
|
147
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(args).toHaveProperty('date', date);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it('should call onKeyDown with date', async () => {
|
|
152
|
+
const onKeyDown = vi.fn();
|
|
153
|
+
const date = '2019-08-02';
|
|
154
|
+
const _render7 = render(/*#__PURE__*/React.createElement(Day, {
|
|
155
|
+
date: date,
|
|
156
|
+
label: "1 August 2019 Friday",
|
|
157
|
+
onKeyDown: onKeyDown,
|
|
158
|
+
onClick: () => {}
|
|
159
|
+
}, "8")),
|
|
160
|
+
container = _render7.container;
|
|
161
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
162
|
+
userEvent.type(day, '{enter}');
|
|
163
|
+
await waitFor(() => {
|
|
164
|
+
const args = onKeyDown.mock.calls[0][1];
|
|
165
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1);
|
|
166
|
+
expect(args).toHaveProperty('date', date);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
it('should apply disabled when interaction is `disabled`', async () => {
|
|
170
|
+
const onClick = vi.fn();
|
|
171
|
+
const _render8 = render(/*#__PURE__*/React.createElement(Day, {
|
|
172
|
+
date: "2019-08-02",
|
|
173
|
+
label: "1 August 2019 Friday",
|
|
174
|
+
onClick: onClick,
|
|
175
|
+
interaction: "disabled"
|
|
176
|
+
}, "8")),
|
|
177
|
+
container = _render8.container;
|
|
178
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
179
|
+
userEvent.click(day);
|
|
180
|
+
await waitFor(() => {
|
|
181
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
182
|
+
expect(day).toHaveAttribute('disabled');
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
it('should provide an elementRef', async () => {
|
|
186
|
+
let element;
|
|
187
|
+
const elementRef = el => {
|
|
188
|
+
element = el;
|
|
189
|
+
};
|
|
190
|
+
const _render9 = render(/*#__PURE__*/React.createElement(Day, {
|
|
191
|
+
date: "2019-08-02",
|
|
192
|
+
label: "1 August 2019 Friday",
|
|
193
|
+
elementRef: elementRef
|
|
194
|
+
}, "8")),
|
|
195
|
+
container = _render9.container;
|
|
196
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
197
|
+
expect(day).toEqual(element);
|
|
198
|
+
});
|
|
199
|
+
describe('element type', () => {
|
|
200
|
+
it('should render as a span by default', async () => {
|
|
201
|
+
const _render10 = render(_Day11 || (_Day11 = /*#__PURE__*/React.createElement(Day, {
|
|
202
|
+
date: "2019-08-02",
|
|
203
|
+
label: "1 August 2019 Friday"
|
|
204
|
+
}, "8"))),
|
|
205
|
+
container = _render10.container;
|
|
206
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
207
|
+
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('SPAN');
|
|
208
|
+
});
|
|
209
|
+
it('should render as a button when onClick is provided', async () => {
|
|
210
|
+
const _render11 = render(/*#__PURE__*/React.createElement(Day, {
|
|
211
|
+
date: "2019-08-02",
|
|
212
|
+
label: "1 August 2019 Friday",
|
|
213
|
+
onClick: () => {}
|
|
214
|
+
}, "8")),
|
|
215
|
+
container = _render11.container;
|
|
216
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
217
|
+
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('BUTTON');
|
|
218
|
+
});
|
|
219
|
+
it('default elementTypes should be overwritten when `as` prop is set', async () => {
|
|
220
|
+
const _render12 = render(/*#__PURE__*/React.createElement(Day, {
|
|
221
|
+
date: "2019-08-02",
|
|
222
|
+
label: "1 August 2019 Friday",
|
|
223
|
+
onClick: () => {},
|
|
224
|
+
as: "li"
|
|
225
|
+
}, "8")),
|
|
226
|
+
container = _render12.container;
|
|
227
|
+
const day = container.querySelector('[class$="-calendarDay"]');
|
|
228
|
+
expect(day === null || day === void 0 ? void 0 : day.tagName).toEqual('LI');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
describe('with generated examples', () => {
|
|
232
|
+
const generatedComponents = generateA11yTests(Day, DayExamples);
|
|
233
|
+
for (const component of generatedComponents) {
|
|
234
|
+
it(component.description, async () => {
|
|
235
|
+
const _render13 = render(component.content),
|
|
236
|
+
container = _render13.container;
|
|
237
|
+
const axeCheck = await runAxeCheck(container);
|
|
238
|
+
expect(axeCheck).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _Calendar, _Calendar2, _Calendar3, _Calendar4;
|
|
1
|
+
var _Calendar, _Calendar2, _Calendar3, _Calendar4, _span, _button, _button2, _button3, _button4, _button5, _button6;
|
|
2
2
|
/*
|
|
3
3
|
* The MIT License (MIT)
|
|
4
4
|
*
|
|
@@ -23,10 +23,31 @@ var _Calendar, _Calendar2, _Calendar3, _Calendar4;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
import React from 'react';
|
|
26
|
-
import { render, screen } from '@testing-library/react';
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
27
|
+
import userEvent from '@testing-library/user-event';
|
|
27
28
|
import { vi } from 'vitest';
|
|
28
29
|
import '@testing-library/jest-dom';
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line no-restricted-imports
|
|
32
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
33
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
34
|
+
import CalendarExamples from '../__examples__/Calendar.examples';
|
|
29
35
|
import Calendar from '../index';
|
|
36
|
+
const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
37
|
+
const generateDays = (count = Calendar.DAY_COUNT) => {
|
|
38
|
+
const days = [];
|
|
39
|
+
const date = new Date('2019-07-28');
|
|
40
|
+
while (days.length < count) {
|
|
41
|
+
days.push(/*#__PURE__*/React.createElement(Calendar.Day, {
|
|
42
|
+
key: date.toISOString(),
|
|
43
|
+
date: date.toISOString(),
|
|
44
|
+
label: date.toISOString(),
|
|
45
|
+
isOutsideMonth: date.getMonth() !== 7
|
|
46
|
+
}, date.getDate()));
|
|
47
|
+
date.setDate(date.getDate() + 1);
|
|
48
|
+
}
|
|
49
|
+
return days;
|
|
50
|
+
};
|
|
30
51
|
describe('<Calendar />', () => {
|
|
31
52
|
let consoleWarningMock;
|
|
32
53
|
let consoleErrorMock;
|
|
@@ -85,4 +106,190 @@ describe('<Calendar />', () => {
|
|
|
85
106
|
}
|
|
86
107
|
});
|
|
87
108
|
});
|
|
109
|
+
it('should render children', async () => {
|
|
110
|
+
const _render4 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
111
|
+
renderWeekdayLabels: weekdayLabels
|
|
112
|
+
}, generateDays())),
|
|
113
|
+
container = _render4.container;
|
|
114
|
+
const calendarDays = container.querySelectorAll('span[class$="-calendarDay__day"]');
|
|
115
|
+
expect(calendarDays.length).toEqual(Calendar.DAY_COUNT);
|
|
116
|
+
});
|
|
117
|
+
it(`should warn if the correct number of children are not provided`, async () => {
|
|
118
|
+
const count = Calendar.DAY_COUNT - 1;
|
|
119
|
+
render(/*#__PURE__*/React.createElement(Calendar, {
|
|
120
|
+
renderWeekdayLabels: weekdayLabels
|
|
121
|
+
}, generateDays(count)));
|
|
122
|
+
const expectedErrorMessage = `should have exactly ${Calendar.DAY_COUNT} children. ${count} provided.`;
|
|
123
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
124
|
+
});
|
|
125
|
+
it('should render weekday labels', async () => {
|
|
126
|
+
const _render5 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
127
|
+
renderWeekdayLabels: weekdayLabels
|
|
128
|
+
}, generateDays())),
|
|
129
|
+
container = _render5.container,
|
|
130
|
+
rerender = _render5.rerender;
|
|
131
|
+
const originalHeaders = container.querySelectorAll('th');
|
|
132
|
+
expect(originalHeaders.length).toEqual(7);
|
|
133
|
+
weekdayLabels.forEach((label, i) => {
|
|
134
|
+
expect(originalHeaders[i]).toHaveTextContent(label);
|
|
135
|
+
});
|
|
136
|
+
const functionalWeekdayLabels = [() => 'Sx', () => 'Mx', () => 'Tx', () => 'Wx', () => 'Tx', () => 'Fx', () => 'Sx'];
|
|
137
|
+
|
|
138
|
+
// Set prop: renderWeekdayLabels
|
|
139
|
+
rerender(/*#__PURE__*/React.createElement(Calendar, {
|
|
140
|
+
renderWeekdayLabels: functionalWeekdayLabels
|
|
141
|
+
}, generateDays()));
|
|
142
|
+
const updatedHeaders = container.querySelectorAll('th');
|
|
143
|
+
expect(updatedHeaders.length).toEqual(7);
|
|
144
|
+
functionalWeekdayLabels.forEach((functionalLabel, i) => {
|
|
145
|
+
expect(updatedHeaders[i]).toHaveTextContent(functionalLabel());
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
it('should warn if 7 weekday labels are not provided', async () => {
|
|
149
|
+
render(/*#__PURE__*/React.createElement(Calendar, {
|
|
150
|
+
renderWeekdayLabels: []
|
|
151
|
+
}, generateDays()));
|
|
152
|
+
const expectedErrorMessage = '`renderWeekdayLabels` should be an array with 7 labels (one for each weekday). 0 provided.';
|
|
153
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
154
|
+
});
|
|
155
|
+
it('should format the weekday labels and days correctly', async () => {
|
|
156
|
+
const _render6 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
157
|
+
renderWeekdayLabels: weekdayLabels
|
|
158
|
+
}, generateDays())),
|
|
159
|
+
container = _render6.container;
|
|
160
|
+
const headerRow = container.querySelectorAll('thead > tr');
|
|
161
|
+
expect(headerRow.length).toEqual(1);
|
|
162
|
+
const headers = container.querySelectorAll('thead > tr > th');
|
|
163
|
+
expect(headers.length).toEqual(7);
|
|
164
|
+
const bodyRows = container.querySelectorAll('tbody > tr');
|
|
165
|
+
expect(bodyRows.length).toEqual(Calendar.DAY_COUNT / 7);
|
|
166
|
+
for (const row of bodyRows) {
|
|
167
|
+
const days = row.querySelectorAll('td');
|
|
168
|
+
expect(days.length).toEqual(7);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
it('should render navigation label', async () => {
|
|
172
|
+
const navLabel = _span || (_span = /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("div", null, "March"), /*#__PURE__*/React.createElement("div", null, "2019")));
|
|
173
|
+
const _render7 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
174
|
+
renderWeekdayLabels: weekdayLabels,
|
|
175
|
+
renderNavigationLabel: navLabel
|
|
176
|
+
}, generateDays())),
|
|
177
|
+
rerender = _render7.rerender;
|
|
178
|
+
const month = screen.getByText('March');
|
|
179
|
+
const year = screen.getByText('2019');
|
|
180
|
+
expect(month).toBeInTheDocument();
|
|
181
|
+
expect(year).toBeInTheDocument();
|
|
182
|
+
|
|
183
|
+
// Set prop: renderNavigationLabel
|
|
184
|
+
rerender(/*#__PURE__*/React.createElement(Calendar, {
|
|
185
|
+
renderWeekdayLabels: weekdayLabels,
|
|
186
|
+
renderNavigationLabel: () => navLabel
|
|
187
|
+
}, generateDays()));
|
|
188
|
+
const updatedMonth = screen.getByText('March');
|
|
189
|
+
const updatedYear = screen.getByText('2019');
|
|
190
|
+
expect(updatedMonth).toBeInTheDocument();
|
|
191
|
+
expect(updatedYear).toBeInTheDocument();
|
|
192
|
+
});
|
|
193
|
+
it('should render next and prev buttons', async () => {
|
|
194
|
+
const _render8 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
195
|
+
renderWeekdayLabels: weekdayLabels
|
|
196
|
+
}, generateDays())),
|
|
197
|
+
rerender = _render8.rerender;
|
|
198
|
+
const defaultPrevButton = screen.getByText('Previous month');
|
|
199
|
+
const defaultNextButton = screen.getByText('Next month');
|
|
200
|
+
expect(defaultPrevButton).toBeInTheDocument();
|
|
201
|
+
expect(defaultNextButton).toBeInTheDocument();
|
|
202
|
+
rerender(/*#__PURE__*/React.createElement(Calendar, {
|
|
203
|
+
renderWeekdayLabels: weekdayLabels,
|
|
204
|
+
renderPrevMonthButton: _button || (_button = /*#__PURE__*/React.createElement("button", null, "test-prev")),
|
|
205
|
+
renderNextMonthButton: _button2 || (_button2 = /*#__PURE__*/React.createElement("button", null, "test-next"))
|
|
206
|
+
}, generateDays()));
|
|
207
|
+
const customPrevButton = screen.getByText('test-prev');
|
|
208
|
+
const customNextButton = screen.getByText('test-next');
|
|
209
|
+
expect(customPrevButton).toBeInTheDocument();
|
|
210
|
+
expect(customNextButton).toBeInTheDocument();
|
|
211
|
+
rerender(/*#__PURE__*/React.createElement(Calendar, {
|
|
212
|
+
renderWeekdayLabels: weekdayLabels,
|
|
213
|
+
renderPrevMonthButton: () => _button3 || (_button3 = /*#__PURE__*/React.createElement("button", null, "func-test-prev")),
|
|
214
|
+
renderNextMonthButton: () => _button4 || (_button4 = /*#__PURE__*/React.createElement("button", null, "func-test-next"))
|
|
215
|
+
}, generateDays()));
|
|
216
|
+
const funcPrevButton = screen.getByText('func-test-prev');
|
|
217
|
+
const funcNextButton = screen.getByText('func-test-next');
|
|
218
|
+
expect(funcPrevButton).toBeInTheDocument();
|
|
219
|
+
expect(funcNextButton).toBeInTheDocument();
|
|
220
|
+
});
|
|
221
|
+
it('should call onRequestRenderNextMonth and onRequestRenderPrevMonth', async () => {
|
|
222
|
+
const onRequestRenderPrevMonth = vi.fn();
|
|
223
|
+
const onRequestRenderNextMonth = vi.fn();
|
|
224
|
+
render(/*#__PURE__*/React.createElement(Calendar, {
|
|
225
|
+
renderWeekdayLabels: weekdayLabels,
|
|
226
|
+
renderPrevMonthButton: _button5 || (_button5 = /*#__PURE__*/React.createElement("button", null, "prev month")),
|
|
227
|
+
renderNextMonthButton: _button6 || (_button6 = /*#__PURE__*/React.createElement("button", null, "next month")),
|
|
228
|
+
onRequestRenderPrevMonth: onRequestRenderPrevMonth,
|
|
229
|
+
onRequestRenderNextMonth: onRequestRenderNextMonth
|
|
230
|
+
}, generateDays()));
|
|
231
|
+
const prevButton = screen.getByText('prev month');
|
|
232
|
+
const nextButton = screen.getByText('next month');
|
|
233
|
+
expect(onRequestRenderPrevMonth).not.toHaveBeenCalled();
|
|
234
|
+
expect(onRequestRenderNextMonth).not.toHaveBeenCalled();
|
|
235
|
+
await userEvent.click(prevButton);
|
|
236
|
+
await userEvent.click(nextButton);
|
|
237
|
+
await waitFor(() => {
|
|
238
|
+
expect(onRequestRenderPrevMonth).toHaveBeenCalledTimes(1);
|
|
239
|
+
expect(onRequestRenderNextMonth).toHaveBeenCalledTimes(1);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
describe('when role="listbox"', () => {
|
|
243
|
+
it('should set role="listbox" on table root and role="presentation" on the correct elements', async () => {
|
|
244
|
+
const _render9 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
245
|
+
renderWeekdayLabels: weekdayLabels,
|
|
246
|
+
role: "listbox"
|
|
247
|
+
}, generateDays())),
|
|
248
|
+
container = _render9.container;
|
|
249
|
+
const table = container.querySelector('table');
|
|
250
|
+
expect(table).toHaveAttribute('role', 'listbox');
|
|
251
|
+
const rows = container.querySelectorAll('tbody > tr');
|
|
252
|
+
for (const row of rows) {
|
|
253
|
+
expect(row).toHaveAttribute('role', 'presentation');
|
|
254
|
+
const tds = row.querySelectorAll('td');
|
|
255
|
+
tds.forEach(td => {
|
|
256
|
+
expect(td).toHaveAttribute('role', 'presentation');
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
it("should link each day with it's weekday header via `aria-describedby`", async () => {
|
|
261
|
+
const _render10 = render(/*#__PURE__*/React.createElement(Calendar, {
|
|
262
|
+
renderWeekdayLabels: weekdayLabels,
|
|
263
|
+
role: "listbox"
|
|
264
|
+
}, generateDays())),
|
|
265
|
+
container = _render10.container;
|
|
266
|
+
const days = container.querySelectorAll('tbody > tr > td');
|
|
267
|
+
const headers = container.querySelectorAll('th');
|
|
268
|
+
days.forEach((dayTd, i) => {
|
|
269
|
+
const index = i % 7;
|
|
270
|
+
const day = dayTd.querySelector('span[class$="-calendarDay"]');
|
|
271
|
+
expect(day).toHaveAttribute('aria-describedby', headers[index].getAttribute('id'));
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
it('should render root as designated by the `as` prop', async () => {
|
|
276
|
+
render(/*#__PURE__*/React.createElement(Calendar, {
|
|
277
|
+
renderWeekdayLabels: weekdayLabels,
|
|
278
|
+
as: "ul"
|
|
279
|
+
}, generateDays()));
|
|
280
|
+
const calendar = screen.getByRole('list');
|
|
281
|
+
expect(calendar.tagName).toBe('UL');
|
|
282
|
+
expect(calendar).toHaveTextContent(weekdayLabels.join(''));
|
|
283
|
+
});
|
|
284
|
+
describe('with generated examples', () => {
|
|
285
|
+
const generatedComponents = generateA11yTests(Calendar, CalendarExamples);
|
|
286
|
+
for (const component of generatedComponents) {
|
|
287
|
+
it(component.description, async () => {
|
|
288
|
+
const _render11 = render(component.content),
|
|
289
|
+
container = _render11.container;
|
|
290
|
+
const axeCheck = await runAxeCheck(container);
|
|
291
|
+
expect(axeCheck).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
88
295
|
});
|