This repository has been archived by the owner on Jul 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adding unit tests for lib/shared #3600
Merged
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b450758
Adds code coverage report the output of `npm test` and adds detailed …
b50ddc5
Switch over to using functions in lib/ rather than dist/, so that cod…
bbcaa78
Import vis at the top level to keep ItemSet passing
6c8cf80
Remove requirement for dist/vis in TimelineItemSet
294525c
Adds tests for Popup
319fced
Tests and sinon dependency introduced
989bfd2
Code changes to modules to tighten up code
3aae9fc
Merge branch 'develop' into mbroad/unittest/lib/shared
a56cd13
Merge branch 'develop' into mbroad/code-coverage
4b766a5
Merge branch 'mbroad/code-coverage' into mbroad/unittest/lib/shared
e25d2e2
Corrects broken tests and adds more tests to ColorPicker
4c68bae
Adds additional tests to DataSet
139bc86
Adds tests for uuid
429b63c
Removes unused functions from util
6288a41
Adds tests for utils: recursiveDomDelete, isDate, convert and isType
645fc91
removes redundant code
c19e524
Adds additional util tests
f81eef5
Address spacing, and unnecessary tests
031d640
Correct test description
0f8455f
Adds isDate tests
8303487
Adds sanity check assertions to popup destroy tests
388edb5
Merge branch 'develop' into mbroad/unittest/lib/shared
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -59,6 +59,11 @@ describe('ColorPicker', function () { | |
it('prevents non-functions from being set as callback', function () { | ||
var colorPicker = new ColorPicker(); | ||
assert.throws(function () {colorPicker.setUpdateCallback(null);}, Error, null); | ||
assert.throws(function () {colorPicker.setUpdateCallback(undefined);}, Error, null); | ||
assert.throws(function () {colorPicker.setUpdateCallback([1, 2, 3]);}, Error, null); | ||
assert.throws(function () {colorPicker.setUpdateCallback({a: 42});}, Error, null); | ||
assert.throws(function () {colorPicker.setUpdateCallback(42);}, Error, null); | ||
assert.throws(function () {colorPicker.setUpdateCallback('meow');}, Error, null); | ||
}); | ||
}); | ||
|
||
|
@@ -67,6 +72,11 @@ describe('ColorPicker', function () { | |
it('prevents non-functions from being set as callback', function () { | ||
var colorPicker = new ColorPicker(); | ||
assert.throws(function () {colorPicker.setCloseCallback(null);}, Error, null); | ||
assert.throws(function () {colorPicker.setCloseCallback(undefined);}, Error, null); | ||
assert.throws(function () {colorPicker.setCloseCallback([1, 2, 3]);}, Error, null); | ||
assert.throws(function () {colorPicker.setCloseCallback({a: 42});}, Error, null); | ||
assert.throws(function () {colorPicker.setCloseCallback(42);}, Error, null); | ||
assert.throws(function () {colorPicker.setCloseCallback('meow');}, Error, null); | ||
}); | ||
}); | ||
|
||
|
@@ -75,19 +85,29 @@ describe('ColorPicker', function () { | |
it('runs updateCallback when applied', function () { | ||
var callback = sinon.spy(); | ||
var colorPicker = new ColorPicker(); | ||
var colorBeforeHide = colorPicker.color; | ||
colorPicker.setUpdateCallback(callback); | ||
colorPicker.applied = true; | ||
colorPicker._hide(); | ||
assert.equal(callback.callCount, 1); | ||
assert.deepEqual(colorBeforeHide, colorPicker.previousColor); | ||
}); | ||
|
||
it('does not run updateCallback when not applied', function () { | ||
var callback = sinon.spy(); | ||
var colorPicker = new ColorPicker(); | ||
var colorBeforeHide = colorPicker.color; | ||
colorPicker.setUpdateCallback(callback); | ||
colorPicker.applied = false; | ||
colorPicker._hide(); | ||
assert.equal(callback.callCount, 0); | ||
assert.deepEqual(colorBeforeHide, colorPicker.previousColor); | ||
}); | ||
|
||
it('does not set previous color when storePrevious is false', function () { | ||
var colorPicker = new ColorPicker(); | ||
colorPicker._hide(false); | ||
assert.deepEqual(colorPicker.previousColor, undefined); | ||
}); | ||
}); | ||
|
||
|
@@ -114,9 +134,14 @@ describe('ColorPicker', function () { | |
assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); | ||
}); | ||
|
||
it('throws error when color is null', function () { | ||
it('throws error when color is a bad value', function () { | ||
var colorPicker = new ColorPicker(); | ||
assert.throws(function () {colorPicker.setColor(null);}, Error, null); | ||
assert.throws(function () {colorPicker.setColor(undefined);}, Error, null); | ||
assert.throws(function () {colorPicker.setColor([1, 2, 3]);}, Error, null); | ||
assert.throws(function () {colorPicker.setColor({a: 42});}, Error, null); | ||
assert.throws(function () {colorPicker.setColor(42);}, Error, null); | ||
assert.throws(function () {colorPicker.setColor('meow');}, Error, null); | ||
}); | ||
|
||
it('handles html color string', function () { | ||
|
@@ -165,15 +190,18 @@ describe('ColorPicker', function () { | |
colorPicker.show(); | ||
assert(callback.called); | ||
assert(callback.calledOnce); | ||
assert(colorPicker.generated) | ||
}); | ||
|
||
it('resets applied state and frame display style to `block`', function () { | ||
var colorPicker = new ColorPicker(); | ||
colorPicker.show(); | ||
assert.equal(colorPicker.applied, false); | ||
assert.equal(colorPicker.frame.style.display, 'block'); | ||
assert(colorPicker.generated) | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On account of thoroughness (which you are, very), I would expect test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're not going to do this? |
||
|
||
describe('_save', function () { | ||
|
||
it('triggers updateCallback', function () { | ||
|
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 |
---|---|---|
|
@@ -418,7 +418,7 @@ describe('DataSet', function () { | |
assert.equal(minValue, null); | ||
}); | ||
|
||
it('ignores undefined values', function () { | ||
it('handles undefined values', function () { | ||
var dataset = new DataSet([{id: undefined}, {id: 1}, {id: 2}, {id: 3}]); | ||
var minValue = dataset.min('id'); | ||
assert.deepEqual(minValue, {id: 1}); | ||
|
@@ -429,14 +429,9 @@ describe('DataSet', function () { | |
var minValue = dataset.min('id'); | ||
assert.deepEqual(minValue, {id: 10000000000000001}); | ||
}); | ||
|
||
xit('handles big values - but not really, because of javascript number handling', function () { | ||
var dataset = new DataSet([{id: -10000000000000001}, {id: -10000000000000002}, {id: -10000000000000003}]); | ||
var minValue = dataset.min('id'); | ||
assert.deepEqual(minValue, {id: -10000000000000003}); | ||
assert.equal('' + minValue.id, '-10000000000000003') | ||
}); | ||
}); | ||
|
||
|
||
describe('max', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline (I usually do 2 here) |
||
|
||
it('finds the maximum value', function () { | ||
|
@@ -451,24 +446,11 @@ describe('DataSet', function () { | |
assert.equal(maxValue, null); | ||
}); | ||
|
||
it('ignores undefined values', function () { | ||
it('handles undefined values', function () { | ||
var dataset = new DataSet([{id: undefined}, {id: 1}, {id: 2}, {id: 3}]); | ||
var maxValue = dataset.max('id'); | ||
assert.deepEqual(maxValue, {id: 3}); | ||
}); | ||
|
||
xit('handles big values - but not really, because of javascript number handling', function () { | ||
var dataset = new DataSet([{id: 10000000000000001}, {id: 10000000000000002}, {id: 10000000000000003}]); | ||
var maxValue = dataset.max('id'); | ||
assert.deepEqual(maxValue, {id: 10000000000000003}); | ||
assert.equal('' + maxValue.id, '10000000000000003') | ||
}); | ||
|
||
xit('handles negative values - This does not work because of javascript', function () { | ||
var dataset = new DataSet([{id: -10000000000000001}, {id: -10000000000000002}, {id: -10000000000000003}]); | ||
var maxValue = dataset.max('id'); | ||
assert.deepEqual(maxValue, {id: -10000000000000001}); | ||
}); | ||
}); | ||
|
||
describe('distinct', function () { | ||
|
@@ -485,22 +467,16 @@ describe('DataSet', function () { | |
assert.deepEqual(distinctValues, []); | ||
}); | ||
|
||
it('ignores undefined values', function () { | ||
it('handles undefined values', function () { | ||
var dataset = new DataSet([{val: undefined}, {val: 1}, {val: 2}, {val: 3}]); | ||
var distinctValues = dataset.distinct('val'); | ||
assert.deepEqual(distinctValues, [1, 2, 3]); | ||
}); | ||
|
||
xit('handles big values - but not really, because of javascript number handling', function () { | ||
var dataset = new DataSet([{val: 10000000000000001}, {val: 10000000000000002}, {val: 10000000000000003}, {val: 10000000000000004}]); | ||
it('handles duplicate values', function () { | ||
var dataset = new DataSet([{val: 1}, {val: 1}, {val: 2}, {val: 3}]); | ||
var distinctValues = dataset.distinct('val'); | ||
assert.deepEqual(distinctValues, [ 10000000000000000, 10000000000000002, 10000000000000003, 10000000000000004]); | ||
}); | ||
|
||
xit('handles negative values - This does not work because of javascript', function () { | ||
var dataset = new DataSet([{val: -10000000000000001}, {val: -10000000000000002}, {val: -10000000000000003}, {val: -10000000000000004}]); | ||
var distinctValues = dataset.distinct('val'); | ||
assert.deepEqual(distinctValues, [ -10000000000000000, -10000000000000002, -10000000000000003, -10000000000000004]); | ||
assert.deepEqual(distinctValues, [1, 2, 3]); | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to add the usual suspects here: 'null, undefined, [1,2,3], {a: 42}, 42, "meow"`.
Actually, I would consider being able to undo a callback (with
null
and/orundefined
) a feature here.Same applies to
setCloseCallback()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed