-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple tests for contact-summary & nools lib code
- Loading branch information
Showing
8 changed files
with
534 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const assert = require('chai').assert; | ||
const parseJs = require('../../src/lib/simple-js-parser'); | ||
|
||
describe('contact-summary lib', function() { | ||
const loadLibWithConfig = ({ cards, fields }) => parseJs({ | ||
jsFiles: [ `${__dirname}/../../src/contact-summary/lib.js` ], | ||
header: `var fields = ${JSON.stringify(fields)};` + | ||
`var cards = ${JSON.stringify(cards)};`, | ||
trimLinesFromEnd: 3, | ||
}, | ||
'isReportValid', | ||
'result'); | ||
|
||
describe('test-setup', function() { | ||
it('should provide the lib', function() { | ||
// given | ||
const lib = loadLibWithConfig({ cards:[], fields:[] }); | ||
|
||
// expect | ||
assert.isNotNull(lib); | ||
}); | ||
}); | ||
|
||
describe('isReportValid', function() { | ||
it('should return true if report has no errors property (as for xforms)', function() { | ||
// given | ||
const lib = loadLibWithConfig({ cards:[], fields:[] }); | ||
|
||
// expect | ||
assert.isTrue(lib.isReportValid({})); | ||
}); | ||
|
||
it('should return true if report has empty errors array (as for JSON forms)', function() { | ||
// given | ||
const lib = loadLibWithConfig({ cards:[], fields:[] }); | ||
|
||
// expect | ||
assert.isTrue(lib.isReportValid({ errors:[] })); | ||
}); | ||
|
||
it('should return false if report has errors', function() { | ||
// given | ||
const lib = loadLibWithConfig({ cards:[], fields:[] }); | ||
|
||
// expect | ||
assert.isFalse(lib.isReportValid({ errors:['???'] })); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const assert = require('chai').assert; | ||
|
||
const jsToString = require('../../src/lib/js-to-string'); | ||
|
||
describe('jsToString', function() { | ||
describe('String handling', function() { | ||
it('should handle a simple string', function() { | ||
// expect | ||
assert.equal(jsToString('a simple string'), '"a simple string"'); | ||
}); | ||
it('a string with quotes', function() { | ||
// given | ||
const input = 'a "string" with \'quotes\''; | ||
const expected = '"a \\"string\\" with \'quotes\'"'; | ||
|
||
// expect | ||
assert.equal(jsToString(input), expected); | ||
}); | ||
it('should handle a string with linebreaks', function() { | ||
// given | ||
const input = 'a\nstring\nwith\nlinebreaks\n'; | ||
const expected = '"a\\nstring\\nwith\\nlinebreaks\\n"'; | ||
|
||
// expect | ||
assert.equal(jsToString(input), expected); | ||
}); | ||
}); | ||
|
||
describe('Number handling', function() { | ||
it('should handle zero', function() { | ||
// expect | ||
assert.equal(jsToString(0), '0'); | ||
}); | ||
it('should handle a positive number', function() { | ||
// expect | ||
assert.equal(jsToString(1), '1'); | ||
}); | ||
it('should handle a negative number', function() { | ||
// expect | ||
assert.equal(jsToString(-1), '-1'); | ||
}); | ||
}); | ||
|
||
describe('Array handling', function() { | ||
it('should handle empty array', function() { | ||
// expect | ||
assert.equal(jsToString([]), '[]'); | ||
}); | ||
it('should handle array with one entry', function() { | ||
// expect | ||
assert.equal(jsToString([1]), '[1]'); | ||
}); | ||
it('should handle array with multiple entries', function() { | ||
// expect | ||
assert.equal(jsToString([1, 2, 3]), '[1,2,3]'); | ||
}); | ||
}); | ||
|
||
describe('Object handling', function() { | ||
it('should handle empty object', function() { | ||
// expect | ||
assert.equal(jsToString({}), '{}'); | ||
}); | ||
it('should handle object with one property', function() { | ||
// expect | ||
assert.equal(jsToString({ a:1 }), '{a:1}'); | ||
}); | ||
it('should handle object with multiple properties', function() { | ||
// expect | ||
assert.equal(jsToString({ a:1, b:2, c:3 }), '{a:1,b:2,c:3}'); | ||
}); | ||
}); | ||
|
||
describe('Function handling', function() { | ||
it('should not handle a simple function', function() { | ||
try { | ||
// when | ||
jsToString(function() {}); | ||
assert.isNotOk('should have thrown :('); | ||
} catch(e) { | ||
// then | ||
assert.equal(e.message, 'This function does not support functions!'); | ||
} | ||
}); | ||
it('should not handle a named function', function() { | ||
try { | ||
// when | ||
jsToString(function withName() {}); | ||
assert.isNotOk('should have thrown :('); | ||
} catch(e) { | ||
// then | ||
assert.equal(e.message, 'This function does not support functions!'); | ||
} | ||
}); | ||
it('should not handle a function which does something', function() { | ||
try { | ||
// when | ||
jsToString(function(a, b) { return a + b; }); | ||
assert.isNotOk('should have thrown :('); | ||
} catch(e) { | ||
// then | ||
assert.equal(e.message, 'This function does not support functions!'); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.