mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Handle reverting falsy values that are not null or undefined
This commit is contained in:
parent
db4d84b94c
commit
8a58a73cb0
@ -195,7 +195,7 @@ const InputField = withI18n()(
|
||||
|
||||
return config ? (
|
||||
<SettingGroup
|
||||
defaultValue={config.default || ''}
|
||||
defaultValue={config.default ?? ''}
|
||||
fieldId={name}
|
||||
helperTextInvalid={meta.error}
|
||||
isRequired={isRequired}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user