-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add excludeDisabled prop for range mode (#2290)
* feat: add excludeDisabled for range mode * Update test
- Loading branch information
Showing
10 changed files
with
185 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react"; | ||
|
||
import { DayPicker } from "react-day-picker"; | ||
|
||
export function RangeExcludeDisabled() { | ||
return ( | ||
<DayPicker mode="range" disabled={{ dayOfWeek: [0, 6] }} excludeDisabled /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { act, renderHook } from "@/test/render"; | ||
|
||
import { dateLib } from "../lib"; | ||
|
||
import { useRange } from "./useRange"; | ||
|
||
describe("useRange", () => { | ||
test("initialize with initiallySelected date range", () => { | ||
const initiallySelected = { | ||
from: new Date(2023, 6, 1), | ||
to: new Date(2023, 6, 5) | ||
}; | ||
const { result } = renderHook(() => | ||
useRange( | ||
{ mode: "range", selected: initiallySelected, required: false }, | ||
dateLib | ||
) | ||
); | ||
|
||
expect(result.current.selected).toEqual(initiallySelected); | ||
}); | ||
|
||
test("update the selected range on select", () => { | ||
const initiallySelected = { | ||
from: new Date(2023, 6, 1), | ||
to: new Date(2023, 6, 5) | ||
}; | ||
const { result } = renderHook(() => | ||
useRange( | ||
{ mode: "range", selected: initiallySelected, required: false }, | ||
dateLib | ||
) | ||
); | ||
|
||
act(() => { | ||
result.current.select?.(new Date(2023, 6, 10), {}, {} as any); | ||
}); | ||
|
||
expect(result.current.selected).toEqual({ | ||
from: new Date(2023, 6, 1), | ||
to: new Date(2023, 6, 10) | ||
}); | ||
}); | ||
|
||
test("reset range if new range exceeds max days", () => { | ||
const { result } = renderHook(() => | ||
useRange( | ||
{ | ||
mode: "range", | ||
selected: undefined, | ||
required: false, | ||
max: 5 | ||
}, | ||
dateLib | ||
) | ||
); | ||
|
||
act(() => { | ||
result.current.select?.(new Date(2023, 6, 1), {}, {} as any); | ||
result.current.select?.(new Date(2023, 6, 10), {}, {} as any); | ||
}); | ||
|
||
expect(result.current.selected).toEqual({ | ||
from: new Date(2023, 6, 10), | ||
to: undefined | ||
}); | ||
}); | ||
|
||
test("reset range if new range is less than min days", () => { | ||
const { result } = renderHook(() => | ||
useRange( | ||
{ mode: "range", selected: undefined, required: false, min: 5 }, | ||
dateLib | ||
) | ||
); | ||
|
||
act(() => { | ||
result.current.select?.(new Date(2023, 6, 1), {}, {} as any); | ||
result.current.select?.(new Date(2023, 6, 3), {}, {} as any); | ||
}); | ||
|
||
expect(result.current.selected).toEqual({ | ||
from: new Date(2023, 6, 3), | ||
to: undefined | ||
}); | ||
}); | ||
|
||
test("exclude disabled dates when selecting range", () => { | ||
const disabled = [{ from: new Date(2023, 6, 5), to: new Date(2023, 6, 7) }]; | ||
const { result } = renderHook(() => | ||
useRange( | ||
{ | ||
mode: "range", | ||
selected: undefined, | ||
required: false, | ||
excludeDisabled: true, | ||
disabled | ||
}, | ||
dateLib | ||
) | ||
); | ||
|
||
act(() => { | ||
result.current.select?.(new Date(2023, 6, 1), {}, {} as any); | ||
result.current.select?.(new Date(2023, 6, 10), {}, {} as any); | ||
}); | ||
|
||
expect(result.current.selected).toEqual({ | ||
from: new Date(2023, 6, 10), | ||
to: undefined | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export { screen, act, within, render } from "@testing-library/react"; | ||
export { | ||
screen, | ||
act, | ||
within, | ||
render, | ||
renderHook | ||
} from "@testing-library/react"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters