<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" />
</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... -->
<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>
<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" />
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() {
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() {
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
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()
}
})
})
+ 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)
+ })
+ })
})
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()
+ })
+ })
})
--- /dev/null
+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