moves validator function

This commit is contained in:
Alex Corey 2020-04-13 15:30:35 -04:00
parent a95632c349
commit ee6fda9f8a
6 changed files with 22 additions and 25 deletions

View File

@ -41,6 +41,5 @@ describe('ErrorDetail', () => {
);
wrapper.find('Expandable').prop('onToggle')();
wrapper.update();
// console.log(wrapper.find('ErrorDetail').prop('error'));
});
});

View File

@ -1,10 +1,10 @@
export default function getErrorMessage(response) {
if (typeof response.data === 'string') {
return response.data;
}
if (!response.data) {
return null;
}
if (typeof response.data === 'string') {
return response.data;
}
if (response.data.detail) {
return response.data.detail;
}

View File

@ -6,9 +6,11 @@ import InventoryStep from './InventoryStep';
import CredentialsStep from './CredentialsStep';
import OtherPromptsStep from './OtherPromptsStep';
import PreviewStep from './PreviewStep';
import { InventoriesAPI } from '@api';
import { InventoriesAPI, CredentialsAPI, CredentialTypesAPI } from '@api';
jest.mock('@api/models/Inventories');
jest.mock('@api/models/CredentialTypes');
jest.mock('@api/models/Credentials');
let config;
const resource = {
@ -25,6 +27,10 @@ describe('LaunchPrompt', () => {
count: 1,
},
});
CredentialsAPI.read.mockResolvedValue({
data: { results: [{ id: 1 }], count: 1 },
});
CredentialTypesAPI.loadAllTypes({ data: { results: [{ type: 'ssh' }] } });
config = {
can_start_without_user_input: false,

View File

@ -322,7 +322,6 @@ exports[`<DeleteRoleConfirmationModal /> should render initially 1`] = `
className="pf-c-backdrop"
>
<FocusTrap
_createFocusTrap={[Function]}
active={true}
className="pf-l-bullseye"
focusTrapOptions={
@ -331,7 +330,6 @@ exports[`<DeleteRoleConfirmationModal /> should render initially 1`] = `
}
}
paused={false}
tag="div"
>
<div
className="pf-l-bullseye"

View File

@ -13,13 +13,7 @@ import FormField, {
FieldTooltip,
} from '@components/FormField';
import AnsibleSelect from '@components/AnsibleSelect';
import {
required,
noWhiteSpace,
combine,
maxLength,
defaultIsNotAvailable,
} from '@util/validators';
import { required, noWhiteSpace, combine, maxLength } from '@util/validators';
function AnswerTypeField({ i18n }) {
const [field] = useField({
@ -72,6 +66,17 @@ function SurveyQuestionForm({
submitError,
i18n,
}) {
const defaultIsNotAvailable = choices => {
return defaultValue => {
if (!choices.includes(defaultValue)) {
return i18n._(
t`Default choice must be answered from the choices listed.`
);
}
return undefined;
};
};
return (
<Formik
initialValues={{

View File

@ -36,17 +36,6 @@ export function minMaxValue(min, max, i18n) {
};
}
export function defaultIsNotAvailable(choices, i18n) {
return defaultValue => {
if (!choices.includes(defaultValue)) {
return i18n._(
t`Default choice must be answered from the choices listed.`
);
}
return undefined;
};
}
export function requiredEmail(i18n) {
return value => {
if (!value) {