react-day-picker 8.4.1 → 8.5.0
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/dist/index.d.ts +123 -70
- package/dist/index.esm.js +14 -50
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +122 -158
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/style.css +2 -1
- package/dist/style.css.d.ts +38 -37
- package/dist/style.css.map +1 -0
- package/dist/style.module.css +0 -1
- package/dist/style.module.css.d.ts +38 -37
- package/package.json +34 -32
- package/src/DayPicker.tsx +1 -1
- package/src/components/Caption/Caption.test.tsx +2 -2
- package/src/components/CaptionDropdowns/CaptionDropdowns.test.tsx +7 -6
- package/src/components/CaptionLabel/CaptionLabel.test.tsx +1 -1
- package/src/components/CaptionLabel/CaptionLabel.tsx +3 -3
- package/src/components/CaptionNavigation/CaptionNavigation.test.tsx +11 -10
- package/src/components/CaptionNavigation/CaptionNavigation.tsx +1 -1
- package/src/components/Day/Day.test.tsx +15 -16
- package/src/components/Day/Day.tsx +1 -1
- package/src/components/DayContent/DayContent.test.tsx +1 -1
- package/src/components/Footer/Footer.test.tsx +1 -1
- package/src/components/HeadRow/HeadRow.test.tsx +1 -20
- package/src/components/HeadRow/HeadRow.tsx +2 -6
- package/src/components/HeadRow/utils/getWeekdays.test.ts +1 -1
- package/src/components/HeadRow/utils/getWeekdays.ts +1 -5
- package/src/components/Month/Month.test.tsx +1 -1
- package/src/components/MonthsDropdown/MonthsDropdown.test.tsx +3 -2
- package/src/components/MonthsDropdown/MonthsDropdown.tsx +1 -3
- package/src/components/Navigation/Navigation.test.tsx +10 -9
- package/src/components/Root/Root.test.tsx +2 -3
- package/src/components/Row/Row.tsx +2 -1
- package/src/components/Table/Table.tsx +1 -1
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +219 -210
- package/src/components/Table/utils/daysToMonthWeeks.ts +11 -10
- package/src/components/Table/utils/getMonthWeeks.ts +7 -6
- package/src/components/YearsDropdown/YearsDropdown.test.tsx +3 -2
- package/src/components/YearsDropdown/YearsDropdown.tsx +1 -3
- package/src/contexts/DayPicker/DayPickerContext.test.ts +55 -138
- package/src/contexts/DayPicker/defaultContextValues.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatCaption.test.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatCaption.ts +1 -2
- package/src/contexts/DayPicker/formatters/formatDay.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatMonthCaption.test.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatMonthCaption.ts +1 -1
- package/src/contexts/DayPicker/formatters/formatWeekdayName.test.ts +3 -3
- package/src/contexts/DayPicker/formatters/formatWeekdayName.ts +2 -2
- package/src/contexts/DayPicker/formatters/formatYearCaption.ts +1 -1
- package/src/contexts/DayPicker/labels/labelDay.ts +1 -1
- package/src/contexts/DayPicker/labels/labelWeekday.test.ts +1 -1
- package/src/contexts/DayPicker/labels/labelWeekday.ts +1 -1
- package/src/contexts/DayPicker/utils/parseFromToProps.ts +1 -3
- package/src/contexts/Focus/FocusContext.test.ts +35 -62
- package/src/contexts/Focus/FocusContext.tsx +1 -1
- package/src/contexts/Focus/utils/getInitialFocusTarget.ts +1 -3
- package/src/contexts/Focus/utils/getNextFocus.ts +12 -10
- package/src/contexts/Modifiers/ModifiersContext.test.ts +8 -14
- package/src/contexts/Modifiers/utils/getActiveModifiers.ts +1 -1
- package/src/contexts/Modifiers/utils/isDateInRange.ts +1 -2
- package/src/contexts/Modifiers/utils/isMatch.ts +1 -4
- package/src/contexts/Navigation/NavigationContext.test.ts +12 -17
- package/src/contexts/Navigation/NavigationContext.tsx +1 -3
- package/src/contexts/Navigation/useNavigationState.test.ts +9 -16
- package/src/contexts/Navigation/useNavigationState.ts +6 -4
- package/src/contexts/Navigation/utils/getDisplayMonths.ts +1 -3
- package/src/contexts/Navigation/utils/getInitialMonth.ts +1 -3
- package/src/contexts/Navigation/utils/getNextMonth.ts +1 -3
- package/src/contexts/Navigation/utils/getPreviousMonth.ts +1 -3
- package/src/contexts/SelectMultiple/SelectMultipleContext.test.ts +15 -20
- package/src/contexts/SelectMultiple/SelectMultipleContext.tsx +1 -1
- package/src/contexts/SelectRange/SelectRangeContext.test.ts +23 -29
- package/src/contexts/SelectRange/SelectRangeContext.tsx +6 -4
- package/src/contexts/SelectRange/utils/addToRange.ts +1 -3
- package/src/contexts/SelectSingle/SelectSingleContext.test.ts +18 -15
- package/src/hooks/useActiveModifiers/useActiveModifiers.test.tsx +9 -16
- package/src/hooks/useControlledValue/useControlledValue.test.ts +16 -39
- package/src/hooks/useDayEventHandlers/useDayEventHandlers.test.tsx +18 -78
- package/src/hooks/useDayRender/useDayRender.test.tsx +68 -95
- package/src/hooks/useDayRender/useDayRender.tsx +5 -8
- package/src/hooks/useInput/useInput.ts +2 -4
- package/src/hooks/useSelectedDays/useSelectedDays.test.ts +15 -45
- package/src/index.ts +1 -0
- package/src/style.css +0 -1
- package/src/style.css.d.ts +37 -36
- package/src/types/Labels.ts +1 -0
- package/dist/index.esm.d.ts +0 -1175
- package/dist/react-day-picker.min.js +0 -1
|
@@ -5,13 +5,13 @@ import userEvent from '@testing-library/user-event';
|
|
|
5
5
|
import { setMonth, setYear } from 'date-fns';
|
|
6
6
|
import { DayPickerProps } from 'DayPicker';
|
|
7
7
|
|
|
8
|
+
import { customRender } from 'test/render';
|
|
8
9
|
import {
|
|
9
10
|
getMonthDropdown,
|
|
10
11
|
getYearDropdown,
|
|
11
12
|
queryMonthDropdown,
|
|
12
13
|
queryYearDropdown
|
|
13
|
-
} from 'test/
|
|
14
|
-
import { customRender } from 'test/render';
|
|
14
|
+
} from 'test/selectors';
|
|
15
15
|
import { freezeBeforeAll } from 'test/utils';
|
|
16
16
|
|
|
17
17
|
import { CaptionProps } from 'components/Caption';
|
|
@@ -25,6 +25,7 @@ const toYear = 2025;
|
|
|
25
25
|
|
|
26
26
|
freezeBeforeAll(today);
|
|
27
27
|
|
|
28
|
+
const user = userEvent.setup();
|
|
28
29
|
function setup(props: CaptionProps, dayPickerProps?: DayPickerProps) {
|
|
29
30
|
customRender(<CaptionDropdowns {...props} />, dayPickerProps);
|
|
30
31
|
}
|
|
@@ -85,8 +86,8 @@ describe('when a month is selected', () => {
|
|
|
85
86
|
});
|
|
86
87
|
describe('from the months drop-down', () => {
|
|
87
88
|
const newMonth = setMonth(today, 0);
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
|
|
89
|
+
beforeEach(async () => {
|
|
90
|
+
await user.selectOptions(
|
|
90
91
|
getMonthDropdown(),
|
|
91
92
|
newMonth.getMonth().toString()
|
|
92
93
|
);
|
|
@@ -97,8 +98,8 @@ describe('when a month is selected', () => {
|
|
|
97
98
|
});
|
|
98
99
|
describe('from the years drop-down', () => {
|
|
99
100
|
const newYear = setYear(today, 2022);
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
|
|
101
|
+
beforeEach(async () => {
|
|
102
|
+
await user.selectOptions(
|
|
102
103
|
getYearDropdown(),
|
|
103
104
|
newYear.getFullYear().toString()
|
|
104
105
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { getMonthCaption } from 'test/po';
|
|
4
3
|
import { customRender } from 'test/render';
|
|
4
|
+
import { getMonthCaption } from 'test/selectors';
|
|
5
5
|
import { freezeBeforeAll } from 'test/utils';
|
|
6
6
|
|
|
7
7
|
import { CaptionLabel } from './CaptionLabel';
|
|
@@ -19,14 +19,14 @@ export function CaptionLabel(props: CaptionLabelProps): JSX.Element {
|
|
|
19
19
|
formatters: { formatCaption }
|
|
20
20
|
} = useDayPicker();
|
|
21
21
|
return (
|
|
22
|
-
<
|
|
22
|
+
<div
|
|
23
23
|
className={classNames.caption_label}
|
|
24
24
|
style={styles.caption_label}
|
|
25
25
|
aria-live="polite"
|
|
26
|
-
|
|
26
|
+
role="presentation"
|
|
27
27
|
id={props.id}
|
|
28
28
|
>
|
|
29
29
|
{formatCaption(props.displayMonth, { locale })}
|
|
30
|
-
</
|
|
30
|
+
</div>
|
|
31
31
|
);
|
|
32
32
|
}
|
|
@@ -5,14 +5,14 @@ import userEvent from '@testing-library/user-event';
|
|
|
5
5
|
import { addMonths } from 'date-fns';
|
|
6
6
|
import { DayPickerProps } from 'DayPicker';
|
|
7
7
|
|
|
8
|
+
import { customRender } from 'test/render';
|
|
8
9
|
import {
|
|
9
10
|
getMonthCaption,
|
|
10
11
|
getNextButton,
|
|
11
12
|
getPrevButton,
|
|
12
13
|
queryNextButton,
|
|
13
14
|
queryPrevButton
|
|
14
|
-
} from 'test/
|
|
15
|
-
import { customRender } from 'test/render';
|
|
15
|
+
} from 'test/selectors';
|
|
16
16
|
import { freezeBeforeAll } from 'test/utils';
|
|
17
17
|
|
|
18
18
|
import { CaptionProps } from 'components/Caption';
|
|
@@ -24,6 +24,7 @@ const today = new Date(2021, 8);
|
|
|
24
24
|
|
|
25
25
|
freezeBeforeAll(today);
|
|
26
26
|
|
|
27
|
+
const user = userEvent.setup();
|
|
27
28
|
function setup(props: CaptionProps, dayPickerProps?: DayPickerProps) {
|
|
28
29
|
customRender(<CaptionNavigation {...props} />, dayPickerProps);
|
|
29
30
|
}
|
|
@@ -115,9 +116,9 @@ describe('when rendered', () => {
|
|
|
115
116
|
onMonthChange: jest.fn()
|
|
116
117
|
};
|
|
117
118
|
const previousMonth = addMonths(today, -1);
|
|
118
|
-
beforeEach(() => {
|
|
119
|
+
beforeEach(async () => {
|
|
119
120
|
customRender(<CaptionNavigation displayMonth={today} />, testContext);
|
|
120
|
-
|
|
121
|
+
await user.click(getPrevButton());
|
|
121
122
|
});
|
|
122
123
|
test('should call the `onMonthChange` callback', () => {
|
|
123
124
|
expect(testContext.onMonthChange).toHaveBeenCalledWith(previousMonth);
|
|
@@ -129,9 +130,9 @@ describe('when rendered', () => {
|
|
|
129
130
|
fromDate: today,
|
|
130
131
|
onMonthChange: jest.fn()
|
|
131
132
|
};
|
|
132
|
-
beforeEach(() => {
|
|
133
|
+
beforeEach(async () => {
|
|
133
134
|
customRender(<CaptionNavigation displayMonth={today} />, testContext);
|
|
134
|
-
|
|
135
|
+
await user.click(getPrevButton());
|
|
135
136
|
});
|
|
136
137
|
test('should call the `onMonthChange` callback', () => {
|
|
137
138
|
expect(testContext.onMonthChange).not.toHaveBeenCalled();
|
|
@@ -146,9 +147,9 @@ describe('when rendered', () => {
|
|
|
146
147
|
onMonthChange: jest.fn()
|
|
147
148
|
};
|
|
148
149
|
const nextMonth = addMonths(today, 1);
|
|
149
|
-
beforeEach(() => {
|
|
150
|
+
beforeEach(async () => {
|
|
150
151
|
customRender(<CaptionNavigation displayMonth={today} />, testContext);
|
|
151
|
-
|
|
152
|
+
await user.click(getNextButton());
|
|
152
153
|
});
|
|
153
154
|
test('should call the `onMonthChange` callback', () => {
|
|
154
155
|
expect(testContext.onMonthChange).toHaveBeenCalledWith(nextMonth);
|
|
@@ -160,9 +161,9 @@ describe('when rendered', () => {
|
|
|
160
161
|
toDate: today,
|
|
161
162
|
onMonthChange: jest.fn()
|
|
162
163
|
};
|
|
163
|
-
beforeEach(() => {
|
|
164
|
+
beforeEach(async () => {
|
|
164
165
|
customRender(<CaptionNavigation displayMonth={today} />, testContext);
|
|
165
|
-
|
|
166
|
+
await user.click(getNextButton());
|
|
166
167
|
});
|
|
167
168
|
test('should call the `onMonthChange` callback', () => {
|
|
168
169
|
expect(testContext.onMonthChange).not.toHaveBeenCalled();
|
|
@@ -13,11 +13,6 @@ import { Day, DayProps } from './Day';
|
|
|
13
13
|
const today = new Date(2021, 8);
|
|
14
14
|
|
|
15
15
|
freezeBeforeAll(today);
|
|
16
|
-
let container: HTMLElement;
|
|
17
|
-
function setup(props: DayProps, dayPickerProps?: DayPickerProps) {
|
|
18
|
-
const view = customRender(<Day {...props} />, dayPickerProps);
|
|
19
|
-
container = view.container;
|
|
20
|
-
}
|
|
21
16
|
|
|
22
17
|
const date = today;
|
|
23
18
|
const displayMonth = today;
|
|
@@ -31,19 +26,21 @@ describe('when the day to render has an hidden modifier', () => {
|
|
|
31
26
|
modifiers: { hidden: date }
|
|
32
27
|
};
|
|
33
28
|
beforeEach(() => {
|
|
34
|
-
|
|
29
|
+
customRender(<Day {...props} />, dayPickerProps);
|
|
35
30
|
});
|
|
36
|
-
test('should render an empty
|
|
37
|
-
|
|
31
|
+
test('should render an empty grid cell', () => {
|
|
32
|
+
const cell = screen.getByRole('gridcell');
|
|
33
|
+
expect(cell).toBeEmptyDOMElement();
|
|
38
34
|
});
|
|
39
35
|
});
|
|
40
36
|
describe('when a no selection mode and no "onDayClick"', () => {
|
|
41
37
|
const dayPickerProps: DayPickerProps = { mode: 'default' };
|
|
42
38
|
beforeEach(() => {
|
|
43
|
-
|
|
39
|
+
customRender(<Day {...props} />, dayPickerProps);
|
|
44
40
|
});
|
|
45
41
|
test('should render a div', () => {
|
|
46
|
-
|
|
42
|
+
const cell = screen.getByRole('gridcell');
|
|
43
|
+
expect(cell.nodeName).toBe('DIV');
|
|
47
44
|
});
|
|
48
45
|
});
|
|
49
46
|
|
|
@@ -52,11 +49,12 @@ describe('when a selection mode is set', () => {
|
|
|
52
49
|
mode: 'single'
|
|
53
50
|
};
|
|
54
51
|
beforeEach(() => {
|
|
55
|
-
|
|
52
|
+
customRender(<Day {...props} />, dayPickerProps);
|
|
56
53
|
});
|
|
57
54
|
test('should render a button named "day"', () => {
|
|
58
|
-
|
|
59
|
-
expect(
|
|
55
|
+
const cell = screen.getByRole('gridcell');
|
|
56
|
+
expect(cell.nodeName).toBe('BUTTON');
|
|
57
|
+
expect(cell).toHaveAttribute('name', 'day');
|
|
60
58
|
});
|
|
61
59
|
});
|
|
62
60
|
|
|
@@ -65,10 +63,11 @@ describe('when "onDayClick" is present', () => {
|
|
|
65
63
|
onDayClick: jest.fn()
|
|
66
64
|
};
|
|
67
65
|
beforeEach(() => {
|
|
68
|
-
|
|
66
|
+
customRender(<Day {...props} />, dayPickerProps);
|
|
69
67
|
});
|
|
70
68
|
test('should render a button', () => {
|
|
71
|
-
|
|
69
|
+
const cell = screen.getByRole('gridcell');
|
|
70
|
+
expect(cell.nodeName).toBe('BUTTON');
|
|
72
71
|
});
|
|
73
72
|
});
|
|
74
73
|
|
|
@@ -77,7 +76,7 @@ describe('when using a custom DayContent component', () => {
|
|
|
77
76
|
DayContent: () => <>Custom DayContent</>
|
|
78
77
|
};
|
|
79
78
|
beforeEach(() => {
|
|
80
|
-
|
|
79
|
+
customRender(<Day {...props} />, { components });
|
|
81
80
|
});
|
|
82
81
|
test('it should render the custom component instead', () => {
|
|
83
82
|
expect(screen.getByText('Custom DayContent')).toBeInTheDocument();
|
|
@@ -21,7 +21,7 @@ export function Day(props: DayProps): JSX.Element {
|
|
|
21
21
|
const dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
|
|
22
22
|
|
|
23
23
|
if (dayRender.isHidden) {
|
|
24
|
-
return
|
|
24
|
+
return <div role="gridcell"></div>;
|
|
25
25
|
}
|
|
26
26
|
if (!dayRender.isButton) {
|
|
27
27
|
return <div {...dayRender.divProps} />;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { RenderResult
|
|
3
|
+
import { RenderResult } from '@testing-library/react';
|
|
4
4
|
import { DayPickerProps } from 'DayPicker';
|
|
5
5
|
|
|
6
6
|
import { customRender } from 'test/render';
|
|
7
7
|
|
|
8
|
-
import { defaultClassNames } from 'contexts/DayPicker/defaultClassNames';
|
|
9
|
-
import { formatWeekdayName } from 'contexts/DayPicker/formatters';
|
|
10
|
-
import { labelWeekday } from 'contexts/DayPicker/labels';
|
|
11
|
-
|
|
12
8
|
import { HeadRow } from './HeadRow';
|
|
13
|
-
import { getWeekdays } from './utils/getWeekdays';
|
|
14
9
|
|
|
15
10
|
let container: HTMLElement;
|
|
16
11
|
let view: RenderResult;
|
|
@@ -65,20 +60,6 @@ describe('when rendered', () => {
|
|
|
65
60
|
expect(el).toHaveClass(dayPickerProps.classNames.head_cell);
|
|
66
61
|
});
|
|
67
62
|
});
|
|
68
|
-
test('the formatted weekday name should be ARIA-hidden', () => {
|
|
69
|
-
const weekdays = getWeekdays();
|
|
70
|
-
weekdays.forEach((weekday) => {
|
|
71
|
-
const text = formatWeekdayName(weekday);
|
|
72
|
-
expect(screen.getByText(text)).toHaveAttribute('aria-hidden', 'true');
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
test('the label should not be visible', () => {
|
|
76
|
-
const weekdays = getWeekdays();
|
|
77
|
-
weekdays.forEach((weekday) => {
|
|
78
|
-
const text = labelWeekday(weekday);
|
|
79
|
-
expect(screen.getByText(text)).toHaveClass(defaultClassNames.vhidden);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
63
|
});
|
|
83
64
|
|
|
84
65
|
describe('when showing the week numbers', () => {
|
|
@@ -36,13 +36,9 @@ export function HeadRow(): JSX.Element {
|
|
|
36
36
|
scope="col"
|
|
37
37
|
className={classNames.head_cell}
|
|
38
38
|
style={styles.head_cell}
|
|
39
|
+
aria-label={labelWeekday(weekday, { locale })}
|
|
39
40
|
>
|
|
40
|
-
|
|
41
|
-
{formatWeekdayName(weekday, { locale })}
|
|
42
|
-
</span>
|
|
43
|
-
<span className={classNames.vhidden}>
|
|
44
|
-
{labelWeekday(weekday, { locale })}
|
|
45
|
-
</span>
|
|
41
|
+
{formatWeekdayName(weekday, { locale })}
|
|
46
42
|
</th>
|
|
47
43
|
))}
|
|
48
44
|
</tr>
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import addDays from 'date-fns
|
|
2
|
-
import startOfISOWeek from 'date-fns/startOfISOWeek';
|
|
3
|
-
import startOfWeek from 'date-fns/startOfWeek';
|
|
4
|
-
|
|
5
|
-
import type { Locale } from 'date-fns';
|
|
1
|
+
import { addDays, Locale, startOfISOWeek, startOfWeek } from 'date-fns';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Generate a series of 7 days, starting from the week, to use for formatting
|
|
@@ -3,8 +3,8 @@ import React from 'react';
|
|
|
3
3
|
import { screen } from '@testing-library/react';
|
|
4
4
|
import { DayPickerProps } from 'DayPicker';
|
|
5
5
|
|
|
6
|
-
import { getMonthCaption, getMonthGrid } from 'test/po';
|
|
7
6
|
import { customRender } from 'test/render';
|
|
7
|
+
import { getMonthCaption, getMonthGrid } from 'test/selectors';
|
|
8
8
|
|
|
9
9
|
import { CustomComponents } from 'types/DayPickerBase';
|
|
10
10
|
|
|
@@ -18,6 +18,7 @@ let root: HTMLDivElement;
|
|
|
18
18
|
let options: HTMLCollectionOf<HTMLOptionElement> | undefined;
|
|
19
19
|
let select: HTMLSelectElement | null;
|
|
20
20
|
|
|
21
|
+
const user = userEvent.setup();
|
|
21
22
|
function setup(props: MonthsDropdownProps, dayPickerProps?: DayPickerProps) {
|
|
22
23
|
const view = customRender(<MonthsDropdown {...props} />, dayPickerProps);
|
|
23
24
|
root = view.container.firstChild as HTMLDivElement;
|
|
@@ -98,8 +99,8 @@ describe('when "fromDate" and "toDate" are not in the same year', () => {
|
|
|
98
99
|
});
|
|
99
100
|
|
|
100
101
|
describe('when the dropdown changes', () => {
|
|
101
|
-
beforeEach(() => {
|
|
102
|
-
if (select)
|
|
102
|
+
beforeEach(async () => {
|
|
103
|
+
if (select) await user.selectOptions(select, 'February');
|
|
103
104
|
});
|
|
104
105
|
test('should fire the "onChange" event handler', () => {
|
|
105
106
|
const expectedMonth = new Date(2015, 1, 1);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import isSameYear from 'date-fns
|
|
4
|
-
import setMonth from 'date-fns/setMonth';
|
|
5
|
-
import startOfMonth from 'date-fns/startOfMonth';
|
|
3
|
+
import { isSameYear, setMonth, startOfMonth } from 'date-fns';
|
|
6
4
|
|
|
7
5
|
import { Dropdown } from 'components/Dropdown';
|
|
8
6
|
import { useDayPicker } from 'contexts/DayPicker';
|
|
@@ -3,13 +3,14 @@ import React from 'react';
|
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import { DayPickerProps } from 'DayPicker';
|
|
5
5
|
|
|
6
|
-
import { getNextButton, getPrevButton } from 'test/po';
|
|
7
6
|
import { customRender } from 'test/render';
|
|
7
|
+
import { getNextButton, getPrevButton } from 'test/selectors';
|
|
8
8
|
|
|
9
9
|
import { Navigation, NavigationProps } from './Navigation';
|
|
10
10
|
|
|
11
11
|
let root: HTMLElement;
|
|
12
12
|
|
|
13
|
+
const user = userEvent.setup();
|
|
13
14
|
function setup(props: NavigationProps, dayPickerProps?: DayPickerProps) {
|
|
14
15
|
const view = customRender(<Navigation {...props} />, dayPickerProps);
|
|
15
16
|
root = view.container.firstChild as HTMLElement;
|
|
@@ -62,16 +63,16 @@ describe('when rendered', () => {
|
|
|
62
63
|
test('the next button should be named "next-month"', () => {
|
|
63
64
|
expect(getNextButton()).toHaveAttribute('name', 'next-month');
|
|
64
65
|
});
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
|
|
66
|
+
beforeEach(async () => {
|
|
67
|
+
await user.click(getPrevButton());
|
|
67
68
|
});
|
|
68
69
|
test('should call "onPreviousClick"', () => {
|
|
69
70
|
expect(props.onPreviousClick).toHaveBeenCalled();
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
describe('when clicking the next button', () => {
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
|
|
74
|
+
beforeEach(async () => {
|
|
75
|
+
await user.click(getNextButton());
|
|
75
76
|
});
|
|
76
77
|
test('should call "onNextClick"', () => {
|
|
77
78
|
expect(props.onNextClick).toHaveBeenCalled();
|
|
@@ -93,16 +94,16 @@ describe('when in right-to-left direction', () => {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
describe('when clicking the previous button', () => {
|
|
96
|
-
beforeEach(() => {
|
|
97
|
-
|
|
97
|
+
beforeEach(async () => {
|
|
98
|
+
await user.click(getPrevButton());
|
|
98
99
|
});
|
|
99
100
|
test('should call "onPreviousClick"', () => {
|
|
100
101
|
expect(props.onPreviousClick).toHaveBeenCalled();
|
|
101
102
|
});
|
|
102
103
|
});
|
|
103
104
|
describe('when clicking the next button', () => {
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
|
|
105
|
+
beforeEach(async () => {
|
|
106
|
+
await user.click(getNextButton());
|
|
106
107
|
});
|
|
107
108
|
test('should call "onNextClick"', () => {
|
|
108
109
|
expect(props.onNextClick).toHaveBeenCalled();
|
|
@@ -4,9 +4,8 @@ import { RenderResult } from '@testing-library/react';
|
|
|
4
4
|
import { addDays } from 'date-fns';
|
|
5
5
|
import { DayPickerProps } from 'DayPicker';
|
|
6
6
|
|
|
7
|
-
import { focusDay } from 'test/actions';
|
|
8
|
-
import { getDayButton, queryMonthGrids } from 'test/po';
|
|
9
7
|
import { customRender } from 'test/render';
|
|
8
|
+
import { getDayButton, queryMonthGrids } from 'test/selectors';
|
|
10
9
|
import { freezeBeforeAll } from 'test/utils';
|
|
11
10
|
|
|
12
11
|
import { defaultClassNames } from 'contexts/DayPicker/defaultClassNames';
|
|
@@ -103,7 +102,7 @@ describe('when "initialFocus" is set', () => {
|
|
|
103
102
|
});
|
|
104
103
|
describe('when a new day is focused', () => {
|
|
105
104
|
beforeEach(() => {
|
|
106
|
-
|
|
105
|
+
getDayButton(addDays(today, 1)).focus();
|
|
107
106
|
});
|
|
108
107
|
describe('and the calendar is rerendered', () => {
|
|
109
108
|
test.todo('should focus the new day');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import getUnixTime from 'date-fns
|
|
3
|
+
import { getUnixTime } from 'date-fns';
|
|
4
4
|
|
|
5
5
|
import { Day } from 'components/Day';
|
|
6
6
|
import { WeekNumber } from 'components/WeekNumber';
|
|
@@ -42,6 +42,7 @@ export function Row(props: RowProps): JSX.Element {
|
|
|
42
42
|
className={classNames.cell}
|
|
43
43
|
style={styles.cell}
|
|
44
44
|
key={getUnixTime(date)}
|
|
45
|
+
role="presentation"
|
|
45
46
|
>
|
|
46
47
|
<DayComponent displayMonth={props.displayMonth} date={date} />
|
|
47
48
|
</td>
|
|
@@ -48,7 +48,7 @@ export function Table(props: TableProps): JSX.Element {
|
|
|
48
48
|
aria-labelledby={props['aria-labelledby']}
|
|
49
49
|
>
|
|
50
50
|
{!hideHead && <HeadComponent />}
|
|
51
|
-
<tbody className={classNames.tbody} style={styles.tbody}>
|
|
51
|
+
<tbody className={classNames.tbody} style={styles.tbody} role="rowgroup">
|
|
52
52
|
{weeks.map((week) => (
|
|
53
53
|
<RowComponent
|
|
54
54
|
displayMonth={props.displayMonth}
|