ldx-widgets
Version:
widgets
167 lines (99 loc) • 4.78 kB
text/coffeescript
Validation = require('../src/validation')
{isAlphaNumericOnly, isAlphaNumericWithSpaces, isPositiveWholeNumber, isNumeric} = Validation
moment = require 'moment'
describe 'Is AlphaNumeric', ->
it 'should return true for an empty string', ->
alphaNumericTest = isAlphaNumericOnly('')
expect(alphaNumericTest).to.equal(yes)
it 'should return false if not alphanumeric', ->
alphaNumericTest = isAlphaNumericOnly('notalphanumeric$')
expect(alphaNumericTest).to.equal(no)
it 'should return false if has underscore', ->
alphaNumericTest = isAlphaNumericOnly('notalphanumeric_')
expect(alphaNumericTest).to.equal(no)
it 'should return the true if alphanumeric', ->
alphaNumericTest = isAlphaNumericOnly('44String')
expect(alphaNumericTest).to.equal(yes)
it 'should return the true if alphabets', ->
alphaNumericTest = isAlphaNumericOnly('string')
expect(alphaNumericTest).to.equal(yes)
it 'should return the true if numeric', ->
alphaNumericTest = isAlphaNumericOnly(14)
expect(alphaNumericTest).to.equal(yes)
it 'should return false if text has space', ->
alphaNumericTest = isAlphaNumericOnly('test has space')
expect(alphaNumericTest).to.equal(no)
describe 'Is AlphaNumeric with spaces', ->
it 'should return true for an empty string', ->
alphaNumericTest = isAlphaNumericWithSpaces('')
expect(alphaNumericTest).to.equal(yes)
it 'should return false if not alphanumeric', ->
alphaNumericTest = isAlphaNumericWithSpaces('notalphanumeric$')
expect(alphaNumericTest).to.equal(no)
it 'should return false if has underscore', ->
alphaNumericTest = isAlphaNumericWithSpaces('notalphanumeric_')
expect(alphaNumericTest).to.equal(no)
it 'should return the true if alphanumeric', ->
alphaNumericTest = isAlphaNumericWithSpaces('44String')
expect(alphaNumericTest).to.equal(yes)
it 'should return the true if alphabets', ->
alphaNumericTest = isAlphaNumericWithSpaces('string')
expect(alphaNumericTest).to.equal(yes)
it 'should return the true if numeric', ->
alphaNumericTest = isAlphaNumericWithSpaces(14)
expect(alphaNumericTest).to.equal(yes)
it 'should return the true if text has space', ->
alphaNumericTest = isAlphaNumericWithSpaces('test has space')
expect(alphaNumericTest).to.equal(yes)
describe 'Is Positive Whole Number', ->
it 'should return false if text has a letter', ->
wholeNumberTest = isPositiveWholeNumber '2a'
expect(wholeNumberTest).to.equal(no)
it 'should return false if text has a non-numeric character', ->
wholeNumberTest = isPositiveWholeNumber '$124578942'
expect(wholeNumberTest).to.equal(no)
wholeNumberTest = isPositiveWholeNumber '124578942%'
expect(wholeNumberTest).to.equal(no)
wholeNumberTest = isPositiveWholeNumber '+124578942'
expect(wholeNumberTest).to.equal(no)
it 'should return false if text is a decimal', ->
wholeNumberTest = isPositiveWholeNumber '2.5'
expect(wholeNumberTest).to.equal(no)
it 'should return false if text is negative', ->
wholeNumberTest = isPositiveWholeNumber '-2'
expect(wholeNumberTest).to.equal(no)
it 'should return true if text is an integer', ->
wholeNumberTest = isPositiveWholeNumber '3213212'
expect(wholeNumberTest).to.equal(yes)
wholeNumberTest = isPositiveWholeNumber 2
expect(wholeNumberTest).to.equal(yes)
wholeNumberTest = isPositiveWholeNumber 0
expect(wholeNumberTest).to.equal(yes)
describe 'Is Numeric', ->
it 'should return false if text has a letter', ->
numericTest = isNumeric '2a'
expect(numericTest).to.equal(no)
it 'should return false if text has only numeric charatcers, but is not a valid number', ->
numericTest = isNumeric '1245.78.942'
expect(numericTest).to.equal(no)
numericTest = isNumeric '1245-78942'
expect(numericTest).to.equal(no)
it 'should return false if text has a non-numeric character', ->
numericTest = isNumeric '$124578942'
expect(numericTest).to.equal(no)
numericTest = isNumeric '124578942%'
expect(numericTest).to.equal(no)
numericTest = isNumeric '+124578942'
expect(numericTest).to.equal(no)
it 'should return the true if text is an integer', ->
numericTest = isNumeric '124578942'
expect(numericTest).to.equal(yes)
it 'should return the true if text is a decimal', ->
numericTest = isNumeric '2.5'
expect(numericTest).to.equal(yes)
it 'should return the true if text is a negative integer', ->
numericTest = isNumeric '-2'
expect(numericTest).to.equal(yes)
it 'should return the true if text is a negative decimal', ->
numericTest = isNumeric '-2.5'
expect(numericTest).to.equal(yes)