diff --git a/ui/app/utils/validators.js b/ui/app/utils/validators.js index ceab04ef39..03f74dd9e6 100644 --- a/ui/app/utils/validators.js +++ b/ui/app/utils/validators.js @@ -25,9 +25,17 @@ export const number = (value, { nullable = false } = {}) => { return !isNaN(value); }; +/* +the following validations return false (invalid) if the condition is met +*/ export const containsWhiteSpace = (value) => { const validation = new RegExp('\\s', 'g'); // search for whitespace return !validation.test(value); }; -export default { presence, length, number, containsWhiteSpace }; +export const endsInSlash = (value) => { + const validation = new RegExp('/$'); + return !validation.test(value); +}; + +export default { presence, length, number, containsWhiteSpace, endsInSlash }; diff --git a/ui/tests/unit/utils/validators-test.js b/ui/tests/unit/utils/validators-test.js index e375d1b9b7..0f01cddf0e 100644 --- a/ui/tests/unit/utils/validators-test.js +++ b/ui/tests/unit/utils/validators-test.js @@ -92,4 +92,17 @@ module('Unit | Util | validators', function (hooks) { check('trailingSpace '); assert.false(isValid, 'Invalid when text has trailing whitespace'); }); + + test('it should validate value ends in a slash', function (assert) { + let isValid; + const check = (prop) => (isValid = validators.endsInSlash(prop)); + check('validText'); + assert.true(isValid, 'Valid when text does not end in slash'); + check('valid/Text'); + assert.true(isValid, 'Valid when text only contains slash'); + check('invalid/'); + assert.false(isValid, 'Invalid when text ends in slash'); + check('also/invalid/'); + assert.false(isValid, 'Invalid when text contains and ends in slash'); + }); });