-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fuselage):
RadioButton
a11y best practices improvement (#1162)
Co-authored-by: Douglas Fabris <devfabris@gmail.com>
- Loading branch information
1 parent
bbe8890
commit 387c401
Showing
5 changed files
with
131 additions
and
45 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,5 @@ | ||
--- | ||
"@rocket.chat/fuselage": patch | ||
--- | ||
|
||
fix(fuselage): RadioButton a11y best practices improvement |
55 changes: 51 additions & 4 deletions
55
packages/fuselage/src/components/RadioButton/RadioButton.spec.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 |
---|---|---|
@@ -1,10 +1,57 @@ | ||
import { composeStories } from '@storybook/testing-react'; | ||
import { render } from '@testing-library/react'; | ||
import { axe } from 'jest-axe'; | ||
import React from 'react'; | ||
|
||
import { RadioButton } from '.'; | ||
import * as stories from './RadioButton.stories'; | ||
|
||
describe('RadioButton Component', () => { | ||
it('renders without crashing', () => { | ||
render(<RadioButton />); | ||
const testCases = Object.values(composeStories(stories)) | ||
.filter((story) => story.storyName !== 'States') | ||
.map((Story) => [Story.storyName || 'Story', Story]); | ||
|
||
const { Default, Checked, Disabled } = composeStories(stories); | ||
|
||
describe('[RadioButton Rendering]', () => { | ||
test.each(testCases)( | ||
`renders %s without crashing`, | ||
async (_storyname, Story) => { | ||
const tree = render(<Story />); | ||
expect(tree.baseElement).toMatchSnapshot(); | ||
} | ||
); | ||
|
||
test.each(testCases)( | ||
'%s should have no a11y violations', | ||
async (_storyname, Story) => { | ||
const { container } = render(<Story />); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
} | ||
); | ||
}); | ||
|
||
describe('[RadioButton Interacting]', () => { | ||
it('changes style of element as radio button is checked', () => { | ||
const { container } = render(<Default />); | ||
const radioButton = container.querySelector( | ||
'input[type="radio"]' | ||
) as HTMLInputElement; | ||
radioButton.click(); | ||
expect(radioButton.checked).toEqual(true); | ||
}); | ||
it('displays radio button with defaultChecked value correctly', () => { | ||
const { container } = render(<Checked />); | ||
const radioButton = container.querySelector( | ||
'input[type="radio"]' | ||
) as HTMLInputElement; | ||
expect(radioButton.defaultChecked).toEqual(true); | ||
}); | ||
it('displays radio button disabled correctly', () => { | ||
const { container } = render(<Disabled />); | ||
const radioButton = container.querySelector( | ||
'input[type="radio"]' | ||
) as HTMLInputElement; | ||
expect(radioButton.disabled).toEqual(true); | ||
}); | ||
}); |
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
44 changes: 6 additions & 38 deletions
44
packages/fuselage/src/components/RadioButton/RadioButton.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
63 changes: 63 additions & 0 deletions
63
packages/fuselage/src/components/RadioButton/__snapshots__/RadioButton.spec.tsx.snap
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,63 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`[RadioButton Rendering] renders Checked without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<label | ||
class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-radio-button" | ||
> | ||
<input | ||
aria-label="Decorator Label" | ||
checked="" | ||
class="rcx-box rcx-box--full rcx-radio-button__input" | ||
type="radio" | ||
/> | ||
<i | ||
aria-hidden="true" | ||
class="rcx-box rcx-box--full rcx-radio-button__fake" | ||
/> | ||
</label> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[RadioButton Rendering] renders Default without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<label | ||
class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-radio-button" | ||
> | ||
<input | ||
aria-label="Decorator Label" | ||
class="rcx-box rcx-box--full rcx-radio-button__input" | ||
type="radio" | ||
/> | ||
<i | ||
aria-hidden="true" | ||
class="rcx-box rcx-box--full rcx-radio-button__fake" | ||
/> | ||
</label> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[RadioButton Rendering] renders Disabled without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<label | ||
class="rcx-box rcx-box--full rcx-label rcx-box rcx-box--full rcx-radio-button" | ||
> | ||
<input | ||
aria-label="Decorator Label" | ||
class="rcx-box rcx-box--full rcx-radio-button__input" | ||
disabled="" | ||
type="radio" | ||
/> | ||
<i | ||
aria-hidden="true" | ||
class="rcx-box rcx-box--full rcx-radio-button__fake" | ||
/> | ||
</label> | ||
</div> | ||
</body> | ||
`; |