Address PR feedback

* Set local_path default value to empty string
* Make playbook directory required
* Update unit tests
This commit is contained in:
Marliana Lara
2019-11-11 13:38:15 -05:00
parent e4721d7722
commit 5319659d58
3 changed files with 11 additions and 15 deletions

View File

@@ -128,23 +128,14 @@ describe('<ProjectAdd />', () => {
}); });
}); });
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0); await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
const formik = wrapper.find('Formik').instance(); await act(async () => {
const changeState = new Promise(resolve => { wrapper.find('ProjectForm').prop('handleSubmit')(
formik.setState( { ...projectData },
{ { scm_type: 'manual' }
values: {
...projectData,
scm_type: 'manual',
},
},
() => resolve()
); );
}); });
await changeState;
await act(async () => {
wrapper.find('form').simulate('submit');
});
wrapper.update(); wrapper.update();
expect(ProjectsAPI.create).toHaveBeenCalledTimes(1);
expect(wrapper.find('ProjectAdd .formSubmitError').length).toBe(1); expect(wrapper.find('ProjectAdd .formSubmitError').length).toBe(1);
}); });

View File

@@ -183,7 +183,7 @@ function ProjectForm({ project, ...props }) {
credential: project.credential || '', credential: project.credential || '',
custom_virtualenv: project.custom_virtualenv || '', custom_virtualenv: project.custom_virtualenv || '',
description: project.description || '', description: project.description || '',
local_path: project.local_path || null, local_path: project.local_path || '',
name: project.name || '', name: project.name || '',
organization: project.organization || '', organization: project.organization || '',
scm_branch: project.scm_branch || '', scm_branch: project.scm_branch || '',

View File

@@ -2,6 +2,7 @@ import React from 'react';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { Field } from 'formik'; import { Field } from 'formik';
import { required } from '@util/validators';
import AnsibleSelect from '@components/AnsibleSelect'; import AnsibleSelect from '@components/AnsibleSelect';
import FormField, { FieldTooltip } from '@components/FormField'; import FormField, { FieldTooltip } from '@components/FormField';
import { FormGroup, Alert } from '@patternfly/react-core'; import { FormGroup, Alert } from '@patternfly/react-core';
@@ -74,9 +75,13 @@ const ManualSubForm = ({
{options.length !== 1 && ( {options.length !== 1 && (
<Field <Field
name="local_path" name="local_path"
validate={required(i18n._(t`Select a value for this field`), i18n)}
render={({ field, form }) => ( render={({ field, form }) => (
<FormGroup <FormGroup
fieldId="project-local-path" fieldId="project-local-path"
helperTextInvalid={form.errors.local_path}
isRequired
isValid={!form.touched.local_path || !form.errors.local_path}
label={i18n._(t`Playbook Directory`)} label={i18n._(t`Playbook Directory`)}
> >
<FieldTooltip <FieldTooltip