diff --git a/lib/shared/ColorPicker.js b/lib/shared/ColorPicker.js index f48d6f6e..e0694fb2 100644 --- a/lib/shared/ColorPicker.js +++ b/lib/shared/ColorPicker.js @@ -92,7 +92,7 @@ class ColorPicker { * Supported formats: * 'red' --> HTML color string * '#ffffff' --> hex string - * 'rbg(255,255,255)' --> rgb string + * 'rgb(255,255,255)' --> rgb string * 'rgba(255,255,255,1.0)' --> rgba string * {r:255,g:255,b:255} --> rgb object * {r:255,g:255,b:255,a:1.0} --> rgba object diff --git a/test/ColorPicker.test.js b/test/ColorPicker.test.js index 30671013..6852179c 100644 --- a/test/ColorPicker.test.js +++ b/test/ColorPicker.test.js @@ -114,10 +114,87 @@ describe('ColorPicker', function () { assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); }); - it('handles null', function () { + it('throws error when color is null', function () { var colorPicker = new ColorPicker(); - colorPicker.setColor('none'); + assert.throws(function () {colorPicker.setColor(null);}, Error, null); + }); + + it('handles html color string', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor('black'); + assert.deepEqual(colorPicker.color, { r: 0, g: 0, b: 0, a: 1 }); + }); + + it('handles hex string', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor('#ffff00'); + assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 0, a: 1 }); + }); + + it('handles rgb string', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor('rgb(255,255,255)'); assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); }); + + it('handles rgba string', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor('rgba(255,255,255,1)'); + assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); + }); + + it('handles rgb object', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor({r:255,g:255,b:255}); + assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); + }); + + it('handles rgba object', function () { + var colorPicker = new ColorPicker(); + colorPicker.setColor({r:255,g:255,b:255,a:1}); + assert.deepEqual(colorPicker.color, { r: 255, g: 255, b: 255, a: 1 }); + }); + }); + + describe('show', function () { + + it('calls closeCallback', function () { + var colorPicker = new ColorPicker(); + var callback = sinon.spy(); + colorPicker.setCloseCallback(callback); + colorPicker.show(); + assert(callback.called); + assert(callback.calledOnce); + }); + + 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'); + }); + }); + describe('_save', function () { + + it('triggers updateCallback', function () { + var colorPicker = new ColorPicker(); + var callback = sinon.spy(); + colorPicker.setUpdateCallback(callback); + colorPicker._save(); + assert(callback.called); + assert(callback.calledOnce); + }); + }); + + describe('_apply', function () { + + it('triggers updateCallback', function () { + var colorPicker = new ColorPicker(); + var callback = sinon.spy(); + colorPicker.setUpdateCallback(callback); + colorPicker._apply(); + assert(callback.called); + assert(callback.calledOnce); + }); }); }); diff --git a/test/Configurator.test.js b/test/Configurator.test.js index c43ef051..c37ed574 100644 --- a/test/Configurator.test.js +++ b/test/Configurator.test.js @@ -38,11 +38,11 @@ describe('Configurator', function () { assert.equal(JSON.stringify(config.options), JSON.stringify(config.defaultOptions)); }); - it('with undefined will set enabled to true', function () { + it('with undefined will set enabled to false', function () { var config = new Configurator(Network, this.container); config.options.enabled = false; config.setOptions(); - assert.equal(JSON.stringify(config.options), JSON.stringify(config.defaultOptions)); + assert.equal(config.options.enabled, false); }); it('with string sets filter and set enabled to true', function () { diff --git a/test/Popup.test.js b/test/Popup.test.js index 07ab860a..f79f2acf 100644 --- a/test/Popup.test.js +++ b/test/Popup.test.js @@ -57,7 +57,7 @@ describe('Popup', function () { assert(isNaN(popup.y)); }); - it('handles null with NaN', function () { + it('handles undefined with NaN', function () { var popup = new Popup(this.container); popup.setPosition(undefined, undefined); assert(isNaN(popup.x)); diff --git a/test/canvas-mock.js b/test/canvas-mock.js index fa7a08f9..8d3fb606 100644 --- a/test/canvas-mock.js +++ b/test/canvas-mock.js @@ -22,6 +22,7 @@ function replaceCanvasContext (el) { setTransform: function(){}, drawImage: function(){}, save: function(){}, + text: function(){}, fillText: function(){}, restore: function(){}, beginPath: function(){}, @@ -32,6 +33,7 @@ function replaceCanvasContext (el) { translate: function(){}, scale: function(){}, rotate: function(){}, + circle: function(){}, arc: function(){}, fill: function(){}, @@ -44,10 +46,10 @@ function replaceCanvasContext (el) { width: 12*text.length, height: 14 }; - }, + } }; } -}; +} /** @@ -59,7 +61,7 @@ function replaceCanvasContext (el) { * The override is only done if there is no 2D context already present. * This allows for normal running in a browser, and for node.js the usage of 'canvas'. * - * @param {object} the current global window object. This can possible come from module 'jsdom', + * @param {object} window - current global window object. This can possible come from module 'jsdom', * when running under node.js. */ function mockify(window) {