Skip to content

Commit

Permalink
Handle reverting falsy values that are not null or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
marshmalien committed Jan 29, 2021
1 parent db4d84b commit 8a58a73
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion awx/ui_next/src/screens/Setting/shared/SharedFields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const InputField = withI18n()(

return config ? (
<SettingGroup
defaultValue={config.default || ''}
defaultValue={config.default ?? ''}
fieldId={name}
helperTextInvalid={meta.error}
isRequired={isRequired}
Expand Down
29 changes: 29 additions & 0 deletions awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a58a73

Please sign in to comment.