Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-migration] some tests #4881

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ const babelTargetList = [
"helper_components/custom_input\\.tsx",
"calendar_test\\.test\\.tsx",
"datepicker_test\\.test\\.tsx",
"min_time_test\\.test\\.tsx",
"month_test\\.test\\.tsx",
"multi_month_test\\.test\\.tsx",
"multiple_selected_dates\\.test\\.tsx",
"week_number_test\\.test\\.tsx",
];

const tsTargetList = [
Expand All @@ -26,19 +21,19 @@ const tsTargetList = [
"include_times_test\\.test\\.tsx",
"index\\.ts",
"inject_times_test\\.test\\.tsx",
// "min_time_test\\.test\\.tsx",
"min_time_test\\.test\\.tsx",
"month_dropdown_test\\.test\\.tsx",
// "month_test\\.test\\.tsx",
"month_test\\.test\\.tsx",
"month_year_dropdown_test\\.test\\.tsx",
// "multi_month_test\\.test\\.tsx",
// "multiple_selected_dates\\.test\\.tsx",
"multi_month_test\\.test\\.tsx",
"multiple_selected_dates\\.test\\.tsx",
"run_axe\\.tsx",
"show_time_test\\.test\\.tsx",
"test_utils\\.ts",
"time_format_test\\.test\\.tsx",
"time_input_test\\.test\\.tsx",
"timepicker_test\\.test\\.tsx",
// "week_number_test\\.test\\.tsx",
"week_number_test\\.test\\.tsx",
"week_picker_test\\.test\\.tsx",
"week_test\\.test\\.tsx",
"year_dropdown_options_test\\.test\\.tsx",
Expand Down
10 changes: 7 additions & 3 deletions src/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type CalendarProps = React.PropsWithChildren &
showTimeInput?: boolean;
showYearDropdown?: boolean;
showMonthDropdown?: boolean;
yearItemNumber: number;
yearItemNumber?: number;
useWeekdaysShort?: boolean;
forceShowMonthNavigation?: boolean;
showDisabledMonthNavigation?: boolean;
Expand Down Expand Up @@ -498,7 +498,9 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
({ date }) => ({
date: subYears(
date,
this.props.showYearPicker ? this.props.yearItemNumber : 1,
this.props.showYearPicker
? this.props.yearItemNumber ?? Calendar.defaultProps.yearItemNumber
yuki0410-dev marked this conversation as resolved.
Show resolved Hide resolved
: 1,
),
}),
() => this.handleYearChange(this.state.date),
Expand Down Expand Up @@ -606,7 +608,9 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
({ date }) => ({
date: addYears(
date,
this.props.showYearPicker ? this.props.yearItemNumber : 1,
this.props.showYearPicker
? this.props.yearItemNumber ?? Calendar.defaultProps.yearItemNumber
: 1,
),
}),
() => this.handleYearChange(this.state.date),
Expand Down
14 changes: 11 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
| "setPreSelection"
| "selectsRange"
| "selectsMultiple"
| "dropdownMode"
> &
Pick<AdditionalProps, "excludeScrollbar"> &
Pick<CalendarIconProps, "icon"> &
Expand All @@ -135,9 +136,10 @@
| "popperOnKeyDown"
| "showArrow"
> & {
dateFormatCalendar: CalendarProps["dateFormat"];
dateFormatCalendar?: CalendarProps["dateFormat"];
calendarClassName?: CalendarProps["className"];
calendarContainer?: CalendarProps["container"];
dropdownMode?: CalendarProps["dropdownMode"];
onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;
popperClassName?: PopperComponentProps["className"];
showPopperArrow?: PopperComponentProps["showArrow"];
Expand Down Expand Up @@ -260,7 +262,7 @@
onChange() {},
disabled: false,
disabledKeyboardNavigation: false,
dropdownMode: "scroll",
dropdownMode: "scroll" as const,
onFocus() {},
onBlur() {},
onKeyDown() {},
Expand Down Expand Up @@ -1199,7 +1201,10 @@
{...this.props}
{...this.state}
setOpen={this.setOpen}
dateFormat={this.props.dateFormatCalendar}
dateFormat={
this.props.dateFormatCalendar ??
DatePicker.defaultProps.dateFormatCalendar

Check warning on line 1206 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L1206

Added line #L1206 was not covered by tests
}
onSelect={this.handleSelect}
onClickOutside={this.handleCalendarClickOutside}
holidays={getHolidaysMap(this.modifyHolidays())}
Expand All @@ -1211,6 +1216,9 @@
handleOnKeyDown={this.props.onKeyDown}
handleOnDayKeyDown={this.onDayKeyDown}
setPreSelection={this.setPreSelection}
dropdownMode={
this.props.dropdownMode ?? DatePicker.defaultProps.dropdownMode
}
>
{this.props.children}
</WrappedCalendar>
Expand Down
26 changes: 22 additions & 4 deletions src/test/min_time_test.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@ import React, { useState } from "react";

import DatePicker from "../index";

const DatePickerWithState = (props) => {
import type { DatePickerProps } from "../index";

const DatePickerWithState = (
props: Partial<
Pick<DatePickerProps, "open" | "selected" | "showTimeSelect" | "dateFormat">
> &
Omit<
DatePickerProps,
| "open"
| "selected"
| "onChange"
| "showTimeSelect"
| "dateFormat"
| "selectsRange"
| "selectsMultiple"
| "onSelect"
>,
) => {
const [selected, setSelected] = useState<Date | null>(null);
return (
<DatePicker
open
selected={selected}
onChange={(date) => {
onChange={(date: Date | null) => {
setSelected(date);
}}
showTimeSelect
dateFormat="MM/dd/yyyy HH:mm"
onSelect={() => {}}
{...props}
/>
);
Expand All @@ -23,7 +41,7 @@ describe("Datepicker minTime", () => {
it("should select time 12:00 AM when no minTime constraint is set.", () => {
const { getByText, container } = render(<DatePickerWithState />);

const day = container.getElementsByClassName("react-datepicker__day")[0];
const day = container.getElementsByClassName("react-datepicker__day")[0]!;

fireEvent.click(day);

Expand All @@ -40,7 +58,7 @@ describe("Datepicker minTime", () => {
<DatePickerWithState minTime={minTime} maxTime={maxTime} />,
);

const day = container.getElementsByClassName("react-datepicker__day")[0];
const day = container.getElementsByClassName("react-datepicker__day")[0]!;

fireEvent.click(day);

Expand Down
Loading
Loading