Handle reverting falsy values that are not null or undefined

This commit is contained in:
Marliana Lara 2020-11-24 15:21:53 -05:00
parent db4d84b94c
commit 8a58a73cb0
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
2 changed files with 30 additions and 1 deletions

View File

@ -195,7 +195,7 @@ const InputField = withI18n()(
return config ? (
<SettingGroup
defaultValue={config.default || ''}
defaultValue={config.default ?? ''}
fieldId={name}
helperTextInvalid={meta.error}
isRequired={isRequired}

View File

@ -133,6 +133,35 @@ describe('Setting form fields', () => {
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 () => {
const wrapper = mountWithContexts(
<Formik