diff --git a/src/components/Wizard/CreateVmWizard/tests/__snapshots__/CreateVmWizard.test.js.snap b/src/components/Wizard/CreateVmWizard/tests/__snapshots__/CreateVmWizard.test.js.snap index 6f3f01c9a..7bfb881aa 100644 --- a/src/components/Wizard/CreateVmWizard/tests/__snapshots__/CreateVmWizard.test.js.snap +++ b/src/components/Wizard/CreateVmWizard/tests/__snapshots__/CreateVmWizard.test.js.snap @@ -95,6 +95,7 @@ Object { "isRequired": Object { "flavor": false, }, + "validation": null, "value": undefined, }, "name": Object { diff --git a/src/components/Wizard/CreateVmWizard/validations/vmSettingsTabValidation.js b/src/components/Wizard/CreateVmWizard/validations/vmSettingsTabValidation.js index c5c51e184..f799b8e09 100644 --- a/src/components/Wizard/CreateVmWizard/validations/vmSettingsTabValidation.js +++ b/src/components/Wizard/CreateVmWizard/validations/vmSettingsTabValidation.js @@ -1,7 +1,13 @@ import { get } from 'lodash'; import { isFieldRequired } from '../utils/vmSettingsTabUtils'; -import { getValidationObject, validateContainer, validateVmName, validateURL } from '../../../../utils/validations'; +import { + getValidationObject, + validateContainer, + validateVmName, + validateURL, + validateMemory, +} from '../../../../utils/validations'; import { objectMerge } from '../../../../utils/utils'; import { settingsValue } from '../../../../k8s/selectors'; import { PROVISION_SOURCE_IMPORT, VALIDATION_ERROR_TYPE } from '../../../../constants'; @@ -13,6 +19,7 @@ import { PROVIDER_KEY, PROVIDERS_DATA_KEY, PROVISION_SOURCE_TYPE_KEY, + MEMORY_KEY, } from '../constants'; import { NAMESPACE_MUST_BE_SELECTED } from '../../../../utils/strings'; import { isProviderValid, validateProvider } from '../providers'; @@ -40,6 +47,7 @@ const validateResolver = { [CONTAINER_IMAGE_KEY]: asVmSettingsValidator(validateContainer), [IMAGE_URL_KEY]: asVmSettingsValidator(validateURL), [PROVIDER_KEY]: validateProviderDropdown, + [MEMORY_KEY]: asVmSettingsValidator(validateMemory), }; export const validateVmSettings = (vmSettings, additionalResources) => { diff --git a/src/utils/validations.js b/src/utils/validations.js index db08a08e7..a9ddc44d0 100644 --- a/src/utils/validations.js +++ b/src/utils/validations.js @@ -20,7 +20,7 @@ import { VALIDATION_ERROR_TYPE } from '../constants'; import { getName, getNamespace } from '../selectors'; import { NAMESPACE_KEY, VIRTUAL_MACHINES_KEY } from '../components/Wizard/CreateVmWizard/constants'; -export const isPositiveNumber = value => value && value.match(/^[1-9]\d*$/); +export const isPositiveNumber = value => value && value.toString().match(/^[1-9]\d*$/); const alphanumberincRegex = '[a-zA-Z0-9]'; @@ -69,6 +69,13 @@ export const validateVmName = (value, vmSettings, props) => { : vmAlreadyExists(value, get(vmSettings, `${NAMESPACE_KEY}.value`), props[VIRTUAL_MACHINES_KEY]); }; +export const validateMemory = value => { + if (!value) { + return getValidationObject(EMPTY_ERROR); + } + return isPositiveNumber(value) ? null : getValidationObject('must be positive integer'); +}; + export const validateURL = value => { if (!value) { return getValidationObject(EMPTY_ERROR);