-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Radio): address component QA feedback (#1986)
- stop using radio icons which can now be removed - replace with styling using in-DOM elements (future proof for transitions) - better application of color tokens - add tests - update snapshots
- Loading branch information
1 parent
f6e280f
commit 03edc20
Showing
7 changed files
with
576 additions
and
123 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,41 @@ | ||
import { generateSnapshots } from '@chanzuckerberg/story-utils'; | ||
import type { StoryFile } from '@storybook/testing-react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
import { Radio } from './Radio-v2'; | ||
import * as stories from './Radio-v2.stories'; | ||
|
||
describe('<Radio /> (v2)', () => { | ||
generateSnapshots(stories as StoryFile); | ||
|
||
test('should toggle the radio with space', async () => { | ||
const user = userEvent.setup(); | ||
const onChange = jest.fn(); | ||
|
||
function ControlledRadio() { | ||
const [checked, setChecked] = React.useState(false); | ||
const handleChange = () => { | ||
setChecked(!checked); | ||
onChange(); | ||
}; | ||
|
||
return ( | ||
<Radio | ||
aria-label="test-radio" | ||
checked={checked} | ||
onChange={handleChange} | ||
/> | ||
); | ||
} | ||
|
||
render(<ControlledRadio />); | ||
const radio = screen.getByRole('radio'); | ||
radio.focus(); | ||
|
||
await user.keyboard(' '); | ||
|
||
expect(radio).toBeChecked(); | ||
expect(onChange).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.