diff options
author | wout <wout@impinc.co.uk> | 2013-06-29 15:16:58 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-06-29 15:16:58 +0100 |
commit | e4fb8522a2c57069b2523f16de92d5eb7e6dd85e (patch) | |
tree | 003e0b4dcfd0ff4006e4d45a96b5b7600a0f9396 /spec | |
parent | 9845c4952ab6011e1b8b70a24b7065c2e9c21b7a (diff) | |
download | svg.js-e4fb8522a2c57069b2523f16de92d5eb7e6dd85e.tar.gz svg.js-e4fb8522a2c57069b2523f16de92d5eb7e6dd85e.zip |
IMplemented <use> element, bumped to v0.23
Diffstat (limited to 'spec')
-rw-r--r-- | spec/index.html | 1 | ||||
-rw-r--r-- | spec/spec/container.js | 9 | ||||
-rw-r--r-- | spec/spec/element.js | 29 | ||||
-rw-r--r-- | spec/spec/gradient.js | 6 | ||||
-rw-r--r-- | spec/spec/use.js | 25 |
5 files changed, 59 insertions, 11 deletions
diff --git a/spec/index.html b/spec/index.html index d619acd..0c7d208 100644 --- a/spec/index.html +++ b/spec/index.html @@ -44,6 +44,7 @@ <script type="text/javascript" src="spec/doc.js"></script> <script type="text/javascript" src="spec/group.js"></script> <script type="text/javascript" src="spec/gradient.js"></script> +<script type="text/javascript" src="spec/use.js"></script> <script type="text/javascript" src="spec/mask.js"></script> <script type="text/javascript" src="spec/clip.js"></script> <script type="text/javascript" src="spec/color.js"></script> diff --git a/spec/spec/container.js b/spec/spec/container.js index 11727d7..4aaa68a 100644 --- a/spec/spec/container.js +++ b/spec/spec/container.js @@ -185,17 +185,22 @@ describe('Container', function() { }) describe('clear()', function() { - it('should remove all children', function() { + it('removes all children', function() { draw.rect(100,100) draw.clear() expect(draw.children().length).toBe(0) }) - it('should keep the defs node', function() { + it('keeps the defs node', function() { var oldDefs = draw.defs() draw.rect(100,100).maskWith(draw.circle(100, 100)) draw.clear() expect(draw.defs()).toBe(oldDefs) }) + it('clears all children in the defs node', function() { + draw.rect(100,100).maskWith(draw.circle(100, 100)) + draw.clear() + expect(draw.defs().children().length).toBe(0) + }) }) describe('each()', function() { diff --git a/spec/spec/element.js b/spec/spec/element.js index bea8481..6deeffb 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -190,11 +190,11 @@ describe('Element', function() { }) describe('rbox()', function() { - it('should return an instance of SVG.RBox', function() { + it('returns an instance of SVG.RBox', function() { var rect = draw.rect(100,100) expect(rect.rbox() instanceof SVG.RBox).toBe(true) }) - it('should return the correct rectangular box', function() { + it('returns the correct rectangular box', function() { var rect = draw.size(200,150).viewbox(0,0,200,150).rect(105,210).move(2,12) var box = rect.rbox() expect(box.x).toBe(2) @@ -204,7 +204,7 @@ describe('Element', function() { expect(box.width).toBe(105) expect(box.height).toBe(210) }) - it('should return the correct rectangular box within a viewbox', function() { + it('returns the correct rectangular box within a viewbox', function() { var rect = draw.size(200,150).viewbox(0,0,100,75).rect(105,210).move(2,12) var box = rect.rbox() expect(box.x).toBe(1) @@ -217,18 +217,18 @@ describe('Element', function() { }) describe('doc()', function() { - it('should return the parent document', function() { + it('returns the parent document', function() { var rect = draw.rect(100,100) expect(rect.doc()).toBe(draw) }) }) describe('parent', function() { - it('should contain the parent svg', function() { + it('contains the parent svg', function() { var rect = draw.rect(100,100) expect(rect.parent).toBe(draw) }) - it('should contain the parent group when in a group', function() { + it('contains the parent group when in a group', function() { var group = draw.group() , rect = group.rect(100,100) expect(rect.parent).toBe(group) @@ -236,16 +236,27 @@ describe('Element', function() { }) describe('clone()', function() { - it('should make an exact copy of the element', function() { + it('makes an exact copy of the element', function() { var rect = draw.rect(100,100).center(321,567).fill('#f06') clone = rect.clone() expect(rect.attr('id', null).attr()).toEqual(clone.attr('id', null).attr()) }) - it('should assign a new id to the cloned element', function() { + it('assigns a new id to the cloned element', function() { var rect = draw.rect(100,100).center(321,567).fill('#f06') clone = rect.clone() expect(rect.attr('id')).not.toEqual(clone.attr('id')) }) }) + + describe('toString()', function() { + it('returns the element id', function() { + var rect = draw.rect(100,100).center(321,567).fill('#f06') + expect(rect + '').toBe(rect.attr('id')) + }) + }) -})
\ No newline at end of file +}) + + + + diff --git a/spec/spec/gradient.js b/spec/spec/gradient.js index 8aef33e..e13e113 100644 --- a/spec/spec/gradient.js +++ b/spec/spec/gradient.js @@ -13,6 +13,12 @@ describe('Gradient', function() { it('returns the id of the gradient wrapped in url()', function() { expect(gradient.fill()).toBe('url(#' + gradient.attr('id') + ')') }) + }) + + describe('toString()', function() { + it('returns the id of the gradient wrapped in url()', function() { + expect(gradient + '').toBe('url(#' + gradient.attr('id') + ')') + }) it('is called when instance is passed as an attribute value', function() { rect.attr('fill', gradient) expect(rect.attr('fill')).toBe('url(#' + gradient.attr('id') + ')') diff --git a/spec/spec/use.js b/spec/spec/use.js new file mode 100644 index 0000000..5a6bbd6 --- /dev/null +++ b/spec/spec/use.js @@ -0,0 +1,25 @@ +describe('Use', function() { + var use, rect + + beforeEach(function() { + rect = draw.rect(100,100) + use = draw.use(rect) + }) + + it('creates an instance of SVG.Use', function() { + expect(use instanceof SVG.Use).toBe(true) + }) + + it('sets the target element id to its href attribute', function() { + expect(use.attr('xlink:href')).toBe('#' + rect) + }) + + it('stores a reference to the target element', function() { + expect(use.target).toBe(rect) + }) + + it('adopts the geometry of the target element', function() { + expect(use.bbox()).toEqual(rect.bbox()) + }) + +})
\ No newline at end of file |