diff options
author | wout <wout@impinc.co.uk> | 2014-01-22 12:48:49 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-22 12:48:49 +0100 |
commit | b27d01e9f91bff6145170ebd46857cd703480fec (patch) | |
tree | aca9a0b30423ec4f7db769969ae5f3b25c7893df /spec | |
parent | df8db4b03df6740e47851907a4b901362634c50b (diff) | |
download | svg.js-b27d01e9f91bff6145170ebd46857cd703480fec.tar.gz svg.js-b27d01e9f91bff6145170ebd46857cd703480fec.zip |
Bumped to v0.33
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/container.js | 4 | ||||
-rw-r--r-- | spec/spec/doc.js | 15 | ||||
-rw-r--r-- | spec/spec/element.js | 27 | ||||
-rw-r--r-- | spec/spec/ellipse.js | 33 | ||||
-rw-r--r-- | spec/spec/image.js | 20 | ||||
-rw-r--r-- | spec/spec/line.js | 28 | ||||
-rw-r--r-- | spec/spec/path.js | 45 | ||||
-rw-r--r-- | spec/spec/polygon.js | 24 | ||||
-rw-r--r-- | spec/spec/polyline.js | 24 | ||||
-rw-r--r-- | spec/spec/rect.js | 33 |
10 files changed, 241 insertions, 12 deletions
diff --git a/spec/spec/container.js b/spec/spec/container.js index 4aaa68a..47a871e 100644 --- a/spec/spec/container.js +++ b/spec/spec/container.js @@ -262,8 +262,8 @@ describe('Container', function() { expect(draw.node.getAttribute('viewBox')).toBe('0 0 50 50') }) it('should accept negative values', function() { - draw.size(100,100).viewbox(-100,-100,-50,-50) - expect(draw.node.getAttribute('viewBox')).toEqual('-100 -100 -50 -50') + draw.size(100,100).viewbox(-100,-100,50,50) + expect(draw.node.getAttribute('viewBox')).toEqual('-100 -100 50 50') }) it('should get the viewbox if no arguments are given', function() { draw.viewbox(0,0,100,100) diff --git a/spec/spec/doc.js b/spec/spec/doc.js index 1d5eaa5..4312678 100644 --- a/spec/spec/doc.js +++ b/spec/spec/doc.js @@ -1,11 +1,20 @@ describe('Doc', function() { - it('should be an instance of SVG.Container', function() { + it('is an instance of SVG.Container', function() { expect(draw instanceof SVG.Container).toBe(true) }) - it('should have a defs element', function() { - expect(draw instanceof SVG.Container).toBe(true) + it('has a defs element', function() { + expect(draw._defs instanceof SVG.Defs).toBe(true) + }) + + describe('defs()', function() { + it('returns defs element', function(){ + expect(draw.defs()).toBe(draw._defs) + }) + it('references parent node', function(){ + expect(draw.defs().parent).toBe(draw) + }) }) })
\ No newline at end of file diff --git a/spec/spec/element.js b/spec/spec/element.js index cbe4088..acb5de5 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -203,7 +203,7 @@ describe('Element', function() { var box = rect.rbox() expect(approximately(box.x)).toBe(approximately(2)) expect(approximately(box.y)).toBe(approximately(12)) - expect(approximately(box.cx)).toBe(approximately(54).5) + expect(approximately(box.cx)).toBe(approximately(54.5)) expect(approximately(box.cy)).toBe(approximately(117)) expect(approximately(box.width)).toBe(approximately(105)) expect(approximately(box.height)).toBe(approximately(210)) @@ -258,6 +258,31 @@ describe('Element', function() { expect(rect + '').toBe(rect.attr('id')) }) }) + + describe('replace()', function() { + it('replaces the original element by another given element', function() { + var rect = draw.rect(100,100).center(321,567).fill('#f06') + var circle = draw.circle(200) + var rectIndex = draw.children().indexOf(rect) + + rect.replace(circle) + + expect(rectIndex).toBe(draw.children().indexOf(circle)) + }) + it('removes the original element', function() { + var rect = draw.rect(100,100).center(321,567).fill('#f06') + + rect.replace(draw.circle(200)) + + expect(draw.has(rect)).toBe(false) + }) + it('returns the new element', function() { + var circle = draw.circle(200) + var element = draw.rect(100,100).center(321,567).fill('#f06').replace(circle) + + expect(element).toBe(circle) + }) + }) }) diff --git a/spec/spec/ellipse.js b/spec/spec/ellipse.js index 507ec7a..27d1840 100644 --- a/spec/spec/ellipse.js +++ b/spec/spec/ellipse.js @@ -52,6 +52,19 @@ describe('Ellipse', function() { expect(box.cy).toBe(345) }) }) + + describe('radius()', function() { + it('should set the rx and ry', function() { + ellipse.radius(10,20) + expect(ellipse.node.getAttribute('rx')).toBe('10') + expect(ellipse.node.getAttribute('ry')).toBe('20') + }) + it('should set the rx and ry if only rx given', function() { + ellipse.radius(30) + expect(ellipse.node.getAttribute('rx')).toBe('30') + expect(ellipse.node.getAttribute('ry')).toBe('30') + }) + }) describe('move()', function() { it('should set the x and y position', function() { @@ -70,6 +83,26 @@ describe('Ellipse', function() { expect(box.cy).toBe(567) }) }) + + describe('width()', function() { + it('sets the width of the element', function() { + ellipse.width(82) + expect(ellipse.node.getAttribute('rx')).toBe('41') + }) + it('gets the width of the element if the argument is null', function() { + expect((ellipse.width() / 2).toString()).toBe(ellipse.node.getAttribute('rx')) + }) + }) + + describe('height()', function() { + it('sets the height of the element', function() { + ellipse.height(1236) + expect(ellipse.node.getAttribute('ry')).toBe('618') + }) + it('gets the height of the element if the argument is null', function() { + expect((ellipse.height() / 2).toString()).toBe(ellipse.node.getAttribute('ry')) + }) + }) describe('size()', function() { it('defines the rx and ry of the element', function() { diff --git a/spec/spec/image.js b/spec/spec/image.js index dec462b..798ea08 100644 --- a/spec/spec/image.js +++ b/spec/spec/image.js @@ -69,6 +69,26 @@ describe('Image', function() { expect(box.cy).toBe(567) }) }) + + describe('width()', function() { + it('sets the width of the element', function() { + image.width(789) + expect(image.node.getAttribute('width')).toBe('789') + }) + it('gets the width of the element if the argument is null', function() { + expect(image.width().toString()).toBe(image.node.getAttribute('width')) + }) + }) + + describe('height()', function() { + it('sets the height of the element', function() { + image.height(1236) + expect(image.node.getAttribute('height')).toBe('1236') + }) + it('gets the height of the element if the argument is null', function() { + expect(image.height().toString()).toBe(image.node.getAttribute('height')) + }) + }) describe('size()', function() { it('should define the width and height of the element', function() { diff --git a/spec/spec/line.js b/spec/spec/line.js index 91874b9..1ed45fb 100644 --- a/spec/spec/line.js +++ b/spec/spec/line.js @@ -74,6 +74,34 @@ describe('Line', function() { expect(box.y).toBe(517) }) }) + + describe('width()', function() { + it('sets the width of the element', function() { + line.width(400) + var box = line.bbox() + expect(box.x).toBe(0) + expect(box.x + box.width).toBe(400) + }) + it('get the width of the element without argument', function() { + line.width(123) + var box = line.bbox() + expect(line.width()).toBe(box.width) + }) + }) + + describe('height()', function() { + it('sets the height of the element', function() { + line.height(300) + var box = line.bbox() + expect(box.y).toBe(0) + expect(box.y + box.height).toBe(300) + }) + it('gets the height of the element without argument', function() { + line.height(456) + var box = line.bbox() + expect(line.height()).toBe(box.height) + }) + }) describe('size()', function() { it('should define the width and height of the element', function() { diff --git a/spec/spec/path.js b/spec/spec/path.js index 77ef77c..a64f8aa 100644 --- a/spec/spec/path.js +++ b/spec/spec/path.js @@ -76,6 +76,30 @@ describe('Path', function() { expect(box.y).toBe(517) }) }) + + describe('width()', function() { + it('sets the width of the element', function() { + path.width(234) + var box = path.bbox() + expect(approximately(box.width, 0.1)).toBe(234) + }) + it('gets the width of the element aithout an agrument', function() { + path.width(456) + expect(approximately(path.width(), 0.1)).toBe(456) + }) + }) + + describe('height()', function() { + it('sets the height of the element', function() { + path.height(654) + var box = path.bbox() + expect(approximately(box.height, 0.1)).toBe(654) + }) + it('gets the height of the element aithout an agrument', function() { + path.height(321) + expect(approximately(path.height(), 0.1)).toBe(321) + }) + }) describe('size()', function() { it('should define the width and height of the element', function() { @@ -88,16 +112,18 @@ describe('Path', function() { describe('scale()', function() { it('should scale the element universally with one argument', function() { - var box = path.scale(2).bbox() + var box1 = path.bbox() + , box2 = path.scale(2).bbox() - expect(box.width).toBe(path._offset.width * 2) - expect(box.height).toBe(path._offset.height * 2) + expect(box1.width * 2).toBe(box2.width) + expect(box1.height * 2).toBe(box2.height) }) it('should scale the element over individual x and y axes with two arguments', function() { - var box = path.scale(2, 3.5).bbox() + var box1 = path.bbox() + , box2 = path.scale(2, 3.5).bbox() - expect(box.width).toBe(path._offset.width * 2) - expect(box.height).toBe(path._offset.height * 3.5) + expect(box1.width * 2).toBe(box2.width) + expect(box1.height * 3.5).toBe(box2.height) }) }) @@ -107,6 +133,13 @@ describe('Path', function() { expect(path.node.getAttribute('transform')).toBe('translate(12 12)') }) }) + + describe('plot()', function() { + it('falls back to a single point without an argument', function() { + path = draw.path() + expect(path.node.getAttribute('d')).toBe('M0,0') + }) + }) }) diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js index f0f131f..a124796 100644 --- a/spec/spec/polygon.js +++ b/spec/spec/polygon.js @@ -70,6 +70,30 @@ describe('Polygon', function() { expect(box.y).toBe(517) }) }) + + describe('width()', function() { + it('sets the width and height of the element', function() { + polygon.width(987) + var box = polygon.bbox() + expect(approximately(box.width, 0.1)).toBe(987) + }) + it('gets the width and height of the element without an argument', function() { + polygon.width(789) + expect(approximately(polygon.width(), 0.1)).toBe(789) + }) + }) + + describe('height()', function() { + it('sets the height and height of the element', function() { + polygon.height(987) + var box = polygon.bbox() + expect(approximately(box.height, 0.1)).toBe(987) + }) + it('gets the height and height of the element without an argument', function() { + polygon.height(789) + expect(approximately(polygon.height(), 0.1)).toBe(789) + }) + }) describe('size()', function() { it('should define the width and height of the element', function() { diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js index c8dcc00..9272d78 100644 --- a/spec/spec/polyline.js +++ b/spec/spec/polyline.js @@ -70,6 +70,30 @@ describe('Polyline', function() { expect(box.y).toBe(517) }) }) + + describe('width()', function() { + it('sets the width and height of the element', function() { + polyline.width(987) + var box = polyline.bbox() + expect(approximately(box.width, 0.1)).toBe(987) + }) + it('gets the width and height of the element without an argument', function() { + polyline.width(789) + expect(approximately(polyline.width(), 0.1)).toBe(789) + }) + }) + + describe('height()', function() { + it('sets the height and height of the element', function() { + polyline.height(987) + var box = polyline.bbox() + expect(approximately(box.height, 0.1)).toBe(987) + }) + it('gets the height and height of the element without an argument', function() { + polyline.height(789) + expect(approximately(polyline.height(), 0.1)).toBe(789) + }) + }) describe('size()', function() { it('should define the width and height of the element', function() { diff --git a/spec/spec/rect.js b/spec/spec/rect.js index 2ebab04..4b9ef2f 100644 --- a/spec/spec/rect.js +++ b/spec/spec/rect.js @@ -52,6 +52,19 @@ describe('Rect', function() { expect(box.cy).toBe(345) }) }) + + describe('radius()', function() { + it('should set the rx and ry', function() { + rect.radius(10,20) + expect(rect.node.getAttribute('rx')).toBe('10') + expect(rect.node.getAttribute('ry')).toBe('20') + }) + it('should set the rx and ry if only rx given', function() { + rect.radius(30) + expect(rect.node.getAttribute('rx')).toBe('30') + expect(rect.node.getAttribute('ry')).toBe('30') + }) + }) describe('move()', function() { it('should set the x and y position', function() { @@ -70,6 +83,26 @@ describe('Rect', function() { }) }) + describe('width()', function() { + it('sets the width of the element', function() { + rect.width(789) + expect(rect.node.getAttribute('width')).toBe('789') + }) + it('gets the width of the element if the argument is null', function() { + expect(rect.width().toString()).toBe(rect.node.getAttribute('width')) + }) + }) + + describe('height()', function() { + it('sets the height of the element', function() { + rect.height(1236) + expect(rect.node.getAttribute('height')).toBe('1236') + }) + it('gets the height of the element if the argument is null', function() { + expect(rect.height().toString()).toBe(rect.node.getAttribute('height')) + }) + }) + describe('size()', function() { it('should define the width and height of the element', function() { rect.size(987,654) |