From 9e6a1dd05116d90cc5f1e9683671bd4f68a289fe Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Fri, 24 Feb 2017 21:50:07 +0100 Subject: added a few missing tests to increase coverage --- spec/SpecRunner.html | 12 ++++++++++ spec/fixture.svg | 10 ++++++++ spec/spec/adopter.js | 22 ++++++++++++++++- spec/spec/array.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- spec/spec/element.js | 36 ++++++++++++++++++++++++++++ spec/spec/utils.js | 10 ++++++++ 6 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 spec/spec/utils.js (limited to 'spec') diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html index eea498f..3163e04 100644 --- a/spec/SpecRunner.html +++ b/spec/SpecRunner.html @@ -27,6 +27,16 @@ + + + + + + + + + + Some description @@ -44,6 +54,7 @@ + @@ -88,6 +99,7 @@ + diff --git a/spec/fixture.svg b/spec/fixture.svg index 34bb671..f910dc1 100644 --- a/spec/fixture.svg +++ b/spec/fixture.svg @@ -1,4 +1,14 @@ + + + + + + + + + + Some description diff --git a/spec/spec/adopter.js b/spec/spec/adopter.js index a8fdd11..a73bc35 100644 --- a/spec/spec/adopter.js +++ b/spec/spec/adopter.js @@ -1,10 +1,12 @@ describe('Adopter', function() { - var path, polyline, polygon + var path, polyline, polygon, linearGradient, radialGradient beforeEach(function() { path = SVG.get('lineAB') polyline = SVG.get('inlineSVG').select('polyline').first() polygon = SVG.get('inlineSVG').select('polygon').first() + linearGradient = SVG.get('inlineSVG').select('linearGradient').first() + radialGradient = SVG.get('inlineSVG').select('radialGradient').first() }) describe('with SVG.Doc instance', function() { @@ -49,6 +51,24 @@ describe('Adopter', function() { expect(polygon.array() instanceof SVG.PointArray).toBeTruthy() }) }) + + describe('with linear SVG.Gradient instance', function() { + it('is instance of SVG.Gradient', function() { + expect(linearGradient instanceof SVG.Gradient).toBeTruthy() + }) + it('has type of linear', function() { + expect(linearGradient.type).toBe('linearGradient') // actually it should be 'linear'. see #606 + }) + }) + + describe('with radial SVG.Gradient instance', function() { + it('is instance of SVG.Gradient', function() { + expect(radialGradient instanceof SVG.Gradient).toBeTruthy() + }) + it('has type of radial', function() { + expect(radialGradient.type).toBe('radialGradient') // actually it should be 'radial'. see #606 + }) + }) describe('with node that has no matching svg.js class', function() { it('wraps the node in the base SVG.Element class', function() { diff --git a/spec/spec/array.js b/spec/spec/array.js index f1d264a..b7e2a29 100644 --- a/spec/spec/array.js +++ b/spec/spec/array.js @@ -1,5 +1,5 @@ describe('Array', function () { - var array + var array, arr1, arr2 it('parses a matrix array correctly to string', function() { array = new SVG.Array([ .343, .669, .119, 0, 0 @@ -9,6 +9,12 @@ describe('Array', function () { expect(array + '').toBe('0.343 0.669 0.119 0 0 0.249 -0.626 0.13 0 0 0.172 0.334 0.111 0 0 0 0 0 1 0') }) + it('parses space seperated string and converts it to array', function() { + expect((new SVG.Array('1 2 3 4')).value).toEqual([1,2,3,4]) + }) + it('parses comma seperated string and converts it to array', function() { + expect((new SVG.Array('1,2,3,4')).value).toEqual([1,2,3,4]) + }) describe('reverse()', function() { it('reverses the array', function() { array = new SVG.Array([1 ,2 ,3, 4, 5]).reverse() @@ -59,6 +65,65 @@ describe('Array', function () { } }) }) + describe('morph()', function() { + it('adds entries so that destination array has equal length', function() { + + arr1 = new SVG.Array([1,2,3,4,5]) + arr2 = new SVG.Array([1,2,3,4]) + + arr1.morph(arr2) + + expect(arr1.destination.length).toBe(arr1.value.length) + }) + it('does the same the other way round', function() { + + arr1 = new SVG.Array([1,2,3,4]) + arr2 = new SVG.Array([1,2,3,4,5]) + + arr1.morph(arr2) + + expect(arr1.destination.length).toBe(arr1.value.length) + }) + }) + describe('settle()', function() { + it('cleans up any duplicate value', function() { + array = new SVG.Array([1,2,3,4,5,4,3,2,1]) + expect(array.settle().sort()).toEqual([1,2,3,4,5].sort()) + }) + }) + describe('at()', function() { + it('returns a new array instance', function() { + arr1 = new SVG.Array([1,2,3,4]) + arr2 = new SVG.Array([2,3,4,5]) + + arr1.morph(arr2) + + start = arr1.at(0) + end = arr1.at(1) + + expect(start instanceof SVG.Array).toBeTruthy() + expect(start).not.toBe(arr1) + + expect(end instanceof SVG.Array).toBeTruthy() + expect(end).not.toBe(arr2) + }) + it('morphs all values of the array', function() { + arr1 = new SVG.Array([1,2,3,4]) + arr2 = new SVG.Array([2,3,4,5]) + + arr1.morph(arr2) + + expect(arr1.at(0.5).value).toEqual([1.5, 2.5, 3.5, 4.5]) + }) + it('returns array if no destination was specified', function() { + arr1 = new SVG.Array([1,2,3,4]) + + arr2 = arr1.at(0.5) + + expect(arr2.value).toEqual([1,2,3,4]) + expect(arr2).toBe(arr1) + }) + }) }) diff --git a/spec/spec/element.js b/spec/spec/element.js index 0dc9124..3482948 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -730,4 +730,40 @@ describe('Element', function() { expect(rect.point(pos.x, pos.y).y).toBeCloseTo(pos.y - translation.y) }) }) + + describe('inside()', function() { + it('checks whether the given point inside the bounding box of the element', function() { + var rect = draw.rect(100,100) + expect(rect.inside(50,50)).toBeTruthy() + expect(rect.inside(150,150)).toBeFalsy() + }) + }) + describe('show()', function() { + it('sets display property to ""', function() { + var rect = draw.rect(100,100).show() + expect(rect.style('display')).toBe('') + }) + }) + describe('hide()', function() { + it('sets display property to none', function() { + var rect = draw.rect(100,100).hide() + expect(rect.style('display')).toBe('none') + }) + }) + describe('visible()', function() { + it('checks if element is hidden or not', function() { + var rect = draw.rect(100,100).hide() + expect(rect.visible()).toBeFalsy() + rect.show() + expect(rect.visible()).toBeTruthy() + }) + }) + describe('is()', function() { + it('checks if element is instance of a certain kind', function() { + var rect = draw.rect(100,100) + expect(rect.is(SVG.Rect)).toBeTruthy() + expect(rect.is(SVG.Element)).toBeTruthy() + expect(rect.is(SVG.Parent)).toBeFalsy() + }) + }) }) diff --git a/spec/spec/utils.js b/spec/spec/utils.js new file mode 100644 index 0000000..be8262e --- /dev/null +++ b/spec/spec/utils.js @@ -0,0 +1,10 @@ +describe('SVG.utils', function() { + describe('degrees()', function() { + it('converts radiant to degrees', function() { + expect(SVG.utils.degrees(Math.PI)).toBe(180) + }) + it('maps to 0 - 360 degree only', function() { + expect(SVG.utils.degrees(2.5 * Math.PI)).toBe(90) + }) + }) +}) \ No newline at end of file -- cgit v1.2.3