-
Notifications
You must be signed in to change notification settings - Fork 383
fix(CalendarMonth) fix first day of month not showing when weekstart … #7679
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
Merged
wise-king-sullyman
merged 3 commits into
patternfly:main
from
dominik-petrik:datepicker-bugfix
Jul 21, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
packages/react-core/src/components/CalendarMonth/__tests__/CalendarMonth.test.tsx
This file contains hidden or 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,29 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { render, screen } from '@testing-library/react'; | ||
|
|
||
| import { CalendarMonth } from '../CalendarMonth'; | ||
|
|
||
| test('Renders the first date in a month when a custom weekStart is passed', () => { | ||
| // custom aria label generation function because of bug with default aria label generation | ||
| // can be removed once the bug is fixed | ||
| const formatAria = (date: Date) => | ||
| `${date.getDate()} ${date.toLocaleDateString(undefined, { month: 'long' })} ${date.getFullYear()}`; | ||
|
|
||
| render(<CalendarMonth cellAriaLabel={formatAria} weekStart={1} date={new Date(2023, 0)} />); | ||
|
|
||
| const firstDate = screen.queryByRole('button', { name: '1 January 2023' }); | ||
| expect(firstDate).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders the last date in a month when a custom weekStart is passed', () => { | ||
| // custom aria label generation function because of bug with default aria labels | ||
| // can be removed once the bug is fixed | ||
| const formatAria = (date: Date) => | ||
| `${date.getDate()} ${date.toLocaleDateString(undefined, { month: 'long' })} ${date.getFullYear()}`; | ||
|
|
||
| render(<CalendarMonth cellAriaLabel={formatAria} weekStart={1} date={new Date(2023, 0)} />); | ||
|
|
||
| const lastDate = screen.queryByRole('button', { name: '31 January 2023' }); | ||
| expect(lastDate).toBeVisible(); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here just stating that this custom aria label is needed because of a bug with automatic aria label generation as it is now, and that it can be removed once that bug is fixed?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'd it be actually a good thing to keep custom aria label because format of default generated aria label might change in future and the test would fail for seemingly unrelated reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point, though the same could be said for this approach and its reliance on the
cellAriaLabelprop functioning properly. This line of thinking could also extend to many other behaviors of the component, such as theweekStartordateprops working properly, or the structure of the component.I totally get not wanting this test to be able to fail for something that isn't the actual behavior under test, but I think that it's generally reasonable for a test to rely on other behavior of the component under test since totally avoiding that would be next to impossible.
Plus if the generated aria labels are properly tested developers should be able to see that test failing as well if the generated aria label is changed, which should make it apparent what the true cause of the failure here is.
All of that being said I don't think what you've got here is bad by any means and I don't think it neccesarily needs to go, but I would still like a comment saying why it's here and that it shouldn't be needed once the bug is fixed 🙂