-
-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: calendar reset after selection (#2429)
* Add test case * Apply fix * Update test * Remove test to revert commit with bug
- Loading branch information
Showing
5 changed files
with
66 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from "react"; | ||
|
||
import { labelGrid } from "react-day-picker"; | ||
|
||
import { dateButton, grid, gridcell, nextButton } from "@/test/elements"; | ||
import { render } from "@/test/render"; | ||
import { user } from "@/test/user"; | ||
|
||
import { TestCase2389 } from "./TestCase2389"; | ||
|
||
const today = new Date(2024, 8, 6); | ||
|
||
beforeAll(() => jest.setSystemTime(today)); | ||
afterAll(() => jest.useRealTimers()); | ||
|
||
beforeEach(async () => { | ||
render(<TestCase2389 />); | ||
}); | ||
|
||
describe("when moving to the next month", () => { | ||
beforeEach(async () => { | ||
await user.click(nextButton()); | ||
}); | ||
test("should display the next month", () => { | ||
const nextMonth = new Date(2024, 9, 1); | ||
expect(grid(labelGrid(nextMonth))).toBeVisible(); | ||
}); | ||
describe("when clicking a day button", () => { | ||
const day = new Date(2024, 9, 10); | ||
beforeEach(async () => { | ||
await user.click(dateButton(day)); | ||
}); | ||
test("should select the day", async () => { | ||
expect(gridcell(day, true)).toHaveAttribute("aria-selected", "true"); | ||
}); | ||
test("should still display the next month", () => { | ||
const nextMonth = new Date(2024, 9, 1); | ||
expect(grid(labelGrid(nextMonth))).toBeVisible(); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
import React, { useState } from "react"; | ||
|
||
import { DayPicker, DateRange } from "react-day-picker"; | ||
import "react-day-picker/style.css"; | ||
|
||
export function TestCase2389() { | ||
const [selectedPeriod, setSelectedPeriod] = useState<DateRange | undefined>(); | ||
|
||
return ( | ||
<DayPicker | ||
mode="range" | ||
startMonth={new Date("2024-07-01")} | ||
endMonth={new Date("2025-07-31")} | ||
onSelect={setSelectedPeriod} | ||
selected={selectedPeriod} | ||
/> | ||
); | ||
} |
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