forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(radioComponent): updated according to PF-next demo (patternfly#756)
Adds label option, more tests
- Loading branch information
Showing
10 changed files
with
378 additions
and
68 deletions.
There are no files selected for viewing
12 changes: 8 additions & 4 deletions
12
packages/patternfly-4/react-core/src/components/Radio/Radio.d.ts
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
7 changes: 4 additions & 3 deletions
7
packages/patternfly-4/react-core/src/components/Radio/Radio.docs.js
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,12 +1,13 @@ | ||
import { Checkbox } from '@patternfly/react-core'; | ||
import Controlled from './examples/ControlledRadio'; | ||
import Uncontrolled from './examples/UncontrolledRadio'; | ||
import Disabled from './examples/DisabledRadio'; | ||
import Custom from './examples/CustomLabelRadio'; | ||
import { Radio } from '@patternfly/react-core'; | ||
|
||
export default { | ||
title: 'Radio', | ||
components: { | ||
Checkbox | ||
Radio | ||
}, | ||
examples: [Controlled, Uncontrolled, Disabled] | ||
examples: [Controlled, Uncontrolled, Disabled, Custom] | ||
}; |
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
74 changes: 53 additions & 21 deletions
74
packages/patternfly-4/react-core/src/components/Radio/Radio.test.js
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,33 +1,65 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Radio from './Radio'; | ||
import { shallow } from 'enzyme'; | ||
|
||
const props = { | ||
onChange: jest.fn(), | ||
checked: false | ||
}; | ||
|
||
test('controlled', () => { | ||
const view = shallow(<Radio checked />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
describe('Radio check component', () => { | ||
test('controlled', () => { | ||
const view = shallow(<Radio checked id="check" aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('uncontrolled', () => { | ||
const view = shallow(<Radio />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
test('uncontrolled', () => { | ||
const view = shallow(<Radio id="check" aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('isDisabled', () => { | ||
const view = shallow(<Radio isDisabled />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
test('isDisabled', () => { | ||
const view = shallow(<Radio id="check" isDisabled aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('label is string', () => { | ||
const view = shallow(<Radio label="Label" id="check" checked aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('label is function', () => { | ||
const functionLabel = () => <h1>Header</h1>; | ||
const view = shallow(<Radio label={functionLabel()} id="check" checked aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('label is node', () => { | ||
const view = shallow(<Radio label={<h1>Header</h1>} id="check" checked aria-label="check" name="check" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('passing class', () => { | ||
const view = shallow( | ||
<Radio label="label" className="class-123" id="check" checked aria-label="check" name="check" /> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('passing HTML attribute', () => { | ||
const view = shallow( | ||
<Radio label="label" aria-labelledby="labelId" id="check" checked aria-label="check" name="check" /> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('radio passes value and event to onChange handler', () => { | ||
const newValue = true; | ||
const event = { | ||
currentTarget: { checked: newValue } | ||
}; | ||
const view = shallow(<Radio {...props} />); | ||
view.find('input').simulate('change', event); | ||
expect(props.onChange).toBeCalledWith(newValue, event); | ||
test('Radio passes value and event to onChange handler', () => { | ||
const newValue = true; | ||
const event = { | ||
currentTarget: { checked: newValue } | ||
}; | ||
const view = shallow(<Radio id="check" {...props} aria-label="check" name="check" />); | ||
view.find('input').simulate('change', event); | ||
expect(props.onChange).toBeCalledWith(newValue, event); | ||
}); | ||
}); |
Oops, something went wrong.