mirror of
https://github.com/ansible/awx.git
synced 2026-03-06 11:11:07 -03:30
Handle reverting falsy values that are not null or undefined
This commit is contained in:
@@ -195,7 +195,7 @@ const InputField = withI18n()(
|
|||||||
|
|
||||||
return config ? (
|
return config ? (
|
||||||
<SettingGroup
|
<SettingGroup
|
||||||
defaultValue={config.default || ''}
|
defaultValue={config.default ?? ''}
|
||||||
fieldId={name}
|
fieldId={name}
|
||||||
helperTextInvalid={meta.error}
|
helperTextInvalid={meta.error}
|
||||||
isRequired={isRequired}
|
isRequired={isRequired}
|
||||||
|
|||||||
@@ -133,6 +133,35 @@ describe('Setting form fields', () => {
|
|||||||
expect(wrapper.find('TextInputBase').prop('value')).toEqual('foo');
|
expect(wrapper.find('TextInputBase').prop('value')).toEqual('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('InputField should revert to expected default value', async () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<Formik
|
||||||
|
initialValues={{
|
||||||
|
number: 5,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{() => (
|
||||||
|
<InputField
|
||||||
|
name="number"
|
||||||
|
type="number"
|
||||||
|
config={{
|
||||||
|
label: 'test number input',
|
||||||
|
min_value: -10,
|
||||||
|
default: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
expect(wrapper.find('TextInputBase')).toHaveLength(1);
|
||||||
|
expect(wrapper.find('TextInputBase').prop('value')).toEqual(5);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('button[aria-label="Revert"]').invoke('onClick')();
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('TextInputBase').prop('value')).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('TextAreaField renders the expected content', async () => {
|
test('TextAreaField renders the expected content', async () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<Formik
|
<Formik
|
||||||
|
|||||||
Reference in New Issue
Block a user