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.find('Expandable').prop('onToggle')();
wrapper.update(); wrapper.update();
// console.log(wrapper.find('ErrorDetail').prop('error'));
}); });
}); });

View File

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

View File

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

View File

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

View File

@@ -13,13 +13,7 @@ import FormField, {
FieldTooltip, FieldTooltip,
} from '@components/FormField'; } from '@components/FormField';
import AnsibleSelect from '@components/AnsibleSelect'; import AnsibleSelect from '@components/AnsibleSelect';
import { import { required, noWhiteSpace, combine, maxLength } from '@util/validators';
required,
noWhiteSpace,
combine,
maxLength,
defaultIsNotAvailable,
} from '@util/validators';
function AnswerTypeField({ i18n }) { function AnswerTypeField({ i18n }) {
const [field] = useField({ const [field] = useField({
@@ -72,6 +66,17 @@ function SurveyQuestionForm({
submitError, submitError,
i18n, 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 ( return (
<Formik <Formik
initialValues={{ 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) { export function requiredEmail(i18n) {
return value => { return value => {
if (!value) { if (!value) {