aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-02-24 21:50:07 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-02-24 21:50:07 +0100
commit9e6a1dd05116d90cc5f1e9683671bd4f68a289fe (patch)
treed4bf5075e373f844041157816c5ea0a786fe27c9 /spec
parent5044f8ac2851019a7ce92e5884971d2aec5b306b (diff)
downloadsvg.js-9e6a1dd05116d90cc5f1e9683671bd4f68a289fe.tar.gz
svg.js-9e6a1dd05116d90cc5f1e9683671bd4f68a289fe.zip
added a few missing tests to increase coverage
Diffstat (limited to 'spec')
-rw-r--r--spec/SpecRunner.html12
-rw-r--r--spec/fixture.svg10
-rw-r--r--spec/spec/adopter.js22
-rw-r--r--spec/spec/array.js67
-rw-r--r--spec/spec/element.js36
-rw-r--r--spec/spec/utils.js10
6 files changed, 155 insertions, 2 deletions
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 @@
<body>
<svg height="0" width="0" id="inlineSVG">
+ <defs>
+ <linearGradient>
+ <stop offset="5%" stop-color="green"/>
+ <stop offset="95%" stop-color="gold"/>
+ </linearGradient>
+ <radialGradient>
+ <stop offset="10%" stop-color="gold"/>
+ <stop offset="95%" stop-color="green"/>
+ </radialGradient>
+ </defs>
<desc>Some description</desc>
<path id="lineAB" d="M 100 350 l 150 -300" stroke="red" stroke-width="3" fill="none" />
<path id="lineBC" d="M 250 50 l 150 300" stroke="red" stroke-width="3" fill="none" />
@@ -44,6 +54,7 @@
</g>
<polygon points="200,10 250,190 160,210" />
<polyline points="20,20 40,25 60,40 80,120 120,140 200,180" />
+
</svg>
<!-- include spec files here... -->
@@ -88,6 +99,7 @@
<script src="spec/viewbox.js"></script>
<script src="spec/sugar.js"></script>
<script src="spec/fx.js"></script>
+ <script src="spec/utils.js"></script>
<script type="text/javascript" src="spec/helper.js"></script>
</body>
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 @@
<svg height="0" width="0" id="inlineSVG">
+ <defs>
+ <linearGradient>
+ <stop offset="5%" stop-color="green"/>
+ <stop offset="95%" stop-color="gold"/>
+ </linearGradient>
+ <radialGradient>
+ <stop offset="10%" stop-color="gold"/>
+ <stop offset="95%" stop-color="green"/>
+ </radialGradient>
+ </defs>
<desc>Some description</desc>
<path id="lineAB" d="M 100 350 l 150 -300" stroke="red" stroke-width="3" fill="none" />
<path id="lineBC" d="M 250 50 l 150 300" stroke="red" stroke-width="3" fill="none" />
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