Browse Source

Address spacing, and unnecessary tests

mbroad/unittest/lib/shared
MacLeod Broad 6 years ago
parent
commit
f81eef53f3
No known key found for this signature in database GPG Key ID: F1B295D13C3CC9CF
5 changed files with 88 additions and 37 deletions
  1. +1
    -2
      lib/shared/Configurator.js
  2. +29
    -1
      test/ColorPicker.test.js
  3. +2
    -2
      test/Configurator.test.js
  4. +8
    -32
      test/DataSet.test.js
  5. +48
    -0
      test/util.test.js

+ 1
- 2
lib/shared/Configurator.js View File

@ -66,8 +66,7 @@ class Configurator {
this.options.filter = options.join();
}
else if (typeof options === 'object') {
if (options == null)
{
if (options == null) {
throw new TypeError('options cannot be null');
}
if (options.container !== undefined) {

+ 29
- 1
test/ColorPicker.test.js View File

@ -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,6 +190,7 @@ 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 () {
@ -172,8 +198,10 @@ describe('ColorPicker', function () {
colorPicker.show();
assert.equal(colorPicker.applied, false);
assert.equal(colorPicker.frame.style.display, 'block');
assert(colorPicker.generated)
});
});
describe('_save', function () {
it('triggers updateCallback', function () {

+ 2
- 2
test/Configurator.test.js View File

@ -26,7 +26,7 @@ describe('Configurator', function () {
it('sets extends options with default options', function () {
var config = new Configurator();
assert.equal(JSON.stringify(config.options), JSON.stringify(config.defaultOptions));
assert.deepEqual(config.options, config.defaultOptions);
});
});
@ -35,7 +35,7 @@ describe('Configurator', function () {
it('with undefined will not modify defaults', function () {
var config = new Configurator(Network, this.container);
config.setOptions();
assert.equal(JSON.stringify(config.options), JSON.stringify(config.defaultOptions));
assert.deepEqual(config.options, config.defaultOptions);
});
it('with undefined will set enabled to false', function () {

+ 8
- 32
test/DataSet.test.js View File

@ -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 () {
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 undefined 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]);
});
});

+ 48
- 0
test/util.test.js View File

@ -635,49 +635,62 @@ describe('mergeOptions', function () {
assert.throws(function () {util.convert({}, 'UnknownType');}, Error, null);
});
});
describe('getType', function () {
it('of object null is null', function () {
assert.equal(util.getType(null), 'null');
});
it('of object Boolean is Boolean', function () {
function Tester () {}
Tester.prototype = Object.create(Boolean.prototype);
assert.equal(util.getType(new Tester('true')), 'Boolean');
});
it('of object Number is Number', function () {
function Tester () {}
Tester.prototype = Object.create(Number.prototype);
assert.equal(util.getType(new Tester(1)), 'Number');
});
it('of object String is String', function () {
function Tester () {}
Tester.prototype = Object.create(String.prototype);
assert.equal(util.getType(new Tester('stringy!')), 'String');
});
it('of object Array is Array', function () {
assert.equal(util.getType(new Array([])), 'Array');
});
it('of object Date is Date', function () {
assert.equal(util.getType(new Date()), 'Date');
});
it('of object any other type is Object', function () {
assert.equal(util.getType({}), 'Object');
});
it('of number is Number', function () {
assert.equal(util.getType(1), 'Number');
});
it('of boolean is Boolean', function () {
assert.equal(util.getType(true), 'Boolean');
});
it('of string is String', function () {
assert.equal(util.getType('string'), 'String');
});
it('of undefined is undefined', function () {
assert.equal(util.getType(), 'undefined');
});
});
describe('easingFunctions', function () {
it('take a number and output a number', function () {
for (var key in util.easingFunctions) {
if (util.easingFunctions.hasOwnProperty(key)) {
@ -689,30 +702,38 @@ describe('mergeOptions', function () {
});
describe('getScrollBarWidth', function () {
beforeEach(function() {
this.jsdom_global = jsdom_global();
});
afterEach(function() {
this.jsdom_global();
});
it('returns 0 when there is no content', function () {
assert.equal(util.getScrollBarWidth(), 0);
});
});
describe('equalArray', function () {
it('arrays of different lengths are not equal', function () {
assert.equal(util.equalArray([1, 2, 3], [1, 2]), false)
});
it('arrays with different content are not equal', function () {
assert.equal(util.equalArray([1, 2, 3], [3, 2, 1]), false)
});
it('same content arrays are equal', function () {
assert(util.equalArray([1, 2, 3], [1, 2, 3]))
});
it('empty arrays are equal', function () {
assert(util.equalArray([], []))
});
it('the same array is equal', function () {
var arr = [1, 2, 3];
assert(util.equalArray(arr, arr))
@ -720,96 +741,121 @@ describe('mergeOptions', function () {
});
describe('asBoolean', function () {
it('resolves value from a function', function () {
assert(util.option.asBoolean(function () {return true}, false));
});
it('returns default value for null', function () {
assert(util.option.asBoolean(null, true));
});
it('returns true for other types', function () {
assert(util.option.asBoolean('should be true', false));
});
it('returns null for undefined', function () {
assert.equal(util.option.asBoolean(), null);
});
});
describe('asNumber', function () {
it('resolves value from a function', function () {
assert.equal(util.option.asNumber(function () {return 777}, 13), 777);
});
it('returns default value for null', function () {
assert.equal(util.option.asNumber(null, 13), 13);
});
it('returns number for other types', function () {
assert.equal(util.option.asNumber('777', 13), 777);
});
it('returns default for NaN', function () {
assert.equal(util.option.asNumber(NaN, 13), 13);
});
it('returns null for undefined', function () {
assert.equal(util.option.asNumber(), null);
});
});
describe('asString', function () {
it('resolves value from a function', function () {
assert.equal(util.option.asString(function () {return 'entered'}, 'default'), 'entered');
});
it('returns default value for null', function () {
assert.equal(util.option.asString(null, 'default'), 'default');
});
it('returns string for other types', function () {
assert.equal(util.option.asString(777, 'default'), '777');
});
it('returns default for undefined', function () {
assert.equal(util.option.asString(undefined, 'default'), 'default');
});
it('returns null for undefined', function () {
assert.equal(util.option.asString(), null);
});
});
describe('asSize', function () {
it('resolves value from a function', function () {
assert.equal(util.option.asSize(function () {return '100px'}, '50px'), '100px');
});
it('returns default value for null', function () {
assert.equal(util.option.asSize(null, '50px'), '50px');
});
it('returns string with px for other number', function () {
assert.equal(util.option.asSize(100, '50px'), '100px');
});
it('returns default for undefined', function () {
assert.equal(util.option.asSize(undefined, '50px'), '50px');
});
it('returns null for undefined', function () {
assert.equal(util.option.asSize(), null);
});
});
describe('asElement', function () {
before(function() {
this.jsdom_global = jsdom_global();
this.value = document.createElement("div");
this.defaultValue = document.createElement("div");
});
it('resolves value from a function', function () {
var me = this;
assert.equal(util.option.asElement(function () {return me.value}, this.defaultValue), this.value);
});
it('returns Element', function () {
assert.equal(util.option.asElement(this.value, this.defaultValue), this.value);
});
it('returns default value for null', function () {
assert.equal(util.option.asElement(null, this.defaultValue), this.defaultValue);
});
it('returns null for undefined', function () {
assert.equal(util.option.asElement(), null);
});
});
describe('binarySearchValue', function () {
it('Finds center target on odd sized array', function () {
assert.equal(
util.binarySearchValue(
@ -820,6 +866,7 @@ describe('mergeOptions', function () {
1
);
});
it('Finds target on odd sized array', function () {
assert.equal(
util.binarySearchValue(
@ -830,6 +877,7 @@ describe('mergeOptions', function () {
2
);
});
it('Cannot find target', function () {
assert.equal(
util.binarySearchValue(

Loading…
Cancel
Save