summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-02-27 22:45:59 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-02-27 22:45:59 +0100
commit2621c26e3e4965c4ce9d0fb28c21568cc1fe78ef (patch)
treec8ce58ac5a08a0df4ecafbdef53131cd72be9bf5
parent16c7266b7f60362be5fc176614b77072a1b3e3f0 (diff)
downloadsvg.js-2621c26e3e4965c4ce9d0fb28c21568cc1fe78ef.tar.gz
svg.js-2621c26e3e4965c4ce9d0fb28c21568cc1fe78ef.zip
added test cases to increase coverage
-rw-r--r--.config/karma.conf.js9
-rw-r--r--spec/fixtures/pixel.pngbin0 -> 119 bytes
-rw-r--r--spec/spec/helper.js4
-rw-r--r--spec/spec/image.js88
-rw-r--r--spec/spec/text.js38
-rw-r--r--spec/spec/tspan.js40
6 files changed, 156 insertions, 23 deletions
diff --git a/.config/karma.conf.js b/.config/karma.conf.js
index 174fe13..f2bdfeb 100644
--- a/.config/karma.conf.js
+++ b/.config/karma.conf.js
@@ -26,9 +26,18 @@ module.exports = function(config) {
included: false,
served: true
},
+ {
+ pattern: 'spec/fixtures/pixel.png',
+ included: false,
+ served: true
+ },
'dist/svg.js',
'spec/spec/**/*.js'
],
+
+ proxies: {
+ '/fixtures/': '/base/spec/fixtures/'
+ },
// list of files to exclude
diff --git a/spec/fixtures/pixel.png b/spec/fixtures/pixel.png
new file mode 100644
index 0000000..818c71d
--- /dev/null
+++ b/spec/fixtures/pixel.png
Binary files differ
diff --git a/spec/spec/helper.js b/spec/spec/helper.js
index 9cd88cd..24b4991 100644
--- a/spec/spec/helper.js
+++ b/spec/spec/helper.js
@@ -8,7 +8,7 @@ draw = SVG(drawing).size(100,100)
svgPath = 'M88.006,61.994c3.203,0,6.216-1.248,8.481-3.514C98.752,56.215,100,53.203,100,50c0-3.204-1.248-6.216-3.513-8.481 c-2.266-2.265-5.278-3.513-8.481-3.513c-2.687,0-5.237,0.877-7.327,2.496h-7.746l5.479-5.479 c5.891-0.757,10.457-5.803,10.457-11.896c0-6.614-5.381-11.995-11.994-11.995c-6.093,0-11.14,4.567-11.896,10.457l-5.479,5.479 v-7.747c1.618-2.089,2.495-4.641,2.495-7.327c0-3.204-1.247-6.216-3.513-8.481C56.216,1.248,53.204,0,50,0 c-3.204,0-6.216,1.248-8.481,3.513c-2.265,2.265-3.513,5.277-3.513,8.481c0,2.686,0.877,5.237,2.495,7.327v7.747l-5.479-5.479 c-0.757-5.89-5.803-10.457-11.896-10.457c-6.614,0-11.995,5.381-11.995,11.995c0,6.093,4.567,11.139,10.458,11.896l5.479,5.479 h-7.747c-2.089-1.619-4.641-2.496-7.327-2.496c-3.204,0-6.216,1.248-8.481,3.513C1.248,43.784,0,46.796,0,50 c0,3.203,1.248,6.216,3.513,8.48c2.265,2.266,5.277,3.514,8.481,3.514c2.686,0,5.237-0.877,7.327-2.496h7.747l-5.479,5.479 c-5.891,0.757-10.458,5.804-10.458,11.896c0,6.614,5.381,11.994,11.995,11.994c6.093,0,11.139-4.566,11.896-10.457l5.479-5.479 v7.749c-3.63,4.7-3.291,11.497,1.018,15.806C43.784,98.752,46.796,100,50,100c3.204,0,6.216-1.248,8.481-3.514 c4.309-4.309,4.647-11.105,1.018-15.806v-7.749l5.479,5.479c0.757,5.891,5.804,10.457,11.896,10.457 c6.613,0,11.994-5.38,11.994-11.994c0-6.093-4.566-11.14-10.457-11.896l-5.479-5.479h7.746 C82.769,61.117,85.319,61.994,88.006,61.994z M76.874,68.354c4.705,0,8.52,3.814,8.52,8.521c0,4.705-3.814,8.52-8.52,8.52 s-8.52-3.814-8.52-8.52l-12.33-12.33V81.98c3.327,3.328,3.327,8.723,0,12.049c-3.327,3.328-8.722,3.328-12.049,0 c-3.327-3.326-3.327-8.721,0-12.049V64.544l-12.33,12.33c0,4.705-3.814,8.52-8.52,8.52s-8.52-3.814-8.52-8.52 c0-4.706,3.814-8.521,8.52-8.521l12.33-12.33H18.019c-3.327,3.328-8.722,3.328-12.049,0c-3.327-3.326-3.327-8.721,0-12.048 s8.722-3.327,12.049,0h17.438l-12.33-12.33c-4.706,0-8.52-3.814-8.52-8.52c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52 l12.33,12.33V18.019c-3.327-3.327-3.327-8.722,0-12.049s8.722-3.327,12.049,0s3.327,8.722,0,12.049v17.438l12.33-12.33 c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52c0,4.705-3.814,8.52-8.52,8.52l-12.33,12.33h17.438 c3.327-3.327,8.722-3.327,12.049,0s3.327,8.722,0,12.048c-3.327,3.328-8.722,3.328-12.049,0H64.544L76.874,68.354z'
// image url
-imageUrl = ''
+imageUrl = 'fixtures/pixel.png'
// lorem ipsum text
loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sodales\n imperdiet auctor. Nunc ultrices lectus at erat dictum pharetra\n elementum ante posuere. Duis turpis risus, blandit nec elementum et,\n posuere eget lacus. Aliquam et risus magna, eu aliquet nibh. Fusce\n consequat mi quis purus varius sagittis euismod urna interdum.\n Curabitur aliquet orci quis felis semper vulputate. Vestibulum ac nisi\n magna, id dictum diam. Proin sed metus vel magna blandit\n sodales. Pellentesque at neque ultricies nunc euismod rutrum ut in\n lorem. Mauris euismod tellus in tellus tempus interdum. Phasellus\n mattis sapien et leo feugiat dictum. Vestibulum at volutpat velit.'
@@ -39,4 +39,4 @@ function dispatchEvent(element, name) {
element.node.dispatchEvent(e)
else
element.node.fireEvent('on' + name, e)
-} \ No newline at end of file
+}
diff --git a/spec/spec/image.js b/spec/spec/image.js
index 2dabbaf..9ea4610 100644
--- a/spec/spec/image.js
+++ b/spec/spec/image.js
@@ -1,14 +1,76 @@
describe('Image', function() {
var image
-
+
beforeEach(function() {
image = draw.image(imageUrl, 100, 100)
})
-
+
afterEach(function() {
draw.clear()
})
-
+
+
+ describe('()', function() {
+ it('should set width and height automatically if no size is given', function(done) {
+ image = draw.image(imageUrl).loaded(function() {
+ expect(image.node.getAttribute('height')).toBe('1')
+ expect(image.node.getAttribute('width')).toBe('1')
+ done()
+ })
+ })
+ it('should set width and height if size is given', function(done) {
+ image = draw.image(imageUrl, 100, 100).loaded(function() {
+ expect(image.node.getAttribute('height')).toBe('100')
+ expect(image.node.getAttribute('width')).toBe('100')
+ done()
+ })
+ })
+ })
+
+ describe('loaded()', function() {
+ beforeEach(function(done) {
+ loadCb = {cb: function(){ done() }}
+ errorCb = jasmine.createSpy('errorCb')
+ spyOn(loadCb, 'cb').and.callThrough()
+ image = draw.image(imageUrl, 100, 100).loaded(loadCb.cb).error(errorCb)
+ })
+
+ it('should set the load callback', function() {
+ expect(image._loaded).toBe(loadCb.cb)
+ })
+ it('executes the load callback', function() {
+ expect(loadCb.cb).toHaveBeenCalledWith({
+ width: 1,
+ height: 1,
+ ratio: 1,
+ url: jasmine.any(String)
+ })
+ })
+ it('does not execute the error callback', function() {
+ expect(errorCb).not.toHaveBeenCalled()
+ })
+ })
+
+ describe('error()', function() {
+ beforeEach(function(done) {
+ loadCb = jasmine.createSpy('loadCb')
+ errorCb = {cb: function(){ done() }}
+ spyOn(errorCb, 'cb').and.callThrough()
+ image = draw.image('not_existant.jpg', 100, 100).loaded(loadCb).error(errorCb.cb)
+ })
+
+ it('should set the error callback', function() {
+ expect(image._error).toBe(errorCb.cb)
+ })
+ it('executes the error callback', function() {
+ expect(errorCb.cb).toHaveBeenCalledWith(jasmine.any(Event))
+ })
+ it('does not execute the load callback', function() {
+ expect(loadCb).not.toHaveBeenCalled()
+ })
+ })
+
+
describe('x()', function() {
it('should return the value of x without an argument', function() {
expect(image.x()).toBe(0)
@@ -19,7 +81,7 @@ describe('Image', function() {
expect(box.x).toBe(123)
})
})
-
+
describe('y()', function() {
it('should return the value of y without an argument', function() {
expect(image.y()).toBe(0)
@@ -30,7 +92,7 @@ describe('Image', function() {
expect(box.y).toBe(345)
})
})
-
+
describe('cx()', function() {
it('should return the value of cx without an argument', function() {
expect(image.cx()).toBe(50)
@@ -41,7 +103,7 @@ describe('Image', function() {
expect(box.cx).toBe(123)
})
})
-
+
describe('cy()', function() {
it('should return the value of cy without an argument', function() {
expect(image.cy()).toBe(50)
@@ -52,7 +114,7 @@ describe('Image', function() {
expect(box.cy).toBe(345)
})
})
-
+
describe('move()', function() {
it('should set the x and y position', function() {
image.move(123,456)
@@ -85,7 +147,7 @@ describe('Image', function() {
expect(image.node.getAttribute('y')).toBe('85')
})
})
-
+
describe('center()', function() {
it('should set the cx and cy position', function() {
image.center(321,567)
@@ -114,7 +176,7 @@ describe('Image', function() {
expect(image.height().toString()).toBe(image.node.getAttribute('height'))
})
})
-
+
describe('size()', function() {
it('should define the width and height of the element', function() {
image.size(987,654)
@@ -134,17 +196,17 @@ describe('Image', function() {
expect(image.width() / image.height()).toBe(box.width / box.height)
})
})
-
+
describe('scale()', function() {
it('should scale the element universally with one argument', function() {
var box = image.scale(2).rbox()
-
+
expect(box.width).toBe(image.attr('width') * 2)
expect(box.height).toBe(image.attr('height') * 2)
})
it('should scale the element over individual x and y axes with two arguments', function() {
var box = image.scale(2, 3.5).rbox()
-
+
expect(box.width).toBe(image.attr('width') * 2)
expect(box.height).toBe(image.attr('height') * 3.5)
})
@@ -156,7 +218,7 @@ describe('Image', function() {
expect(image.node.getAttribute('transform')).toBe('matrix(1,0,0,1,12,12)')
})
})
-
+
})
diff --git a/spec/spec/text.js b/spec/spec/text.js
index 1e3a6cc..690cf3d 100644
--- a/spec/spec/text.js
+++ b/spec/spec/text.js
@@ -13,6 +13,30 @@ describe('Text', function() {
draw.clear()
})
+ describe('leading()', function() {
+ it('returns the leading value of the text without an argument', function() {
+ expect(text.leading() instanceof SVG.Number)
+ expect(text.leading().valueOf()).toBe(1.3)
+ })
+ it('sets the leading value of the text with the first argument', function() {
+ expect(text.leading(1.5).dom.leading.valueOf()).toBe(1.5)
+ })
+ })
+
+ describe('rebuild()', function() {
+ it('disables the rebuild if called with false', function() {
+ expect(text.rebuild(false)._rebuild).toBeFalsy()
+ })
+ it('enables the rebuild if called with true', function() {
+ expect(text.rebuild(true)._rebuild).toBeTruthy()
+ })
+ it('rebuilds the text without an argument given', function() {
+ var dy = text.lines().get(2).attr('dy')
+ text.leading(1.7)
+ expect(dy == text.lines().get(2).attr('dy')).toBeFalsy()
+ })
+ })
+
describe('x()', function() {
it('returns the value of x without an argument', function() {
expect(text.x()).toBe(0)
@@ -21,6 +45,12 @@ describe('Text', function() {
text.x(123)
expect(text.node.getAttribute('x')).toBeCloseTo(123)
})
+ it('sets the value of all lines', function() {
+ text.x(200)
+ text.lines().each(function() {
+ expect(this.x()).toBe(200)
+ })
+ })
it('sets the value of y with a percent value', function() {
text.x('40%')
expect(text.node.getAttribute('x')).toBe('40%')
@@ -267,11 +297,3 @@ describe('Text', function() {
})
})
-
-
-
-
-
-
-
-
diff --git a/spec/spec/tspan.js b/spec/spec/tspan.js
new file mode 100644
index 0000000..4a3fde6
--- /dev/null
+++ b/spec/spec/tspan.js
@@ -0,0 +1,40 @@
+describe('Tspan', function() {
+ var text, tspan
+
+ beforeEach(function() {
+ text = draw.text(loremIpsum)
+ tspan = text.tspan('Hello World')
+ })
+
+ afterEach(function() {
+ draw.clear()
+ })
+
+ describe('newLine()', function() {
+ it('converts the tspan to a line', function() {
+ tspan = text.tspan('Hello World')
+ expect(tspan.newLine().dom.newLined).toBeTruthy()
+ })
+ })
+
+ describe('text()', function() {
+ it('returns the text of the tspan without newline when not newlined', function() {
+ tspan = text.tspan('Hello World')
+ expect(tspan.text()).toBe('Hello World')
+ })
+ it('returns the text of the tspan with newline when newlined', function() {
+ tspan = text.tspan('Hello World').newLine()
+ expect(tspan.text()).toBe('Hello World\n')
+ })
+ })
+
+ describe('dx()', function() {
+ it('gets the dx value with no argument', function() {
+ tspan.attr('dx', 25)
+ expect(tspan.dx()).toBe(25)
+ })
+ it('sets the dx value whith the first argument', function() {
+ expect(tspan.dx(25).attr('dx')).toBe(25)
+ })
+ })
+})