})
})
describe('at()', function() {
- it('returns a new array instance', function() {
+ beforeEach(function() {
arr1 = new SVG.Array([1,2,3,4])
arr2 = new SVG.Array([2,3,4,5])
-
+ })
+
+ it('returns a new array instance', function() {
arr1.morph(arr2)
start = arr1.at(0)
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)
+ it('returns itself if no destination was specified', function() {
+ expect(arr1.at(0.5)).toBe(arr1)
})
})
})
expect(array.value).toEqual([[1,2]])
})
+
+ describe('at()', function() {
+ var arr1, arr2
+
+ beforeEach(function() {
+ arr1 = new SVG.PointArray([[1,2],[3,4]])
+ arr2 = new SVG.Array([[2,3],[4,5]])
+ })
+
+ it('returns a new array instance', function() {
+ arr1.morph(arr2)
+
+ start = arr1.at(0)
+ end = arr1.at(1)
+
+ expect(start instanceof SVG.PointArray).toBeTruthy()
+ expect(start).not.toBe(arr1)
+
+ expect(end instanceof SVG.PointArray).toBeTruthy()
+ expect(end).not.toBe(arr2)
+ })
+ it('morphs all values of the array', function() {
+ arr1.morph(arr2)
+ expect(arr1.at(0.5).value).toEqual([[1.5, 2.5], [3.5, 4.5]])
+ })
+ it('returns itself if no destination was specified', function() {
+ expect(arr1.at(0.5)).toBe(arr1)
+ })
+ })
})
describe('PathArray', function () {
expect(p2.toString()).toBe('M10 80C50 90 75 90 105 160S255 310 285 240T585 540Q637 550 680 620Z ')
expect(p3.toString()).toBe('M80 80A45 45 0 0 0 125 125L125 80Z ')
expect(p4.toString()).toBe('M215.458 245.23C215.458 245.23 292.861 245.23 309.73199999999997 245.23S405 216.451 405 138.054S329.581 15 287.9 15C246.21999999999997 15 147.97599999999997 15 117.21199999999999 15C86.45 15 15 60.65 15 134.084C15 207.518 111.259 246.221 129.122 246.221C146.984 246.221 215.458 245.23 215.458 245.23Z ')
-
+ })
+
+ // this test is designed to cover a certain line but it doesnt work because of #608
+ it('returns the valueOf when PathArray is given', function() {
+ var p = new SVG.PathArray('m10 10 h 80 v 80 h -80 l 300 400 z')
+
+ expect((new SVG.PathArray(p)).value).toEqual(p.value)
+ })
+
+ it('can handle all formats which can be used', function() {
+ // when no command is specified after move, line is used automatically (specs say so)
+ expect(new SVG.PathArray('M10 10 80 80 30 30 Z').toString()).toBe('M10 10L80 80L30 30Z ')
+
+ // parsing can handle 0.5.3.3.2 stuff
+ expect(new SVG.PathArray('M10 10L.5.5.3.3Z').toString()).toBe('M10 10L0.5 0.5L0.3 0.3Z ')
})
describe('move()', function() {
it('references the clipped element in the clipPath target list', function() {
expect(rect.clipper.targets.indexOf(rect) > -1).toBe(true)
})
+
+ it('reuses clip element when clip was given', function() {
+ var clip = rect.clipper
+ expect(draw.rect(100,100).clipWith(clip).clipper).toBe(clip)
+ })
it('unclips all clipped elements when being removed', function() {
rect.clipper.remove()
expect(morphed.g).toBe(102)
expect(morphed.b).toBe(255)
})
+
+ it('returns itself when no destination specified', function() {
+ expect(color.at(0.5)).toBe(color)
+ })
})
})
expect(draw.get(3)).toBeNull()
})
})
+
+ describe('first()', function() {
+ it('gets the first child', function() {
+ draw.clear()
+ var rect = draw.rect(100,100)
+ var circle = draw.circle(100)
+ var line = draw.line(0,0,100,100)
+ expect(draw.first()).toBe(rect)
+ })
+ })
+
+ describe('last()', function() {
+ it('gets the last child', function() {
+ draw.clear()
+ var rect = draw.rect(100,100)
+ var circle = draw.circle(100)
+ var line = draw.line(0,0,100,100)
+ expect(draw.last()).toBe(line)
+ })
+ })
describe('has()', function() {
it('determines if a given element is a child of the parent', function() {
})
})
+ describe('defs()', function() {
+ it('returns the defs from the svg', function() {
+ var g = draw.group()
+ expect(g.defs()).toBe(draw.doc().defs())
+ expect(g.defs() instanceof SVG.Defs).toBeTruthy()
+ })
+ })
+
})
--- /dev/null
+describe('SVG.easing', function() {
+ var easedValues = {
+ '-':0.5,
+ '<>':0.5,
+ '>':0.7071,
+ '<':0.2929,
+ }
+
+ ;['-', '<>', '<', '>'].forEach(function(el) {
+ describe(el, function() {
+ it('is 0 at 0', function() {
+ expect(SVG.easing[el](0)).toBe(0)
+ })
+ it('is 1 at 1', function() {
+ expect(Math.round(SVG.easing[el](1)*1000)/1000).toBe(1) // we need to round cause for some reason at some point 1==0.999999999
+ })
+ it('is eased at 0.5', function() {
+ expect(SVG.easing[el](0.5)).toBeCloseTo(easedValues[el])
+ })
+ })
+ })
+})
expect(rect.attr('svgjs:data')).toBe('{"foo":"bar","number":"3px"}')
})
+ it('recursively dumps the data', function() {
+ var g = draw.group()
+ rect = g.rect(100,100)
+ g.dom.foo = 'bar'
+ rect.dom.number = new SVG.Number('3px')
+
+ g.writeDataToDom()
+
+ expect(g.attr('svgjs:data')).toBe('{"foo":"bar"}')
+ expect(rect.attr('svgjs:data')).toBe('{"number":"3px"}')
+ })
+ it('uses lines() instead of each() when dealing with text', function() {
+ var text = draw.text('Hello\nWorld')
+ text.writeDataToDom()
+ expect(text.attr('svgjs:data')).toBe('{"leading":"1.3"}')
+ expect(text.lines().first().attr('svgjs:data')).toBe('{"newLined":true}')
+ })
})
describe('setData()', function() {
describe('on()', function() {
- it('attaches and event to the element', function() {
+ it('attaches an event to the element', function() {
dispatchEvent(rect.on('event', action), 'event')
expect(toast).toBe('ready')
})
+ it('attaches an event to a non svg element', function() {
+ var body = document.getElementsByTagName('body')[0]
+ SVG.on(body, 'event', action)
+ body.dispatchEvent(new CustomEvent('event'))
+ expect(toast).toBe('ready')
+ SVG.off(body, 'event', action)
+ })
it('attaches multiple handlers on different element', function() {
var listenerCnt = SVG.listeners.length
expect(rect.masker.targets.indexOf(rect) > -1).toBe(true)
})
+ it('reuses mask element when mask was given', function() {
+ var mask = rect.masker
+ expect(draw.rect(100,100).maskWith(mask).masker).toBe(mask)
+ })
+
it('unmasks all masked elements when being removed', function() {
rect.masker.remove()
expect(rect.attr('mask')).toBe(undefined)
})
})
+
+ describe('clone()', function() {
+ it('returns a clone of the matrix', function() {
+ var matrix = new SVG.Matrix(2, 0, 0, 5, 0, 0)
+ , clone = matrix.clone()
+ expect(matrix).not.toBe(clone)
+ for(var i in 'abcdef') {
+ expect(matrix[i]).toEqual(clone[i])
+ }
+ })
+ })
describe('morph()', function() {
it('stores a given matrix for morphing', function() {
expect(matrix2.toString()).toBe('matrix(1,0,0,1,4,3)')
expect(matrix3.toString()).toBe('matrix(1.5,0,0,3,2,1.5)')
})
+ it('returns itself when no destination specified', function() {
+ var matrix = new SVG.Matrix(2, 0, 0, 5, 0, 0)
+ expect(matrix.at(0.5)).toBe(matrix)
+ })
})
describe('multiply()', function() {
it('use the unit of this number as the unit of the returned number when the destination number as no unit', function() {
expect(expect(new SVG.Number('100s').morph(50).at(0.5).unit).toBe('s'))
})
+ it('returns itself when no destination specified', function() {
+ expect(number.at(0.5)).toBe(number)
+ })
})
})
describe('clone()', function() {
it('returns cloned point', function() {
var point1 = new SVG.Point(1,1)
- , point2 = new SVG.Point(point1)
+ , point2 = point1.clone()
expect(point1).toEqual(point2)
expect(point1).not.toBe(point2)
expect(point3).toEqual(new SVG.Point(1.5, 1.5))
})
+ it('returns itself when no destination specified', function() {
+ var point = new SVG.Point(1,1)
+ expect(point.at(0.4)).toBe(point)
+ })
})
describe('transform()', function() {
})
})
+ describe('prepare()', function() {
+ var drawing, wrapper, parser
+
+ beforeEach(function() {
+ wrapper = document.createElement('div')
+ document.getElementsByTagName('body')[0].appendChild(wrapper)
+ drawing = SVG(wrapper)
+
+ parser = document.getElementsByTagName('body')[0].lastChild
+ })
+
+ it('creates a parser element when calling SVG()', function() {
+ expect(SVG.parser.draw.node.nodeName).toBe('svg')
+ })
+ it('hides the parser', function() {
+ expect(SVG.parser.draw.node.getAttribute('style')).toBe('opacity: 0; position: fixed; left: 100%; top: 100%; overflow: hidden;')
+ })
+ it('holds polyline and path', function() {
+ expect(SVG.select('polyline', SVG.parser.draw.node).first().type).toBe('polyline')
+ expect(SVG.select('path', SVG.parser.draw.node).first().type).toBe('path')
+ })
+ })
+
})
\ No newline at end of file
expect(viewbox2.toString()).toBe('50 -100 300 300')
expect(viewbox3.toString()).toBe('30 0 250 300')
})
+ it('returns itself when no destination given', function() {
+ var viewbox = new SVG.ViewBox(10, 100, 200, 300)
+ expect(viewbox.at(0.5)).toBe(viewbox)
+ })
})
})
\ No newline at end of file