ldx-widgets
Version:
widgets
229 lines (148 loc) • 6.51 kB
text/coffeescript
Validation = require('../src/validation')
{isAlphaNumericOnly, isAlphaNumericWithSpaces, isPositiveWholeNumber, isNumeric, isValidNhs} = 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)
describe 'Is Valid NHS', ->
it 'should return false if nhs has less than 10 digits', ->
nhsTest = isValidNhs '1'
expect(nhsTest).to.equal(no)
nhsTest = isValidNhs '12'
expect(nhsTest).to.equal(no)
nhsTest = isValidNhs '123'
expect(nhsTest).to.equal(no)
nhsTest = isValidNhs '123456789'
expect(nhsTest).to.equal(no)
nhsTest = isValidNhs '123456789 '
expect(nhsTest).to.equal(no)
it 'should return false if nhs is 10 digits, modulus is 10', ->
nhsTest = isValidNhs '304 171 0820'
expect(nhsTest).to.equal(no)
it 'should return false if nhs is 10 digits, modulus is 11 and last digit is not 0', ->
nhsTest = isValidNhs '304 171 0877'
expect(nhsTest).to.equal(no)
it 'should return true if nhs is 10 digits, modulus is 11 and last digit is 0', ->
nhsTest = isValidNhs '100 100 4280'
expect(nhsTest).to.equal(yes)
it 'should return true if nhs is 10 digits, modulus is equal to last digit', ->
# 1
nhsTest = isValidNhs '374 990 7021'
expect(nhsTest).to.equal(yes)
# 2
nhsTest = isValidNhs '621 585 1582'
expect(nhsTest).to.equal(yes)
# 3
nhsTest = isValidNhs '184 800 2793'
expect(nhsTest).to.equal(yes)
# 4
nhsTest = isValidNhs '660 645 8544'
expect(nhsTest).to.equal(yes)
# 5
nhsTest = isValidNhs '677 092 6555'
expect(nhsTest).to.equal(yes)
# 6
nhsTest = isValidNhs '527 935 9246'
expect(nhsTest).to.equal(yes)
# 7
nhsTest = isValidNhs '530 502 4137'
expect(nhsTest).to.equal(yes)
# 8
nhsTest = isValidNhs '230 188 2578'
expect(nhsTest).to.equal(yes)
# 9
nhsTest = isValidNhs '304 171 0889'
expect(nhsTest).to.equal(yes)