-
-
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: dropdown may navigate to the wrong month when multiple months ar…
…e set (#1884)
- Loading branch information
Showing
6 changed files
with
92 additions
and
4 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
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,14 @@ | ||
import React from 'react'; | ||
|
||
import { DayPicker } from 'react-day-picker'; | ||
|
||
export default function App() { | ||
return ( | ||
<DayPicker | ||
numberOfMonths={5} | ||
captionLayout="dropdown-buttons" | ||
fromYear={2015} | ||
toYear={2025} | ||
/> | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
website/test-integration/examples/dropdown-multiple-months.test.tsx
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,53 @@ | ||
import React from 'react'; | ||
|
||
import { axe } from '@site/test/axe'; | ||
import { user } from '@site/test/user'; | ||
import { freezeBeforeAll } from '@site/test/utils'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
|
||
import { getMonthGrid } from 'react-day-picker/test/selectors'; | ||
|
||
import Example from '@examples/dropdown-multiple-months'; | ||
|
||
const today = new Date(2023, 9, 16); | ||
freezeBeforeAll(today); | ||
|
||
let container: HTMLElement; | ||
beforeEach(() => (container = render(<Example />).container)); | ||
|
||
test('should not have AXE violations', async () => { | ||
expect(await axe(container)).toHaveNoViolations(); | ||
}); | ||
|
||
test('should display 5 year dropdowns', () => { | ||
expect(screen.getAllByRole('combobox', { name: 'Year:' })).toHaveLength(5); | ||
}); | ||
test('should display 5 month dropdowns', () => { | ||
expect(screen.getAllByRole('combobox', { name: 'Month:' })).toHaveLength(5); | ||
}); | ||
|
||
describe('when choosing a month from the first drop-down', () => { | ||
const newMonthName = 'January'; | ||
beforeEach(() => { | ||
const firstDropDown = screen.getAllByRole('combobox', { | ||
name: 'Month:' | ||
})[0]; | ||
return act(() => user.selectOptions(firstDropDown, newMonthName)); | ||
}); | ||
test('should display the month in the first dropdown', () => { | ||
expect(getMonthGrid(0)).toHaveAccessibleName(`${newMonthName} 2023`); | ||
}); | ||
}); | ||
|
||
describe('when choosing a month from the third drop-down', () => { | ||
const newMonthName = 'October'; | ||
beforeEach(() => { | ||
const thirdDropDown = screen.getAllByRole('combobox', { | ||
name: 'Month:' | ||
})[2]; | ||
return act(() => user.selectOptions(thirdDropDown, newMonthName)); | ||
}); | ||
test('should display the month selected the third dropdown', () => { | ||
expect(getMonthGrid(2)).toHaveAccessibleName(`${newMonthName} 2023`); | ||
}); | ||
}); |