diff options
author | wout <wout@impinc.co.uk> | 2014-02-14 22:25:12 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-14 22:25:12 +0100 |
commit | 8f9ccb16300142307b8ed6aed46c2a4984545600 (patch) | |
tree | 77040e5aa3802c7890d67aa0a62cdff432c2359f /spec | |
parent | a7d61df3e8e065599c42752d60bb2f0190395080 (diff) | |
download | svg.js-8f9ccb16300142307b8ed6aed46c2a4984545600.tar.gz svg.js-8f9ccb16300142307b8ed6aed46c2a4984545600.zip |
Completely reworked `SVG.Text`, `SVG.TSpan` and `SVG.PathArray` and bumped to 1.0.0-rc.5
Diffstat (limited to 'spec')
-rwxr-xr-x[-rw-r--r--] | spec/index.html | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/lib/jasmine-1.3.1/MIT.LICENSE | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/lib/jasmine-1.3.1/jasmine-html.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/lib/jasmine-1.3.1/jasmine.css | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/lib/jasmine-1.3.1/jasmine.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/arrange.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/array.js | 42 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/bbox.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/clip.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/color.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/container.js | 30 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/doc.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/element.js | 33 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/ellipse.js | 25 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/gradient.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/group.js | 24 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/helper.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/hyperlink.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/image.js | 25 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/line.js | 36 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/mask.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/memory.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/number.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/path.js | 38 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/pattern.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/polygon.js | 28 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/polyline.js | 28 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/rect.js | 25 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/set.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/svg.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/text.js | 162 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/textpath.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/spec/use.js | 0 |
33 files changed, 431 insertions, 65 deletions
diff --git a/spec/index.html b/spec/index.html index 2044a3e..2044a3e 100644..100755 --- a/spec/index.html +++ b/spec/index.html diff --git a/spec/lib/jasmine-1.3.1/MIT.LICENSE b/spec/lib/jasmine-1.3.1/MIT.LICENSE index 7c435ba..7c435ba 100644..100755 --- a/spec/lib/jasmine-1.3.1/MIT.LICENSE +++ b/spec/lib/jasmine-1.3.1/MIT.LICENSE diff --git a/spec/lib/jasmine-1.3.1/jasmine-html.js b/spec/lib/jasmine-1.3.1/jasmine-html.js index 543d569..543d569 100644..100755 --- a/spec/lib/jasmine-1.3.1/jasmine-html.js +++ b/spec/lib/jasmine-1.3.1/jasmine-html.js diff --git a/spec/lib/jasmine-1.3.1/jasmine.css b/spec/lib/jasmine-1.3.1/jasmine.css index 8c008dc..8c008dc 100644..100755 --- a/spec/lib/jasmine-1.3.1/jasmine.css +++ b/spec/lib/jasmine-1.3.1/jasmine.css diff --git a/spec/lib/jasmine-1.3.1/jasmine.js b/spec/lib/jasmine-1.3.1/jasmine.js index 476d4b8..476d4b8 100644..100755 --- a/spec/lib/jasmine-1.3.1/jasmine.js +++ b/spec/lib/jasmine-1.3.1/jasmine.js diff --git a/spec/spec/arrange.js b/spec/spec/arrange.js index 195c322..195c322 100644..100755 --- a/spec/spec/arrange.js +++ b/spec/spec/arrange.js diff --git a/spec/spec/array.js b/spec/spec/array.js index 375326c..c051976 100644..100755 --- a/spec/spec/array.js +++ b/spec/spec/array.js @@ -26,4 +26,46 @@ describe('PointArray', function () { expect(array + '').toBe('0,0.15 -100,-3.141592654 50,100') }) +}) + +/* toUpperCase() for Firefox */ +describe('PathArray', function () { + var p1, p2 + + beforeEach(function() { + p1 = new SVG.PathArray('m10 10 h 80 v 80 h -80 l 300 400 z') + p2 = new SVG.PathArray('m10 80 c 40 10 65 10 95 80 s 150 150 180 80 t 300 300 q 52 10 95 80 z') + p3 = new SVG.PathArray('m80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 z') + }) + + it('converts to absolute values', function() { + expect(p1.toString()).toBe('M10 10H90V90H10L310 490Z ') + expect(p2.toString()).toBe('M10 80C50 90 75 90 105 160S255 310 285 240T585 540Q637 550 680 620Z ') + expect(p3.toString()).toBe('M80 80A45 45 0 0 0 125 125L125 80Z ') + }) + + describe('move()', function() { + it('moves all points in a straight path', function() { + expect(p1.move(100,200).toString()).toBe('M100 200H180V280H100L400 680Z ') + }) + it('moves all points in a curved path', function() { + expect(p2.move(100,200).toString()).toBe('M100 200C140 210 165 210 195 280S345 430 375 360T675 660Q727 670 770 740Z ') + }) + it('moves all points in a arc path', function() { + expect(p3.move(100,200).toString()).toBe('M100 200A45 45 0 0 0 145 245L145 200Z ') + }) + }) + + describe('size()', function() { + it('resizes all points in a straight path', function() { + expect(p1.size(600,200).toString()).toBe('M10 10H170V43.333333333333336H10L610 210Z ') + }) + it('resizes all points in a curved path', function() { + expect(p2.size(600,200).toString()).toBe('M10 80C45.82089552238806 83.70370370370371 68.2089552238806 83.70370370370371 95.07462686567165 109.62962962962963S229.40298507462686 165.1851851851852 256.2686567164179 139.25925925925927T524.9253731343283 250.37037037037038Q571.4925373134329 254.07407407407408 610 280Z ') + }) + it('resizes all points in a arc path', function() { + expect(p3.size(600,200).toString()).toBe('M80 80A599.9998982747568 199.9999660915856 0 0 0 679.9998982747568 279.99996609158563L679.9998982747568 80Z ') + }) + }) + })
\ No newline at end of file diff --git a/spec/spec/bbox.js b/spec/spec/bbox.js index 44c1eb8..44c1eb8 100644..100755 --- a/spec/spec/bbox.js +++ b/spec/spec/bbox.js diff --git a/spec/spec/clip.js b/spec/spec/clip.js index fb673f0..fb673f0 100644..100755 --- a/spec/spec/clip.js +++ b/spec/spec/clip.js diff --git a/spec/spec/color.js b/spec/spec/color.js index 6bae4c8..6bae4c8 100644..100755 --- a/spec/spec/color.js +++ b/spec/spec/color.js diff --git a/spec/spec/container.js b/spec/spec/container.js index 02bc4e9..f72ec17 100644..100755 --- a/spec/spec/container.js +++ b/spec/spec/container.js @@ -165,24 +165,44 @@ describe('Container', function() { }) describe('text()', function() { - it('should increase children by 1', function() { + it('increases children by 1', function() { var initial = draw.children().length draw.text(loremIpsum) expect(draw.children().length).toBe(initial + 1) }) - it('should create a rect', function() { + it('creates a text element', function() { expect(draw.text(loremIpsum).type).toBe('text') }) - it('should create an instance of SVG.Rect', function() { + it('creates an instance of SVG.Rect', function() { expect(draw.text(loremIpsum) instanceof SVG.Text).toBe(true) }) - it('should be an instance of SVG.Shape', function() { + it('is an instance of SVG.Shape', function() { expect(draw.text(loremIpsum) instanceof SVG.Shape).toBe(true) }) - it('should be an instance of SVG.Element', function() { + it('is an instance of SVG.Element', function() { expect(draw.text(loremIpsum) instanceof SVG.Element).toBe(true) }) }) + + describe('plain()', function() { + it('increases children by 1', function() { + var initial = draw.children().length + draw.plain(loremIpsum) + expect(draw.children().length).toBe(initial + 1) + }) + it('creates a plain element', function() { + expect(draw.plain(loremIpsum).type).toBe('text') + }) + it('creates an instance of SVG.Rect', function() { + expect(draw.plain(loremIpsum) instanceof SVG.Text).toBe(true) + }) + it('is an instance of SVG.Shape', function() { + expect(draw.plain(loremIpsum) instanceof SVG.Shape).toBe(true) + }) + it('is an instance of SVG.Element', function() { + expect(draw.plain(loremIpsum) instanceof SVG.Element).toBe(true) + }) + }) describe('clear()', function() { it('removes all children', function() { diff --git a/spec/spec/doc.js b/spec/spec/doc.js index 4312678..4312678 100644..100755 --- a/spec/spec/doc.js +++ b/spec/spec/doc.js diff --git a/spec/spec/element.js b/spec/spec/element.js index 67d12f0..22b09bf 100644..100755 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -314,39 +314,6 @@ describe('Element', function() { expect(element).toBe(circle) }) }) - - describe('relative()', function() { - var rect - - beforeEach(function() { - rect = draw.rect(100,100).move(50,60) - }) - - afterEach(function() { - draw.clear() - }) - - describe('x()', function() { - it('moves the x positon of the element', function() { - rect.relative().x(100) - expect(rect.node.getAttribute('x')).toBe('150') - }) - }) - describe('y()', function() { - it('moves the y positon of the element', function() { - rect.relative().x(120) - expect(rect.node.getAttribute('x')).toBe('170') - }) - }) - describe('move()', function() { - it('moves the x and y positon of the element', function() { - rect.relative().move(80, 25) - expect(rect.node.getAttribute('x')).toBe('130') - expect(rect.node.getAttribute('y')).toBe('85') - }) - }) - - }) }) diff --git a/spec/spec/ellipse.js b/spec/spec/ellipse.js index 7d7101a..f9e6387 100644..100755 --- a/spec/spec/ellipse.js +++ b/spec/spec/ellipse.js @@ -74,6 +74,31 @@ describe('Ellipse', function() { expect(box.y).toBe(456) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + ellipse.move(50,60) + ellipse.dx(100) + expect(ellipse.node.getAttribute('cx')).toBe('270') + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + ellipse.move(50,60) + ellipse.dy(120) + expect(ellipse.node.getAttribute('cy')).toBe('225') + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + ellipse.move(50,60) + ellipse.dmove(80, 25) + expect(ellipse.node.getAttribute('cx')).toBe('250') + expect(ellipse.node.getAttribute('cy')).toBe('130') + }) + }) describe('center()', function() { it('sets the cx and cy position', function() { diff --git a/spec/spec/gradient.js b/spec/spec/gradient.js index a0e4d98..a0e4d98 100644..100755 --- a/spec/spec/gradient.js +++ b/spec/spec/gradient.js diff --git a/spec/spec/group.js b/spec/spec/group.js index 64d0463..dd56ed5 100644..100755 --- a/spec/spec/group.js +++ b/spec/spec/group.js @@ -69,6 +69,30 @@ describe('Group', function() { expect(box.cy).toBe(567) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + group.move(50,60) + group.dx(100) + expect(group.node.getAttribute('transform')).toBe('translate(150 60)') + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + group.move(50,60) + group.dy(120) + expect(group.node.getAttribute('transform')).toBe('translate(50 180)') + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + group.move(50, 60) + group.dmove(80, 25) + expect(group.node.getAttribute('transform')).toBe('translate(130 85)') + }) + }) })
\ No newline at end of file diff --git a/spec/spec/helper.js b/spec/spec/helper.js index 552ca6c..552ca6c 100644..100755 --- a/spec/spec/helper.js +++ b/spec/spec/helper.js diff --git a/spec/spec/hyperlink.js b/spec/spec/hyperlink.js index 3fe78f8..3fe78f8 100644..100755 --- a/spec/spec/hyperlink.js +++ b/spec/spec/hyperlink.js diff --git a/spec/spec/image.js b/spec/spec/image.js index b24835b..91cfff6 100644..100755 --- a/spec/spec/image.js +++ b/spec/spec/image.js @@ -60,6 +60,31 @@ describe('Image', function() { expect(image.node.getAttribute('y')).toBe('456') }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + image.move(50,60) + image.dx(100) + expect(image.node.getAttribute('x')).toBe('150') + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + image.move(50,60) + image.dy(120) + expect(image.node.getAttribute('y')).toBe('180') + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + image.move(50,60) + image.dmove(80, 25) + expect(image.node.getAttribute('x')).toBe('130') + expect(image.node.getAttribute('y')).toBe('85') + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { diff --git a/spec/spec/line.js b/spec/spec/line.js index cb9d6f6..97490ad 100644..100755 --- a/spec/spec/line.js +++ b/spec/spec/line.js @@ -63,6 +63,42 @@ describe('Line', function() { expect(box.y).toBe(456) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + line.move(50,60) + line.dx(100) + var box = line.bbox() + expect(box.x).toBe(150) + expect(box.y + box.height).toBe(160) + expect(box.x + box.width).toBe(250) + expect(box.y).toBe(60) + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + line.move(50, 60) + line.dy(120) + var box = line.bbox() + expect(box.x).toBe(50) + expect(box.y + box.height).toBe(280) + expect(box.x + box.width).toBe(150) + expect(box.y).toBe(180) + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + line.move(50,60) + line.dmove(80, 25) + var box = line.bbox() + expect(box.x).toBe(130) + expect(box.y + box.height).toBe(185) + expect(box.x + box.width).toBe(230) + expect(box.y).toBe(85) + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { diff --git a/spec/spec/mask.js b/spec/spec/mask.js index a13d842..a13d842 100644..100755 --- a/spec/spec/mask.js +++ b/spec/spec/mask.js diff --git a/spec/spec/memory.js b/spec/spec/memory.js index c7bb942..c7bb942 100644..100755 --- a/spec/spec/memory.js +++ b/spec/spec/memory.js diff --git a/spec/spec/number.js b/spec/spec/number.js index f35be5f..f35be5f 100644..100755 --- a/spec/spec/number.js +++ b/spec/spec/number.js diff --git a/spec/spec/path.js b/spec/spec/path.js index 2862a92..6ca9cfe 100644..100755 --- a/spec/spec/path.js +++ b/spec/spec/path.js @@ -67,6 +67,34 @@ describe('Path', function() { expect(box.y).toBe(456) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + path.move(50,60) + path.dx(100) + var box = path.bbox() + expect(box.x).toBe(150) + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + path.move(50, 60) + path.dy(120) + var box = path.bbox() + expect(box.y).toBe(180) + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + path.move(50,60) + path.dmove(80, 25) + var box = path.bbox() + expect(box.x).toBe(130) + expect(box.y).toBe(85) + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { @@ -149,18 +177,18 @@ describe('Path', function() { describe('plot()', function() { it('falls back to a single point without an argument', function() { path = draw.path() - expect(path.node.getAttribute('d')).toBe('M 0 0') + expect(path.node.getAttribute('d')).toBe('M0 0 ') }) }) describe('toString()', function() { it('renders path array correctly to string', function() { - path = path.plot('M 50 60 A 60 60 0 0 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60') - expect(path.node.getAttribute('d')).toBe('M 50 60 A 60 60 0 0 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60') + path = path.plot('M 50 60 A 60 60 0 0 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60 ') + expect(path.node.getAttribute('d')).toBe('M50 60A60 60 0 0 0 50 -60H100V100L20 30C10 20 30 40 50 60 ') }) it('renders path array correctly to string', function() { - path = path.plot('M 50 60 A 60 60 1 1 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60') - expect(path.node.getAttribute('d')).toBe('M 50 60 A 60 60 1 1 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60') + path = path.plot('M 50 60 A 60 60 1 1 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60 ') + expect(path.node.getAttribute('d')).toBe('M50 60A60 60 1 1 0 50 -60H100V100L20 30C10 20 30 40 50 60 ') }) }) diff --git a/spec/spec/pattern.js b/spec/spec/pattern.js index b251801..b251801 100644..100755 --- a/spec/spec/pattern.js +++ b/spec/spec/pattern.js diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js index e94facd..88899de 100644..100755 --- a/spec/spec/polygon.js +++ b/spec/spec/polygon.js @@ -61,6 +61,34 @@ describe('Polygon', function() { expect(box.y).toBe(456) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + polygon.move(50,60) + polygon.dx(100) + var box = polygon.bbox() + expect(box.x).toBe(150) + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + polygon.move(50, 60) + polygon.dy(120) + var box = polygon.bbox() + expect(box.y).toBe(180) + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + polygon.move(50,60) + polygon.dmove(80, 25) + var box = polygon.bbox() + expect(box.x).toBe(130) + expect(box.y).toBe(85) + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js index 204cfa7..99dce1a 100644..100755 --- a/spec/spec/polyline.js +++ b/spec/spec/polyline.js @@ -61,6 +61,34 @@ describe('Polyline', function() { expect(box.y).toBe(456) }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + polyline.move(50,60) + polyline.dx(100) + var box = polyline.bbox() + expect(box.x).toBe(150) + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + polyline.move(50, 60) + polyline.dy(120) + var box = polyline.bbox() + expect(box.y).toBe(180) + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + polyline.move(50,60) + polyline.dmove(80, 25) + var box = polyline.bbox() + expect(box.x).toBe(130) + expect(box.y).toBe(85) + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { diff --git a/spec/spec/rect.js b/spec/spec/rect.js index 36d4925..938bc46 100644..100755 --- a/spec/spec/rect.js +++ b/spec/spec/rect.js @@ -73,6 +73,31 @@ describe('Rect', function() { expect(rect.node.getAttribute('y')).toBe('456') }) }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + rect.move(50,60) + rect.dx(100) + expect(rect.node.getAttribute('x')).toBe('150') + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + rect.move(50,60) + rect.dy(120) + expect(rect.node.getAttribute('y')).toBe('180') + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + rect.move(50,60) + rect.dmove(80, 25) + expect(rect.node.getAttribute('x')).toBe('130') + expect(rect.node.getAttribute('y')).toBe('85') + }) + }) describe('center()', function() { it('should set the cx and cy position', function() { diff --git a/spec/spec/set.js b/spec/spec/set.js index 0eb822d..0eb822d 100644..100755 --- a/spec/spec/set.js +++ b/spec/spec/set.js diff --git a/spec/spec/svg.js b/spec/spec/svg.js index 75f8a6d..75f8a6d 100644..100755 --- a/spec/spec/svg.js +++ b/spec/spec/svg.js diff --git a/spec/spec/text.js b/spec/spec/text.js index f23f4f5..f9019a2 100644..100755 --- a/spec/spec/text.js +++ b/spec/spec/text.js @@ -14,15 +14,15 @@ describe('Text', function() { }) describe('x()', function() { - it('should return the value of x without an argument', function() { + it('returns the value of x without an argument', function() { expect(approximately(text.x())).toBe(approximately(0)) }) - it('should set the value of x with the first argument', function() { + it('sets the value of x with the first argument', function() { text.x(123) var box = text.bbox() expect(approximately(box.x, 5)).toBe(approximately(123, 5)) }) - it('should set the value of x based on the anchor with the first argument', function() { + it('sets the value of x based on the anchor with the first argument', function() { text.x(123, true) var box = text.bbox() expect(approximately(box.x, 5)).toBe(approximately(123, 5)) @@ -30,15 +30,15 @@ describe('Text', function() { }) describe('y()', function() { - it('should return the value of y without an argument', function() { + it('returns the value of y without an argument', function() { expect(text.y()).toBe(0) }) - it('should set the value of y with the first argument', function() { + it('sets the value of y with the first argument', function() { text.y(345) var box = text.bbox() expect(approximately(box.y, 5)).toBe(approximately(345, 5)) }) - it('should set the value of y based on the anchor with the first argument', function() { + it('sets the value of y based on the anchor with the first argument', function() { text.y(345, true) var box = text.bbox() expect(approximately(box.y, 5)).toBe(approximately(345, 5)) @@ -46,16 +46,16 @@ describe('Text', function() { }) describe('cx()', function() { - it('should return the value of cx without an argument', function() { + it('returns the value of cx without an argument', function() { var box = text.bbox() expect(approximately(text.cx())).toBe(approximately(box.width / 2)) }) - it('should set the value of cx with the first argument', function() { + it('sets the value of cx with the first argument', function() { text.cx(123) var box = text.bbox() expect(approximately(box.cx, 5)).toBe(approximately(123, 5)) }) - it('should set the value of cx based on the anchor with the first argument', function() { + it('sets the value of cx based on the anchor with the first argument', function() { text.cx(123, true) var box = text.bbox() expect(approximately(box.cx, 5)).toBe(approximately(123, 5)) @@ -63,32 +63,28 @@ describe('Text', function() { }) describe('cy()', function() { - it('should return the value of cy without an argument', function() { + it('returns the value of cy without an argument', function() { var box = text.bbox() expect(text.cy()).toBe(box.cy) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { text.cy(345) var box = text.bbox() expect(approximately(box.cy, 5)).toBe(approximately(345, 5)) }) - it('should set the value of cy based on the anchor with the first argument', function() { - text.cy(345, true) - var box = text.bbox() - expect(approximately(box.cy, 5)).toBe(approximately(345 + box.height / 2, 5)) - }) }) describe('move()', function() { - it('should set the x and y position', function() { + it('sets the x and y position', function() { text.move(123,456) - expect(text.node.getAttribute('x')).toBe('123') - expect(text.node.getAttribute('y')).toBe('456') + var box = text.bbox() + expect(box.x).toBe(123) + expect(box.y).toBe(456) }) }) describe('center()', function() { - it('should set the cx and cy position', function() { + it('sets the cx and cy position', function() { text.center(321,567) var box = text.bbox() expect(approximately(box.cx, 5)).toBe(approximately(321, 5)) @@ -99,16 +95,138 @@ describe('Text', function() { describe('size()', function() { it('should define the width and height of the element', function() { text.size(50) - expect(text.style('font-size').valueOf()).toBe(50) + expect(text.attr('font-size').valueOf()).toBe(50) }) }) describe('translate()', function() { - it('should set the translation of an element', function() { + it('sets the translation of an element', function() { text.transform({ x: 12, y: 12 }) expect(text.node.getAttribute('transform')).toBe('translate(12 12)') }) }) + + describe('text()', function() { + it('adds content in a nested tspan', function() { + text.text('It is a bear!') + expect(text.node.childNodes[0].nodeType).toBe(1) + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('It is a bear!') + }) + it('creates multiple lines with a newline separated string', function() { + text.text('It is\nJUST\na bear!') + expect(text.node.childNodes.length).toBe(3) + }) + it('stores a reference to the tspan nodes in a set', function() { + text.text('It is\nJUST\na bear!') + expect(text.lines instanceof SVG.Set).toBe(true) + expect(text.lines.members.length).toBe(3) + }) + it('stores the text value in the content reference', function() { + text.text('It is\nJUST\na bear!') + expect(text.content).toBe('It is\nJUST\na bear!') + }) + it('gets the given content of a text element without an argument', function() { + text.text('It is another bear!') + expect(text.node.childNodes[0].nodeType).toBe(1) + expect(text.text()).toMatch('It is another bear!') + }) + it('accepts a block as first arguments', function() { + text.text(function(add) { + add.tspan('mastaba') + add.plain('hut') + }) + expect(text.node.childNodes[0].nodeType).toBe(1) + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('mastaba') + expect(text.node.childNodes[1].nodeType).toBe(3) + expect(text.node.childNodes[1].nodeValue).toBe('hut') + }) + }) + + describe('plain()', function() { + it('adds content without a tspan', function() { + text.plain('It is a bear!') + expect(text.node.childNodes[0].nodeType).toBe(3) + expect(text.node.childNodes[0].nodeValue).toBe('It is a bear!') + }) + it('clears content before adding new content', function() { + text.plain('It is not a bear!') + expect(text.node.childNodes.length).toBe(1) + expect(text.node.childNodes[0].nodeValue).toBe('It is not a bear!') + }) + it('stores the text value in the content reference', function() { + text.plain('Just plain text!') + expect(text.content).toBe('Just plain text!') + }) + }) + + describe('tspan()', function() { + it('adds content in a tspan', function() { + text.tspan('It is a bear!') + expect(text.node.childNodes[0].nodeType).toBe(1) + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('It is a bear!') + }) + it('clears content before adding new content', function() { + text.tspan('It is not a bear!') + expect(text.node.childNodes.length).toBe(1) + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('It is not a bear!') + }) + }) + + describe('clear()', function() { + it('removes all content', function() { + text.text(function(add) { + add.tspan('The first.') + add.tspan('The second.') + add.tspan('The third.') + }) + expect(text.node.childNodes.length).toBe(3) + text.clear() + expect(text.node.childNodes.length).toBe(0) + }) + it('initializes a new set for the lines reference', function() { + var lines = text.lines + text.clear() + expect(text.lines instanceof SVG.Set).toBe(true) + expect(text.lines).not.toBe(lines) + }) + it('clears the stored content value', function() { + text.text('Stored locally.') + expect(text.content).toBe('Stored locally.') + text.clear() + expect(text.content).toBe('') + }) + }) + + describe('build()', function() { + it('enables adding multiple plain text nodes when given true', function() { + text.clear().build(true) + text.plain('A great piece!') + text.plain('Another great piece!') + expect(text.node.childNodes[0].nodeValue).toBe('A great piece!') + expect(text.node.childNodes[1].nodeValue).toBe('Another great piece!') + }) + it('enables adding multiple tspan nodes when given true', function() { + text.clear().build(true) + text.tspan('A great piece!') + text.tspan('Another great piece!') + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('A great piece!') + expect(text.node.childNodes[1].childNodes[0].nodeValue).toBe('Another great piece!') + }) + it('disables adding multiple plain text nodes when given false', function() { + text.clear().build(true) + text.plain('A great piece!') + text.build(false).plain('Another great piece!') + expect(text.node.childNodes[0].nodeValue).toBe('Another great piece!') + expect(text.node.childNodes[1]).toBe(undefined) + }) + it('disables adding multiple tspan nodes when given false', function() { + text.clear().build(true) + text.tspan('A great piece!') + text.build(false).tspan('Another great piece!') + expect(text.node.childNodes[0].childNodes[0].nodeValue).toBe('Another great piece!') + expect(text.node.childNodes[1]).toBe(undefined) + }) + }) }) diff --git a/spec/spec/textpath.js b/spec/spec/textpath.js index 286b07e..286b07e 100644..100755 --- a/spec/spec/textpath.js +++ b/spec/spec/textpath.js diff --git a/spec/spec/use.js b/spec/spec/use.js index ed0d567..ed0d567 100644..100755 --- a/spec/spec/use.js +++ b/spec/spec/use.js |