Skip to content

Commit 95a447b

Browse files
committed
Add missing test for PF4 radio
1 parent cdd8f16 commit 95a447b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/pf4-component-mapper/src/tests/form-fields.test.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ import {
1111
SwitchField,
1212
} from '../form-fields/form-fields';
1313
import { mount, shallow } from 'enzyme';
14-
15-
const FieldProvider = ({ render, ...props }) => <div>{ render({ input: { name: 'Foo', onChange: jest.fn() }, meta: { error: false, touched: false }, ...props }) }</div>;
14+
import { Radio } from '@patternfly/react-core';
1615

1716
describe('FormFields', () => {
17+
let FieldProvider;
18+
let onChangeSpy;
19+
20+
beforeEach(() => {
21+
onChangeSpy = jest.fn();
22+
23+
FieldProvider = ({ render, ...props }) => <div>
24+
{ render({ input: { name: 'Foo', onChange: onChangeSpy }, meta: { error: false, touched: false }, ...props }) }
25+
</div>;
26+
});
27+
1828
const props = {
1929
input: {
2030
name: 'Name of the field',
@@ -119,6 +129,16 @@ describe('FormFields', () => {
119129
expect(toJson(wrapper)).toMatchSnapshot();
120130
});
121131

132+
it('radio - should call fieldProvider onChange correctly', () => {
133+
const wrapper = mount(
134+
<RadioField { ...propsWithOptions } FieldProvider={ FieldProvider } disabled={ true } />
135+
);
136+
137+
wrapper.find(Radio).first().props().onChange();
138+
139+
expect(onChangeSpy).toHaveBeenCalled();
140+
});
141+
122142
it('should render Select correctly', () => {
123143
const wrapper = shallow(
124144
<SelectField { ...propsWithOptions } />

0 commit comments

Comments
 (0)