summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/SpecRunner.html1
-rw-r--r--spec/spec/element.js26
-rw-r--r--spec/spec/gradient.js30
-rw-r--r--spec/spec/image.js4
-rw-r--r--spec/spec/matrix.js39
-rw-r--r--spec/spec/nested.js13
-rw-r--r--spec/spec/sugar.js291
-rw-r--r--spec/spec/tspan.js6
8 files changed, 404 insertions, 6 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html
index 6ab030b..3aab38d 100644
--- a/spec/SpecRunner.html
+++ b/spec/SpecRunner.html
@@ -84,6 +84,7 @@
<script src="spec/textpath.js"></script>
<script src="spec/doc.js"></script>
<script src="spec/defs.js"></script>
+ <script src="spec/nested.js"></script>
<script src="spec/group.js"></script>
<script src="spec/set.js"></script>
<script src="spec/gradient.js"></script>
diff --git a/spec/spec/element.js b/spec/spec/element.js
index b8a931a..84699e6 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -109,6 +109,18 @@ describe('Element', function() {
expect(draw.defs().select('pattern image').length()).toBe(1)
expect(draw.defs().select('pattern image').first().src).toBe(imageUrl)
})
+ it('correctly creates SVG.Array if array given', function() {
+ rect.attr('something', [2,3,4])
+ expect(rect.attr('something')).toBe('2 3 4')
+ })
+ it('redirects to the leading() method when setting leading', function() {
+ var text = draw.text(loremIpsum)
+ spyOn(text, 'leading')
+
+ text.attr('leading', 2)
+ expect(text.leading).toHaveBeenCalled()
+ text.remove()
+ })
})
describe('id()', function() {
@@ -270,6 +282,10 @@ describe('Element', function() {
rect.transform({ a: 0.5, c: 0.5 })
expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0.5,1,0,0)')
})
+ it('transforms relative using a matrix', function() {
+ rect.transform({ a: 0.5, c: 0.5 }).transform(new SVG.Matrix({ e: 20, f: 20 }), true)
+ expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0.5,1,20,20)')
+ })
})
describe('untransform()', function() {
@@ -290,7 +306,7 @@ describe('Element', function() {
expect(circle.ctm()).toEqual(new SVG.Matrix)
})
})
-
+
describe('matrixify', function() {
var rect
@@ -368,6 +384,14 @@ describe('Element', function() {
var rect = draw.rect(100,100).data('test', 101)
expect(rect.data('test')).toBe(101)
})
+ it('gets the raw value when value is no valid json', function() {
+ var rect = draw.rect(100,100).data('test', '{["sd":12}]', true)
+ expect(rect.data('test')).toBe('{["sd":12}]')
+ })
+ it('removes data when null given', function() {
+ var rect = draw.rect(100,100).data('test', '{"sd":12}', true)
+ expect(rect.data('test', null).attr('data-test')).toBeFalsy()
+ })
it('maintains data type for a number', function() {
var rect = draw.rect(100,100).data('test', 101)
expect(typeof rect.data('test')).toBe('number')
diff --git a/spec/spec/gradient.js b/spec/spec/gradient.js
index e0b061a..3fb74f9 100644
--- a/spec/spec/gradient.js
+++ b/spec/spec/gradient.js
@@ -7,6 +7,10 @@ describe('Gradient', function() {
stop.at({ offset: 0, color: '#333', opacity: 1 })
stop.at({ offset: 1, color: '#fff', opacity: 1 })
})
+ radial = draw.gradient('radial', function(stop) {
+ stop.at({ offset: 0, color: '#333', opacity: 1 })
+ stop.at({ offset: 1, color: '#fff', opacity: 1 })
+ })
})
afterEach(function() {
@@ -28,6 +32,32 @@ describe('Gradient', function() {
expect(gradient.fill()).toBe('url(#' + gradient.attr('id') + ')')
})
})
+
+ describe('from()', function() {
+ it('sets fx and fy attribute for radial gradients', function() {
+ radial.from(7, 10)
+ expect(radial.attr('fx')).toBe(7)
+ expect(radial.attr('fy')).toBe(10)
+ })
+ it('sets x1 and y1 attribute for linear gradients', function() {
+ gradient.from(7, 10)
+ expect(gradient.attr('x1')).toBe(7)
+ expect(gradient.attr('y1')).toBe(10)
+ })
+ })
+
+ describe('to()', function() {
+ it('sets cx and cy attribute for radial gradients', function() {
+ radial.to(75, 105)
+ expect(radial.attr('cx')).toBe(75)
+ expect(radial.attr('cy')).toBe(105)
+ })
+ it('sets x2 and y2 attribute for linear gradients', function() {
+ gradient.to(75, 105)
+ expect(gradient.attr('x2')).toBe(75)
+ expect(gradient.attr('y2')).toBe(105)
+ })
+ })
describe('attr()', function() {
it('will catch transform attribues and convert them to gradientTransform', function() {
diff --git a/spec/spec/image.js b/spec/spec/image.js
index 9ea4610..c81d68a 100644
--- a/spec/spec/image.js
+++ b/spec/spec/image.js
@@ -25,6 +25,10 @@ describe('Image', function() {
done()
})
})
+ it('returns itself when no url given', function() {
+ var img = new SVG.Image()
+ expect(img.load()).toBe(img)
+ })
})
describe('loaded()', function() {
diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js
index 1c74ac2..8fd40b4 100644
--- a/spec/spec/matrix.js
+++ b/spec/spec/matrix.js
@@ -112,6 +112,45 @@ describe('Matrix', function() {
})
})
+ describe('with an array given', function() {
+ it('parses the array correctly', function() {
+ var matrix = new SVG.Matrix([2, 0, 0, 2, 100, 50])
+
+ expect(matrix.a).toBe(2)
+ expect(matrix.b).toBe(0)
+ expect(matrix.c).toBe(0)
+ expect(matrix.d).toBe(2)
+ expect(matrix.e).toBe(100)
+ expect(matrix.f).toBe(50)
+ })
+ })
+
+ describe('with an object given', function() {
+ it('parses the object correctly', function() {
+ var matrix = new SVG.Matrix({a:2, b:0, c:0, d:2, e:100, f:50})
+
+ expect(matrix.a).toBe(2)
+ expect(matrix.b).toBe(0)
+ expect(matrix.c).toBe(0)
+ expect(matrix.d).toBe(2)
+ expect(matrix.e).toBe(100)
+ expect(matrix.f).toBe(50)
+ })
+ })
+
+ describe('with 6 arguments given', function() {
+ it('parses the arguments correctly', function() {
+ var matrix = new SVG.Matrix(2, 0, 0, 2, 100, 50)
+
+ expect(matrix.a).toBe(2)
+ expect(matrix.b).toBe(0)
+ expect(matrix.c).toBe(0)
+ expect(matrix.d).toBe(2)
+ expect(matrix.e).toBe(100)
+ expect(matrix.f).toBe(50)
+ })
+ })
+
})
describe('clone()', function() {
diff --git a/spec/spec/nested.js b/spec/spec/nested.js
new file mode 100644
index 0000000..3113880
--- /dev/null
+++ b/spec/spec/nested.js
@@ -0,0 +1,13 @@
+describe('Nested', function() {
+
+ afterEach(function() {
+ draw.clear()
+ })
+
+ describe('()', function() {
+ it('creates a nested svg of type SVG.Nested', function() {
+ expect(draw.nested() instanceof SVG.Nested).toBeTruthy()
+ })
+ })
+
+})
diff --git a/spec/spec/sugar.js b/spec/spec/sugar.js
index cb9d891..2b9aa4c 100644
--- a/spec/spec/sugar.js
+++ b/spec/spec/sugar.js
@@ -11,28 +11,309 @@ describe('Sugar', function() {
})
describe('fill()', function() {
- it('returns the node reference', function() {
+ beforeEach(function() {
rect = draw.rect(100,100)
+ })
+
+ afterEach(function() {
+ rect.remove()
+ })
+
+ it('returns the node reference', function() {
expect(rect.fill('red')).toBe(rect)
})
it('sets the given value', function() {
- rect = draw.rect(100,100)
expect(rect.fill('red').attr('fill')).toBe('red')
})
it('sets the given value with object given', function() {
- rect = draw.rect(100,100)
rect.fill({color: 'red', opacity: 0.5, rule: 'odd'})
expect(rect.attr('fill')).toBe('red')
expect(rect.attr('fill-opacity')).toBe(0.5)
expect(rect.attr('fill-rule')).toBe('odd')
})
- it('is a nop with no argument given and returns noce reference', function() {
- rect = draw.rect(100,100).fill('red')
+ it('is a nop with no argument given and returns node reference', function() {
+ rect.fill('red')
expect(rect.fill()).toBe(rect)
expect(rect.attr('fill')).toBe('red')
})
})
+
+ describe('rotate()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'transform')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.transform.calls.reset()
+ })
+
+ it('redirects to transform()', function() {
+ rect.rotate(1,2,3)
+ expect(rect.transform).toHaveBeenCalledWith({ rotation: 1, cx: 2, cy: 3 })
+ })
+ })
+
+ describe('skew()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'transform')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.transform.calls.reset()
+ })
+
+ it('redirects to transform() with no argument', function() {
+ rect.skew()
+ expect(rect.transform).toHaveBeenCalledWith({ skewX: undefined, skewY: undefined, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with one argument', function() {
+ rect.skew(5)
+ expect(rect.transform).toHaveBeenCalledWith({ skew: 5, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with two argument', function() {
+ rect.skew(5, 6)
+ expect(rect.transform).toHaveBeenCalledWith({ skewX: 5, skewY: 6, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with three arguments', function() {
+ rect.skew(5, 6, 7)
+ expect(rect.transform).toHaveBeenCalledWith({ skew: 5, cx: 6, cy: 7 })
+ })
+
+ it('redirects to transform() with four arguments', function() {
+ rect.skew(5, 6, 7, 8)
+ expect(rect.transform).toHaveBeenCalledWith({ skewX: 5, skewY: 6, cx: 7, cy: 8 })
+ })
+ })
+
+ describe('scale()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'transform')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.transform.calls.reset()
+ })
+
+ it('redirects to transform() with no argument', function() {
+ rect.scale()
+ expect(rect.transform).toHaveBeenCalledWith({ scaleX: undefined, scaleY: undefined, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with one argument', function() {
+ rect.scale(5)
+ expect(rect.transform).toHaveBeenCalledWith({ scale: 5, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with two argument', function() {
+ rect.scale(5, 6)
+ expect(rect.transform).toHaveBeenCalledWith({ scaleX: 5, scaleY: 6, cx: undefined, cy: undefined })
+ })
+
+ it('redirects to transform() with three arguments', function() {
+ rect.scale(5, 6, 7)
+ expect(rect.transform).toHaveBeenCalledWith({ scale: 5, cx: 6, cy: 7 })
+ })
+
+ it('redirects to transform() with four arguments', function() {
+ rect.scale(5, 6, 7, 8)
+ expect(rect.transform).toHaveBeenCalledWith({ scaleX: 5, scaleY: 6, cx: 7, cy: 8 })
+ })
+ })
+
+ describe('translate()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'transform')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.transform.calls.reset()
+ })
+
+ it('redirects to transform()', function() {
+ rect.translate(1,2)
+ expect(rect.transform).toHaveBeenCalledWith({ x: 1, y: 2 })
+ })
+ })
+
+ describe('flip()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'transform')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.transform.calls.reset()
+ })
+
+ it('redirects to transform()', function() {
+ rect.flip(1,2)
+ expect(rect.transform).toHaveBeenCalledWith({ flip: 1, offset: 2 })
+ })
+ })
+
+ describe('matrix()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'attr')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.attr.calls.reset()
+ })
+
+ it('redirects to attr() directly with one argument', function() {
+ rect.matrix([1,2,3,4,5,6])
+ expect(rect.attr).toHaveBeenCalledWith('transform', new SVG.Matrix([1,2,3,4,5,6]))
+ })
+
+ it('redirects to attr() directly with 6 arguments', function() {
+ rect.matrix(1,2,3,4,5,6)
+ expect(rect.attr).toHaveBeenCalledWith('transform', new SVG.Matrix([1,2,3,4,5,6]))
+ })
+ })
+
+ describe('opacity()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'attr')
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.attr.calls.reset()
+ })
+
+ it('redirects to attr() directly', function() {
+ rect.opacity(0.5)
+ expect(rect.attr).toHaveBeenCalledWith('opacity', 0.5)
+ })
+ })
+
+ describe('dx() / dy()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'x').and.callThrough()
+ spyOn(rect, 'y').and.callThrough()
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.x.calls.reset()
+ rect.y.calls.reset()
+ })
+
+ it('redirects to x() / y() with adding the current value', function() {
+ rect.dx(5)
+ rect.dy(5)
+ expect(rect.x).toHaveBeenCalledWith(5, true)
+ expect(rect.y).toHaveBeenCalledWith(5, true)
+ })
+ })
+
+ describe('dmove()', function() {
+ var rect, spy, undefined
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ spyOn(rect, 'dx').and.callThrough()
+ spyOn(rect, 'dy').and.callThrough()
+ })
+
+ afterEach(function() {
+ rect.remove()
+ rect.dx.calls.reset()
+ rect.dy.calls.reset()
+ })
+
+ it('redirects to dx() / dy() directly', function() {
+ rect.dmove(5,5)
+ expect(rect.dx).toHaveBeenCalledWith(5)
+ expect(rect.dy).toHaveBeenCalledWith(5)
+ })
+ })
+
+ describe('font()', function() {
+ var text, spy, undefined
+
+ beforeEach(function() {
+ text = draw.text(loremIpsum)
+ spyOn(text, 'leading')
+ spyOn(text, 'attr')
+ })
+
+ afterEach(function() {
+ text.remove()
+ text.leading.calls.reset()
+ text.attr.calls.reset()
+ })
+
+ it('sets leading when given', function() {
+ text.font({leading: 3})
+ expect(text.leading).toHaveBeenCalledWith(3)
+ })
+
+ it('sets text-anchor when anchor given', function() {
+ text.font({anchor: 'start'})
+ expect(text.attr).toHaveBeenCalledWith('text-anchor', 'start')
+ })
+
+ it('sets all font properties via attr()', function() {
+ text.font({
+ size: 20,
+ family: 'Verdana',
+ weight: 'bold',
+ stretch: 'wider',
+ variant: 'small-caps',
+ style: 'italic'
+ })
+ expect(text.attr).toHaveBeenCalledWith('font-size', 20)
+ expect(text.attr).toHaveBeenCalledWith('font-family', 'Verdana')
+ expect(text.attr).toHaveBeenCalledWith('font-weight', 'bold')
+ expect(text.attr).toHaveBeenCalledWith('font-stretch', 'wider')
+ expect(text.attr).toHaveBeenCalledWith('font-variant', 'small-caps')
+ expect(text.attr).toHaveBeenCalledWith('font-style', 'italic')
+ })
+
+ it('redirects all other stuff directly to attr()', function() {
+ text.font({
+ foo:'bar',
+ bar:'baz'
+ })
+ expect(text.attr).toHaveBeenCalledWith('foo', 'bar')
+ expect(text.attr).toHaveBeenCalledWith('bar', 'baz')
+ })
+ })
+
})
diff --git a/spec/spec/tspan.js b/spec/spec/tspan.js
index 4a3fde6..d8ac4b1 100644
--- a/spec/spec/tspan.js
+++ b/spec/spec/tspan.js
@@ -26,6 +26,12 @@ describe('Tspan', function() {
tspan = text.tspan('Hello World').newLine()
expect(tspan.text()).toBe('Hello World\n')
})
+ it('calls the function when function given', function() {
+ var spy = jasmine.createSpy('dummy')
+ tspan = text.tspan('Hello World')
+ tspan.text(spy)
+ expect(spy).toHaveBeenCalledWith(tspan)
+ })
})
describe('dx()', function() {