diff options
author | wout <wout@impinc.co.uk> | 2014-06-25 15:05:03 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-06-25 15:05:03 +0200 |
commit | e567c774c17e6649041d4972defd1232ab602012 (patch) | |
tree | 05140fe4715a652c99f15672e1d56c0fc8426824 /spec | |
parent | ec21f496bddc588e2113fd5418d713ce8ae78f39 (diff) | |
download | svg.js-e567c774c17e6649041d4972defd1232ab602012.tar.gz svg.js-e567c774c17e6649041d4972defd1232ab602012.zip |
Added SVG.Circle, removed structural internal references
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/index.html | 9 | ||||
-rw-r--r-- | spec/spec/adopter.js | 49 | ||||
-rw-r--r-- | spec/spec/circle.js | 185 | ||||
-rwxr-xr-x | spec/spec/container.js | 8 | ||||
-rwxr-xr-x | spec/spec/ellipse.js | 37 | ||||
-rwxr-xr-x | spec/spec/path.js | 33 | ||||
-rwxr-xr-x | spec/spec/polygon.js | 31 | ||||
-rwxr-xr-x | spec/spec/polyline.js | 31 |
8 files changed, 318 insertions, 65 deletions
diff --git a/spec/index.html b/spec/index.html index 7932214..060e076 100755 --- a/spec/index.html +++ b/spec/index.html @@ -19,21 +19,23 @@ </head> <body> - <svg height="0" width="0"> + <svg height="0" width="0" id="inlineSVG"> <path id="lineAB" d="M 100 350 l 150 -300" stroke="red" stroke-width="3" fill="none" /> <path id="lineBC" d="M 250 50 l 150 300" stroke="red" stroke-width="3" fill="none" /> <path d="M 175 200 l 150 0" stroke="green" stroke-width="3" fill="none" /> <path d="M 100 350 q 150 -300 300 0" stroke="blue" stroke-width="5" fill="none" /> - <g stroke="black" stroke-width="3" fill="black"> + <g stroke="black" stroke-width="3" fill="black" id="pointGroup"> <circle id="pointA" cx="100" cy="350" r="3" /> <circle id="pointB" cx="250" cy="50" r="3" /> <circle id="pointC" cx="400" cy="350" r="3" /> </g> - <g font-size="30" font="sans-serif" fill="black" stroke="none" text-anchor="middle"> + <g font-size="30" font="sans-serif" fill="black" stroke="none" text-anchor="middle" id="labelGroup"> <text x="100" y="350" dx="-30">A</text> <text x="250" y="50" dy="-10">B</text> <text x="400" y="350" dx="30">C</text> </g> + <polygon points="200,10 250,190 160,210" /> + <polyline points="20,20 40,25 60,40 80,120 120,140 200,180" /> </svg> </body> @@ -54,6 +56,7 @@ <script type="text/javascript" src="spec/arrange.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/circle.js"></script> <script type="text/javascript" src="spec/ellipse.js"></script> <script type="text/javascript" src="spec/line.js"></script> <script type="text/javascript" src="spec/polyline.js"></script> diff --git a/spec/spec/adopter.js b/spec/spec/adopter.js index efdb806..522802f 100644 --- a/spec/spec/adopter.js +++ b/spec/spec/adopter.js @@ -2,20 +2,53 @@ describe('Adopter', function() { var path beforeEach(function() { - path = SVG.get('lineAB') + path = SVG.get('lineAB') + polyline = SVG.get('inlineSVG').select('polyline').first() + polygon = SVG.get('inlineSVG').select('polygon').first() }) - it('adopts an exiting path element', function() { - expect(path instanceof SVG.Path).toBe(true) + describe('with SVG.Doc instance', function() { + it('adopts the main svg document when parent() method is called on first level children', function() { + expect(path.parent() instanceof SVG.Doc).toBeTruthy() + }) + it('defines a xmlns attribute', function() { + expect(path.parent().node.getAttribute('xmlns')).toBe(SVG.ns) + }) + it('defines a version attribute', function() { + expect(path.parent().node.getAttribute('version')).toBe('1.1') + }) + it('defines a xmlns:xlink attribute', function() { + expect(path.parent().node.getAttribute('xmlns:xlink')).toBe(SVG.xlink) + }) + it('initializes a defs node', function() { + expect(path.parent()._defs).toBe(path.parent().defs()) + }) }) - it('modifies an adopted element', function() { - path.fill('#f06') - expect(path.node.getAttribute('fill')).toBe('#ff0066') + describe('with SVG.Path instance', function() { + it('adopts an exiting path element', function() { + expect(path instanceof SVG.Path).toBeTruthy() + }) + it('modifies an adopted element', function() { + path.fill('#f06') + expect(path.node.getAttribute('fill')).toBe('#ff0066') + }) + it('parses d attribute to SVG.PathArray', function() { + expect(path.array() instanceof SVG.PathArray).toBeTruthy() + }) }) - it('adopts a parent when parent() method is called', function() { - expect(path.parent() instanceof SVG.Doc).toBe(true) + describe('with SVG.Polyline instance', function() { + it('parses points attribute to SVG.PointArray', function() { + expect(polyline.array() instanceof SVG.PointArray).toBeTruthy() + }) }) + describe('with SVG.Polygon instance', function() { + it('parses points attribute to SVG.PointArray', function() { + expect(polygon.array() instanceof SVG.PointArray).toBeTruthy() + }) + }) + + })
\ No newline at end of file diff --git a/spec/spec/circle.js b/spec/spec/circle.js new file mode 100644 index 0000000..8501a26 --- /dev/null +++ b/spec/spec/circle.js @@ -0,0 +1,185 @@ +describe('Circle', function() { + var circle + + beforeEach(function() { + circle = draw.circle(240) + }) + + afterEach(function() { + draw.clear() + }) + + describe('x()', function() { + it('returns the value of x without an argument', function() { + expect(circle.x()).toBe(0) + }) + it('sets the value of x with the first argument', function() { + circle.x(123) + var box = circle.bbox() + expect(box.x).toBe(123) + }) + }) + + describe('y()', function() { + it('returns the value of y without an argument', function() { + expect(circle.y()).toBe(0) + }) + it('sets the value of cy with the first argument', function() { + circle.y(345) + var box = circle.bbox() + expect(box.y).toBe(345) + }) + }) + + describe('cx()', function() { + it('returns the value of cx without an argument', function() { + expect(circle.cx()).toBe(120) + }) + it('sets the value of cx with the first argument', function() { + circle.cx(123) + var box = circle.bbox() + expect(box.cx).toBe(123) + }) + }) + + describe('cy()', function() { + it('returns the value of cy without an argument', function() { + expect(circle.cy()).toBe(120) + }) + it('sets the value of cy with the first argument', function() { + circle.cy(345) + var box = circle.bbox() + expect(box.cy).toBe(345) + }) + }) + + describe('radius()', function() { + it('sets the r attribute with the first argument', function() { + circle.radius(10) + expect(circle.node.getAttribute('r')).toBe('10') + }) + }) + + describe('rx()', function() { + it('sets the r attribute with the first argument', function() { + circle.rx(11) + expect(circle.node.getAttribute('r')).toBe('11') + }) + it('gets the r attribute without and argument', function() { + circle.rx() + expect(circle.node.getAttribute('r')).toBe('120') + }) + }) + + describe('ry()', function() { + it('sets the r attribute with the first argument', function() { + circle.ry(12) + expect(circle.node.getAttribute('r')).toBe('12') + }) + it('gets the r attribute without and argument', function() { + circle.ry() + expect(circle.node.getAttribute('r')).toBe('120') + }) + }) + + describe('move()', function() { + it('sets the x and y position', function() { + circle.move(123, 456) + var box = circle.bbox() + expect(box.x).toBe(123) + expect(box.y).toBe(456) + }) + }) + + describe('dx()', function() { + it('moves the x positon of the element relative to the current position', function() { + circle.move(50, 60) + circle.dx(100) + expect(circle.node.getAttribute('cx')).toBe('270') + }) + }) + + describe('dy()', function() { + it('moves the y positon of the element relative to the current position', function() { + circle.move(50, 60) + circle.dy(120) + expect(circle.node.getAttribute('cy')).toBe('300') + }) + }) + + describe('dmove()', function() { + it('moves the x and y positon of the element relative to the current position', function() { + circle.move(50,60) + circle.dmove(80, 25) + expect(circle.node.getAttribute('cx')).toBe('250') + expect(circle.node.getAttribute('cy')).toBe('205') + }) + }) + + describe('center()', function() { + it('sets the cx and cy position', function() { + circle.center(321,567) + var box = circle.bbox() + expect(box.cx).toBe(321) + expect(box.cy).toBe(567) + }) + }) + + describe('width()', function() { + it('sets the width and height of the element', function() { + circle.width(82) + expect(circle.node.getAttribute('r')).toBe('41') + }) + it('gets the width and height of the element if the argument is null', function() { + expect((circle.width() / 2).toString()).toBe(circle.node.getAttribute('r')) + }) + }) + + describe('height()', function() { + it('sets the height and width of the element', function() { + circle.height(1236) + expect(circle.node.getAttribute('r')).toBe('618') + }) + it('gets the height and width of the element if the argument is null', function() { + expect((circle.height() / 2).toString()).toBe(circle.node.getAttribute('r')) + }) + }) + + describe('size()', function() { + it('defines the r of the element', function() { + circle.size(987) + expect(circle.node.getAttribute('r')).toBe((987 / 2).toString()) + }) + }) + + describe('scale()', function() { + it('should scale the element universally with one argument', function() { + var box = circle.scale(2).bbox() + + expect(box.width).toBe(circle.attr('r') * 2 * 2) + expect(box.height).toBe(circle.attr('r') * 2 * 2) + }) + it('should scale the element over individual x and y axes with two arguments', function() { + var box = circle.scale(2, 3.5).bbox() + + expect(box.width).toBe(circle.attr('r') * 2 * 2) + expect(box.height).toBe(circle.attr('r') * 2 * 3.5) + }) + }) + + describe('translate()', function() { + it('sets the translation of an element', function() { + circle.transform({ x: 12, y: 12 }) + expect(circle.node.getAttribute('transform')).toBe('translate(12 12)') + }) + }) + +}) + + + + + + + + diff --git a/spec/spec/container.js b/spec/spec/container.js index 3fa0867..63b1a01 100755 --- a/spec/spec/container.js +++ b/spec/spec/container.js @@ -50,11 +50,11 @@ describe('Container', function() { draw.circle(100) expect(draw.children().length).toBe(initial + 1) }) - it('should create an ellipse', function() { - expect(draw.circle(100).type).toBe('ellipse') + it('should create an circle', function() { + expect(draw.circle(100).type).toBe('circle') }) - it('should create an instance of SVG.Ellipse', function() { - expect(draw.circle(100) instanceof SVG.Ellipse).toBe(true) + it('should create an instance of SVG.Circle', function() { + expect(draw.circle(100) instanceof SVG.Circle).toBe(true) }) it('should be an instance of SVG.Shape', function() { expect(draw.circle(100) instanceof SVG.Shape).toBe(true) diff --git a/spec/spec/ellipse.js b/spec/spec/ellipse.js index f9e6387..a9eb03b 100755 --- a/spec/spec/ellipse.js +++ b/spec/spec/ellipse.js @@ -10,10 +10,10 @@ describe('Ellipse', 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(ellipse.x()).toBe(0) }) - it('should set the value of x with the first argument', function() { + it('sets the value of x with the first argument', function() { ellipse.x(123) var box = ellipse.bbox() expect(box.x).toBe(123) @@ -21,10 +21,10 @@ describe('Ellipse', 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(ellipse.y()).toBe(0) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { ellipse.y(345) var box = ellipse.bbox() expect(box.y).toBe(345) @@ -32,10 +32,10 @@ describe('Ellipse', 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() { expect(ellipse.cx()).toBe(120) }) - it('should set the value of cx with the first argument', function() { + it('sets the value of cx with the first argument', function() { ellipse.cx(123) var box = ellipse.bbox() expect(box.cx).toBe(123) @@ -43,10 +43,10 @@ describe('Ellipse', 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() { expect(ellipse.cy()).toBe(45) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { ellipse.cy(345) var box = ellipse.bbox() expect(box.cy).toBe(345) @@ -54,21 +54,26 @@ describe('Ellipse', function() { }) describe('radius()', function() { - it('should set the rx and ry', function() { - ellipse.radius(10,20) + it('sets 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() { + it('sets 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') }) + it('sets the and ry value correctly when given 0', function() { + ellipse.radius(11, 0) + expect(ellipse.node.getAttribute('rx')).toBe('11') + expect(ellipse.node.getAttribute('ry')).toBe('0') + }) }) describe('move()', function() { - it('should set the x and y position', function() { - ellipse.move(123,456) + it('sets the x and y position', function() { + ellipse.move(123, 456) var box = ellipse.bbox() expect(box.x).toBe(123) expect(box.y).toBe(456) @@ -77,7 +82,7 @@ describe('Ellipse', function() { describe('dx()', function() { it('moves the x positon of the element relative to the current position', function() { - ellipse.move(50,60) + ellipse.move(50, 60) ellipse.dx(100) expect(ellipse.node.getAttribute('cx')).toBe('270') }) @@ -85,7 +90,7 @@ describe('Ellipse', function() { describe('dy()', function() { it('moves the y positon of the element relative to the current position', function() { - ellipse.move(50,60) + ellipse.move(50, 60) ellipse.dy(120) expect(ellipse.node.getAttribute('cy')).toBe('225') }) @@ -165,7 +170,7 @@ describe('Ellipse', function() { }) describe('translate()', function() { - it('should set the translation of an element', function() { + it('sets the translation of an element', function() { ellipse.transform({ x: 12, y: 12 }) expect(ellipse.node.getAttribute('transform')).toBe('translate(12 12)') }) diff --git a/spec/spec/path.js b/spec/spec/path.js index 6ca9cfe..ae0e25e 100755 --- a/spec/spec/path.js +++ b/spec/spec/path.js @@ -8,12 +8,21 @@ describe('Path', function() { afterEach(function() { draw.clear() }) + + describe('array()', function() { + it('returns an instance of SVG.PathArray', function() { + expect(path.array() instanceof SVG.PathArray).toBeTruthy() + }) + it('returns the value stored in the private variable _array', function() { + expect(path.array()).toBe(path._array) + }) + }) 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(path.x()).toBe(0) }) - it('should set the value of x with the first argument', function() { + it('sets the value of x with the first argument', function() { path.x(123) var box = path.bbox() expect(box.x).toBe(123) @@ -21,10 +30,10 @@ describe('Path', 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(path.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() { path.y(345) var box = path.bbox() expect(box.y).toBe(345) @@ -32,10 +41,10 @@ describe('Path', 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() { expect(path.cx()).toBe(50) }) - it('should set the value of cx with the first argument', function() { + it('sets the value of cx with the first argument', function() { path.cx(123) var box = path.bbox() expect(box.cx).toBe(123) @@ -43,10 +52,10 @@ describe('Path', 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() { expect(path.cy()).toBe(50) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { path.cy(345) var box = path.bbox() expect(box.cy).toBe(345) @@ -54,13 +63,13 @@ describe('Path', function() { }) describe('move()', function() { - it('should set the x and y position', function() { + it('sets the x and y position', function() { path.move(123,456) var box = path.bbox() expect(box.x).toBe(123) expect(box.y).toBe(456) }) - it('should set the x and y position when scaled to half its size', function() { + it('sets the x and y position when scaled to half its size', function() { path.scale(0.5).move(123,456) var box = path.bbox() expect(box.x).toBe(123) @@ -97,7 +106,7 @@ describe('Path', function() { }) describe('center()', function() { - it('should set the cx and cy position', function() { + it('sets the cx and cy position', function() { path.center(321,567) var box = path.bbox() expect(box.x).toBe(271) @@ -168,7 +177,7 @@ describe('Path', function() { }) describe('translate()', function() { - it('should set the translation of an element', function() { + it('sets the translation of an element', function() { path.transform({ x: 12, y: 12 }) expect(path.node.getAttribute('transform')).toBe('translate(12 12)') }) diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js index 88899de..35c8836 100755 --- a/spec/spec/polygon.js +++ b/spec/spec/polygon.js @@ -8,12 +8,21 @@ describe('Polygon', function() { afterEach(function() { draw.clear() }) + + describe('array()', function() { + it('returns an instance of SVG.PointArray', function() { + expect(polygon.array() instanceof SVG.PointArray).toBeTruthy() + }) + it('returns the value stored in the private variable _array', function() { + expect(polygon.array()).toBe(polygon._array) + }) + }) 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(polygon.x()).toBe(0) }) - it('should set the value of x with the first argument', function() { + it('sets the value of x with the first argument', function() { polygon.x(123) var box = polygon.bbox() expect(box.x).toBe(123) @@ -21,10 +30,10 @@ describe('Polygon', 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(polygon.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() { polygon.y(345) var box = polygon.bbox() expect(box.y).toBe(345) @@ -32,10 +41,10 @@ describe('Polygon', 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() { expect(polygon.cx()).toBe(50) }) - it('should set the value of cx with the first argument', function() { + it('sets the value of cx with the first argument', function() { polygon.cx(123) var box = polygon.bbox() expect(box.cx).toBe(123) @@ -43,10 +52,10 @@ describe('Polygon', 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() { expect(polygon.cy()).toBe(50) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { polygon.cy(345) var box = polygon.bbox() expect(box.cy).toBe(345) @@ -54,7 +63,7 @@ describe('Polygon', function() { }) describe('move()', function() { - it('should set the x and y position', function() { + it('sets the x and y position', function() { polygon.move(123,456) var box = polygon.bbox() expect(box.x).toBe(123) @@ -91,7 +100,7 @@ describe('Polygon', function() { }) describe('center()', function() { - it('should set the cx and cy position', function() { + it('sets the cx and cy position', function() { polygon.center(321,567) var box = polygon.bbox() expect(box.x).toBe(271) @@ -162,7 +171,7 @@ describe('Polygon', function() { }) describe('translate()', function() { - it('should set the translation of an element', function() { + it('sets the translation of an element', function() { polygon.transform({ x: 12, y: 12 }) expect(polygon.node.getAttribute('transform')).toBe('translate(12 12)') }) diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js index 99dce1a..5b79934 100755 --- a/spec/spec/polyline.js +++ b/spec/spec/polyline.js @@ -8,12 +8,21 @@ describe('Polyline', function() { afterEach(function() { draw.clear() }) + + describe('array()', function() { + it('returns an instance of SVG.PointArray', function() { + expect(polyline.array() instanceof SVG.PointArray).toBeTruthy() + }) + it('returns the value stored in the private variable _array', function() { + expect(polyline.array()).toBe(polyline._array) + }) + }) 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(polyline.x()).toBe(0) }) - it('should set the value of x with the first argument', function() { + it('sets the value of x with the first argument', function() { polyline.x(123) var box = polyline.bbox() expect(box.x).toBe(123) @@ -21,10 +30,10 @@ describe('Polyline', 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(polyline.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() { polyline.y(345) var box = polyline.bbox() expect(box.y).toBe(345) @@ -32,10 +41,10 @@ describe('Polyline', 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() { expect(polyline.cx()).toBe(50) }) - it('should set the value of cx with the first argument', function() { + it('sets the value of cx with the first argument', function() { polyline.cx(123) var box = polyline.bbox() expect(box.cx).toBe(123) @@ -43,10 +52,10 @@ describe('Polyline', 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() { expect(polyline.cy()).toBe(50) }) - it('should set the value of cy with the first argument', function() { + it('sets the value of cy with the first argument', function() { polyline.cy(345) var box = polyline.bbox() expect(box.cy).toBe(345) @@ -54,7 +63,7 @@ describe('Polyline', function() { }) describe('move()', function() { - it('should set the x and y position', function() { + it('sets the x and y position', function() { polyline.move(123,456) var box = polyline.bbox() expect(box.x).toBe(123) @@ -91,7 +100,7 @@ describe('Polyline', function() { }) describe('center()', function() { - it('should set the cx and cy position', function() { + it('sets the cx and cy position', function() { polyline.center(321,567) var box = polyline.bbox() expect(box.x).toBe(271) @@ -162,7 +171,7 @@ describe('Polyline', function() { }) describe('translate()', function() { - it('should set the translation of an element', function() { + it('sets the translation of an element', function() { polyline.transform({ x: 12, y: 12 }) expect(polyline.node.getAttribute('transform')).toBe('translate(12 12)') }) |