-
Notifications
You must be signed in to change notification settings - Fork 390
fix(Spinner): define default aria-label via destructuring #12420
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,35 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Spinner } from '../Spinner'; | ||
|
|
||
| test('simple spinner', () => { | ||
| const { asFragment } = render(<Spinner />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('uses default aria-label of "Contents" when none is provided', () => { | ||
| render(<Spinner />); | ||
| expect(screen.getByRole('progressbar')).toHaveAccessibleName('Contents'); | ||
| }); | ||
|
|
||
| test('uses a custom aria-label when one is provided', () => { | ||
| render(<Spinner aria-label="Loading users" />); | ||
| expect(screen.getByRole('progressbar')).toHaveAccessibleName('Loading users'); | ||
| }); | ||
|
|
||
| test('keeps the default aria-label when aria-labelledby is provided', () => { | ||
| render( | ||
| <> | ||
| <span id="spinner-label">Loading reports</span> | ||
| <Spinner aria-labelledby="spinner-label" /> | ||
| </> | ||
| ); | ||
|
|
||
| const spinner = screen.getByRole('progressbar'); | ||
| expect(spinner).toHaveAttribute('aria-label', 'Contents'); | ||
| expect(spinner).toHaveAttribute('aria-labelledby', 'spinner-label'); | ||
|
Comment on lines
+28
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we separate the aria-label check into a separate test, "Renders with aria-label even when aria-labelledby is passed". Then we can also remove the |
||
| expect(spinner).toHaveAccessibleName('Loading reports'); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test('small spinner', () => { | ||
| const { asFragment } = render(<Spinner size="sm" />); | ||
| expect(asFragment()).toMatchSnapshot(); | ||
|
|
||
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.
"Renders with accessible name via aria-labelledby when passed" might be slightly more fitting test name here.