From 2b2a4040f69fde2fb6555c663da8ef6235639dd0 Mon Sep 17 00:00:00 2001 From: wout Date: Fri, 31 Jan 2014 16:22:01 +0100 Subject: Added morph() and at() methods to SVG.Color --- spec/spec/color.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/spec/color.js b/spec/spec/color.js index ca74bca..526b544 100644 --- a/spec/spec/color.js +++ b/spec/spec/color.js @@ -1,24 +1,66 @@ describe('Color', function() { + var color + + beforeEach(function() { + color = new SVG.Color({ r: 0, g: 102, b: 255 }) + }) it('correclty parses a rgb string', function() { - var color = new SVG.Color('rgb(255,0,128)') + color = new SVG.Color('rgb(255,0,128)') expect(color.r).toBe(255) expect(color.g).toBe(0) expect(color.b).toBe(128) }) it('correclty parses a 3 digit hex string', function() { - var color = new SVG.Color('#f06') + color = new SVG.Color('#f06') expect(color.r).toBe(255) expect(color.g).toBe(0) expect(color.b).toBe(102) }) it('correclty parses a 6 digit hex string', function() { - var color = new SVG.Color('#0066ff') + color = new SVG.Color('#0066ff') expect(color.r).toBe(0) expect(color.g).toBe(102) expect(color.b).toBe(255) }) -}) \ No newline at end of file + describe('toHex()', function() { + it('returns a hex color', function() { + expect(color.toHex()).toBe('#0066ff') + }) + }) + + describe('toRgb()', function() { + it('returns a rgb string color', function() { + expect(color.toRgb()).toBe('rgb(0,102,255)') + }) + }) + + describe('brightness()', function() { + it('returns the percieved brightness value of a color', function() { + expect(color.brightness()).toBe(0.346) + }) + }) + + describe('morph()', function() { + it('prepares the color for morphing', function() { + var destination = new SVG.Color + color.morph(destination) + expect(color.destination).toEqual(destination) + }) + }) + + describe('at()', function() { + it('morphes color to a given position', function() { + var destination = new SVG.Color + var morphed = color.morph(destination).at(0.5) + expect(morphed.r).toBe(0) + expect(morphed.g).toBe(51) + expect(morphed.b).toBe(127) + }) + }) + +}) + -- cgit v1.2.3