From c7df993012b3c0e8cfee75313041c3c64ad9b9e1 Mon Sep 17 00:00:00 2001 From: wout Date: Tue, 28 May 2013 20:58:52 +0100 Subject: Added merge() to SVG.BBox --- spec/index.html | 1 + spec/spec/bbox.js | 43 +++++++++++++++++++++++++++++++++++++++++++ spec/spec/element.js | 31 ++++--------------------------- spec/spec/svg.js | 7 +++++++ 4 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 spec/spec/bbox.js (limited to 'spec') 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 @@ + 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 -- cgit v1.2.3