diff options
author | wout <wout@impinc.co.uk> | 2013-05-28 20:58:52 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-05-28 20:58:52 +0100 |
commit | c7df993012b3c0e8cfee75313041c3c64ad9b9e1 (patch) | |
tree | 5b4358a6c029d5a1763b939e5b60d300f7a4a124 /spec | |
parent | 00532a5e2d547c4761aa888c9bda2e94ee310046 (diff) | |
download | svg.js-c7df993012b3c0e8cfee75313041c3c64ad9b9e1.tar.gz svg.js-c7df993012b3c0e8cfee75313041c3c64ad9b9e1.zip |
Added merge() to SVG.BBox
Diffstat (limited to 'spec')
-rw-r--r-- | spec/index.html | 1 | ||||
-rw-r--r-- | spec/spec/bbox.js | 43 | ||||
-rw-r--r-- | spec/spec/element.js | 31 | ||||
-rw-r--r-- | spec/spec/svg.js | 7 |
4 files changed, 55 insertions, 27 deletions
diff --git a/spec/index.html b/spec/index.html index ca23dec..38150a9 100644 --- a/spec/index.html +++ b/spec/index.html @@ -31,6 +31,7 @@ <script type="text/javascript" src="spec/svg.js"></script> <script type="text/javascript" src="spec/container.js"></script> <script type="text/javascript" src="spec/element.js"></script> +<script type="text/javascript" src="spec/bbox.js"></script> <script type="text/javascript" src="spec/rect.js"></script> <script type="text/javascript" src="spec/ellipse.js"></script> <script type="text/javascript" src="spec/line.js"></script> diff --git a/spec/spec/bbox.js b/spec/spec/bbox.js new file mode 100644 index 0000000..0218e42 --- /dev/null +++ b/spec/spec/bbox.js @@ -0,0 +1,43 @@ +describe('BBox', function() { + + afterEach(function() { + draw.clear() + }) + + it('should create a new instance without passing an element', function() { + var box = new SVG.BBox + expect(box.x).toBe(0) + expect(box.y).toBe(0) + expect(box.cx).toBe(0) + expect(box.cy).toBe(0) + expect(box.width).toBe(0) + expect(box.height).toBe(0) + }) + + describe('merge()', function() { + it('should merge various bounding boxes', function() { + var box1 = draw.rect(100,100).move(50,50).bbox() + var box2 = draw.rect(100,100).move(300,400).bbox() + var box3 = draw.rect(100,100).move(500,100).bbox() + var merged = box1.merge(box2).merge(box3) + expect(merged.x).toBe(50) + expect(merged.y).toBe(50) + expect(merged.cx).toBe(325) + expect(merged.cy).toBe(275) + expect(merged.width).toBe(550) + expect(merged.height).toBe(450) + }) + it('should return a new bbox instance', function() { + var box1 = draw.rect(100,100).move(50,50).bbox() + var box2 = draw.rect(100,100).move(300,400).bbox() + var merged = box1.merge(box2) + expect(box1).not.toBe(merged) + expect(box2).not.toBe(merged) + expect(box1.x).toBe(50) + expect(box1.y).toBe(50) + expect(box2.x).toBe(300) + expect(box2.y).toBe(400) + }) + }) + +})
\ No newline at end of file diff --git a/spec/spec/element.js b/spec/spec/element.js index 51839e5..9e8a204 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -112,6 +112,10 @@ describe('Element', function() { }) describe('transform()', function() { + it('should get the current transformations', function() { + var rect = draw.rect(100,100) + expect(rect.transform()).toEqual(SVG.defaults.trans()) + }) it('should set the translation of and element', function() { var rect = draw.rect(100,100).transform({ x: 10, y: 10 }) expect(rect.node.getAttribute('transform')).toBe('translate(10,10)') @@ -182,33 +186,6 @@ describe('Element', function() { }) }) - describe('bbox()', function() { - it('should return an instance of SVG.BBox', function() { - var rect = draw.rect(100,100) - expect(rect.bbox() instanceof SVG.BBox).toBe(true) - }) - it('should return the correct bounding box', function() { - var rect = draw.rect(105,210).move(2,12) - var box = rect.bbox() - expect(box.x).toBe(2) - expect(box.y).toBe(12) - expect(box.cx).toBe(54.5) - expect(box.cy).toBe(117) - expect(box.width).toBe(105) - expect(box.height).toBe(210) - }) - it('should return the correct bounding within a viewbox', function() { - var rect = draw.size(300,200).viewbox(150,100).rect(105,210).move(2,12) - var box = rect.bbox() - expect(box.x).toBe(2) - expect(box.y).toBe(12) - expect(box.cx).toBe(54.5) - expect(box.cy).toBe(117) - expect(box.width).toBe(105) - expect(box.height).toBe(210) - }) - }) - describe('rbox()', function() { it('should return an instance of SVG.RBox', function() { var rect = draw.rect(100,100) diff --git a/spec/spec/svg.js b/spec/spec/svg.js index 5d3837f..1aecc31 100644 --- a/spec/spec/svg.js +++ b/spec/spec/svg.js @@ -85,6 +85,13 @@ describe('SVG', function() { expect(SVG.get(rect.attr('id'))).toBe(rect) }) + it('should make have all the element\'s methods available', function() { + var element = draw.group() + , got = SVG.get(element.attr('id')) + + expect(got.transform()).toEqual(SVG.defaults.trans()) + expect(got.attr()).toEqual(element.attr()) + }) }) })
\ No newline at end of file |