summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-01-29 21:20:58 +0100
committerwout <wout@impinc.co.uk>2014-01-29 21:20:58 +0100
commit5b6736666dd85f8a063b87e6c6483ea47be4391c (patch)
tree139b35c98807ac36cad095af13ef45495958b78f /spec
parent9688054367938f1e9240c2d8572e94bb0149bc77 (diff)
downloadsvg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.tar.gz
svg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.zip
Added SVG.PathArray, updated data() and bumped to v1.0rc1
Diffstat (limited to 'spec')
-rw-r--r--spec/index.html12
-rw-r--r--spec/spec/element.js21
-rw-r--r--spec/spec/ellipse.js12
-rw-r--r--spec/spec/gradient.js13
-rw-r--r--spec/spec/helper.js8
-rw-r--r--spec/spec/image.js12
-rw-r--r--spec/spec/line.js12
-rw-r--r--spec/spec/path.js16
-rw-r--r--spec/spec/polygon.js12
-rw-r--r--spec/spec/polyline.js12
-rw-r--r--spec/spec/rect.js12
11 files changed, 124 insertions, 18 deletions
diff --git a/spec/index.html b/spec/index.html
index b5e4d99..f7e01ec 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -8,10 +8,11 @@
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<style type="text/css" media="screen">
- #canvas {
- width: 1px;
- height: 1px;
- overflow: hidden;
+ #drawing {
+ width: 500px;
+ height: 500px;
+ position: absolute;
+ z-index: -10;
}
</style>
@@ -27,7 +28,6 @@
<script src="../dist/svg.js" type="text/javascript" charset="utf-8"></script>
<!-- include spec files here... -->
-<script type="text/javascript" src="spec/helper.js"></script>
<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>
@@ -84,4 +84,6 @@
})();
</script>
+<script type="text/javascript" src="spec/helper.js"></script>
+
</html>
diff --git a/spec/spec/element.js b/spec/spec/element.js
index f1edb01..22b09bf 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -158,23 +158,34 @@ describe('Element', function() {
})
describe('data()', function() {
- it('should set a data attribute and convert value to json', function() {
+ it('sets a data attribute and convert value to json', function() {
var rect = draw.rect(100,100).data('test', 'value')
expect(rect.node.getAttribute('data-test')).toBe('value')
})
- it('should set a data attribute and not convert value to json if flagged raw', function() {
+ it('sets a data attribute and not convert value to json if flagged raw', function() {
var rect = draw.rect(100,100).data('test', 'value', true)
expect(rect.node.getAttribute('data-test')).toBe('value')
})
- it('should get data value in ony one argument is passed', function() {
+ it('sets multiple data attributes and convert values to json when an object is passed', function() {
+ var rect = draw.rect(100,100).data({
+ forbidden: 'fruit'
+ , multiple: {
+ values: 'in'
+ , an: 'object'
+ }
+ })
+ expect(rect.node.getAttribute('data-forbidden')).toBe('fruit')
+ expect(rect.node.getAttribute('data-multiple')).toEqual('{"values":"in","an":"object"}')
+ })
+ it('gets data value if only one argument is passed', function() {
var rect = draw.rect(100,100).data('test', 101)
expect(rect.data('test')).toBe(101)
})
- it('should maintain data type for a number', function() {
+ it('maintains data type for a number', function() {
var rect = draw.rect(100,100).data('test', 101)
expect(typeof rect.data('test')).toBe('number')
})
- it('should maintain data type for an object', function() {
+ it('maintains data type for an object', function() {
var rect = draw.rect(100,100).data('test', { string: 'value', array: [1,2,3] })
expect(typeof rect.data('test')).toBe('object')
expect(Array.isArray(rect.data('test').array)).toBe(true)
diff --git a/spec/spec/ellipse.js b/spec/spec/ellipse.js
index 27d1840..7d7101a 100644
--- a/spec/spec/ellipse.js
+++ b/spec/spec/ellipse.js
@@ -110,6 +110,18 @@ describe('Ellipse', function() {
expect(ellipse.node.getAttribute('rx')).toBe((987 / 2).toString())
expect(ellipse.node.getAttribute('ry')).toBe((654 / 2).toString())
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = ellipse.bbox()
+ ellipse.size(500)
+ expect(ellipse.width()).toBe(500)
+ expect(ellipse.width() / ellipse.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = ellipse.bbox()
+ ellipse.size(null, 525)
+ expect(ellipse.height()).toBe(525)
+ expect(ellipse.width() / ellipse.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
diff --git a/spec/spec/gradient.js b/spec/spec/gradient.js
index e13e113..7072164 100644
--- a/spec/spec/gradient.js
+++ b/spec/spec/gradient.js
@@ -1,9 +1,18 @@
describe('Gradient', function() {
- var rect = draw.rect(100,100)
- , gradient = draw.gradient('linear', function(stop) {
+ var rect, gradient
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ gradient = draw.gradient('linear', function(stop) {
stop.at({ offset: 0, color: '#333', opacity: 1 })
stop.at({ offset: 1, color: '#fff', opacity: 1 })
})
+ })
+
+ afterEach(function() {
+ rect.remove()
+ gradient.remove()
+ })
it('is an instance of SVG.Gradient', function() {
expect(gradient instanceof SVG.Gradient).toBe(true)
diff --git a/spec/spec/helper.js b/spec/spec/helper.js
index 7394754..552ca6c 100644
--- a/spec/spec/helper.js
+++ b/spec/spec/helper.js
@@ -1,8 +1,8 @@
/* create canavs */
-var canvas = document.createElement('div')
-canvas.id = 'canvas'
-document.getElementsByTagName('body')[0].appendChild(canvas)
-draw = SVG(canvas).size(100,100)
+var drawing = document.createElement('div')
+drawing.id = 'drawing'
+document.getElementsByTagName('body')[0].appendChild(drawing)
+draw = SVG(drawing).size(100,100)
/* raw path data */
svgPath = 'M88.006,61.994c3.203,0,6.216-1.248,8.481-3.514C98.752,56.215,100,53.203,100,50c0-3.204-1.248-6.216-3.513-8.481 c-2.266-2.265-5.278-3.513-8.481-3.513c-2.687,0-5.237,0.877-7.327,2.496h-7.746l5.479-5.479 c5.891-0.757,10.457-5.803,10.457-11.896c0-6.614-5.381-11.995-11.994-11.995c-6.093,0-11.14,4.567-11.896,10.457l-5.479,5.479 v-7.747c1.618-2.089,2.495-4.641,2.495-7.327c0-3.204-1.247-6.216-3.513-8.481C56.216,1.248,53.204,0,50,0 c-3.204,0-6.216,1.248-8.481,3.513c-2.265,2.265-3.513,5.277-3.513,8.481c0,2.686,0.877,5.237,2.495,7.327v7.747l-5.479-5.479 c-0.757-5.89-5.803-10.457-11.896-10.457c-6.614,0-11.995,5.381-11.995,11.995c0,6.093,4.567,11.139,10.458,11.896l5.479,5.479 h-7.747c-2.089-1.619-4.641-2.496-7.327-2.496c-3.204,0-6.216,1.248-8.481,3.513C1.248,43.784,0,46.796,0,50 c0,3.203,1.248,6.216,3.513,8.48c2.265,2.266,5.277,3.514,8.481,3.514c2.686,0,5.237-0.877,7.327-2.496h7.747l-5.479,5.479 c-5.891,0.757-10.458,5.804-10.458,11.896c0,6.614,5.381,11.994,11.995,11.994c6.093,0,11.139-4.566,11.896-10.457l5.479-5.479 v7.749c-3.63,4.7-3.291,11.497,1.018,15.806C43.784,98.752,46.796,100,50,100c3.204,0,6.216-1.248,8.481-3.514 c4.309-4.309,4.647-11.105,1.018-15.806v-7.749l5.479,5.479c0.757,5.891,5.804,10.457,11.896,10.457 c6.613,0,11.994-5.38,11.994-11.994c0-6.093-4.566-11.14-10.457-11.896l-5.479-5.479h7.746 C82.769,61.117,85.319,61.994,88.006,61.994z M76.874,68.354c4.705,0,8.52,3.814,8.52,8.521c0,4.705-3.814,8.52-8.52,8.52 s-8.52-3.814-8.52-8.52l-12.33-12.33V81.98c3.327,3.328,3.327,8.723,0,12.049c-3.327,3.328-8.722,3.328-12.049,0 c-3.327-3.326-3.327-8.721,0-12.049V64.544l-12.33,12.33c0,4.705-3.814,8.52-8.52,8.52s-8.52-3.814-8.52-8.52 c0-4.706,3.814-8.521,8.52-8.521l12.33-12.33H18.019c-3.327,3.328-8.722,3.328-12.049,0c-3.327-3.326-3.327-8.721,0-12.048 s8.722-3.327,12.049,0h17.438l-12.33-12.33c-4.706,0-8.52-3.814-8.52-8.52c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52 l12.33,12.33V18.019c-3.327-3.327-3.327-8.722,0-12.049s8.722-3.327,12.049,0s3.327,8.722,0,12.049v17.438l12.33-12.33 c0-4.706,3.814-8.52,8.52-8.52s8.52,3.814,8.52,8.52c0,4.705-3.814,8.52-8.52,8.52l-12.33,12.33h17.438 c3.327-3.327,8.722-3.327,12.049,0s3.327,8.722,0,12.048c-3.327,3.328-8.722,3.328-12.049,0H64.544L76.874,68.354z'
diff --git a/spec/spec/image.js b/spec/spec/image.js
index 798ea08..b24835b 100644
--- a/spec/spec/image.js
+++ b/spec/spec/image.js
@@ -96,6 +96,18 @@ describe('Image', function() {
expect(image.node.getAttribute('width')).toBe('987')
expect(image.node.getAttribute('height')).toBe('654')
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = image.bbox()
+ image.size(500)
+ expect(image.width()).toBe(500)
+ expect(image.width() / image.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = image.bbox()
+ image.size(null, 525)
+ expect(image.height()).toBe(525)
+ expect(image.width() / image.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
diff --git a/spec/spec/line.js b/spec/spec/line.js
index 1ed45fb..cb9d6f6 100644
--- a/spec/spec/line.js
+++ b/spec/spec/line.js
@@ -112,6 +112,18 @@ describe('Line', function() {
expect(box.x + box.width).toBe(987)
expect(box.y).toBe(0)
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = line.bbox()
+ line.size(500)
+ expect(line.width()).toBe(500)
+ expect(line.width() / line.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = line.bbox()
+ line.size(null, 525)
+ expect(line.height()).toBe(525)
+ expect(line.width() / line.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
diff --git a/spec/spec/path.js b/spec/spec/path.js
index a64f8aa..9503e3b 100644
--- a/spec/spec/path.js
+++ b/spec/spec/path.js
@@ -102,12 +102,24 @@ describe('Path', function() {
})
describe('size()', function() {
- it('should define the width and height of the element', function() {
+ it('defines the width and height of the element', function() {
path.size(987,654)
var box = path.bbox()
expect(approximately(box.width, 0.1)).toBe(987)
expect(approximately(box.height, 0.1)).toBe(654)
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = path.bbox()
+ path.size(500)
+ expect(path.width()).toBe(500)
+ expect(path.width() / path.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = path.bbox()
+ path.size(null, 525)
+ expect(path.height()).toBe(525)
+ expect(path.width() / path.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
@@ -137,7 +149,7 @@ 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('M0,0')
+ expect(path.node.getAttribute('d')).toBe('M 0 0')
})
})
diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js
index a124796..e94facd 100644
--- a/spec/spec/polygon.js
+++ b/spec/spec/polygon.js
@@ -102,6 +102,18 @@ describe('Polygon', function() {
expect(approximately(box.width, 0.1)).toBe(987)
expect(approximately(box.height, 0.1)).toBe(654)
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = polygon.bbox()
+ polygon.size(500)
+ expect(polygon.width()).toBe(500)
+ expect(polygon.width() / polygon.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = polygon.bbox()
+ polygon.size(null, 525)
+ expect(polygon.height()).toBe(525)
+ expect(polygon.width() / polygon.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js
index 9272d78..204cfa7 100644
--- a/spec/spec/polyline.js
+++ b/spec/spec/polyline.js
@@ -102,6 +102,18 @@ describe('Polyline', function() {
expect(approximately(box.width, 0.1)).toBe(987)
expect(approximately(box.height, 0.1)).toBe(654)
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = polyline.bbox()
+ polyline.size(500)
+ expect(polyline.width()).toBe(500)
+ expect(polyline.width() / polyline.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = polyline.bbox()
+ polyline.size(null, 525)
+ expect(polyline.height()).toBe(525)
+ expect(polyline.width() / polyline.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {
diff --git a/spec/spec/rect.js b/spec/spec/rect.js
index 4b9ef2f..36d4925 100644
--- a/spec/spec/rect.js
+++ b/spec/spec/rect.js
@@ -109,6 +109,18 @@ describe('Rect', function() {
expect(rect.node.getAttribute('width')).toBe('987')
expect(rect.node.getAttribute('height')).toBe('654')
})
+ it('defines the width and height proportionally with only the width value given', function() {
+ var box = rect.bbox()
+ rect.size(500)
+ expect(rect.width()).toBe(500)
+ expect(rect.width() / rect.height()).toBe(box.width / box.height)
+ })
+ it('defines the width and height proportionally with only the height value given', function() {
+ var box = rect.bbox()
+ rect.size(null, 525)
+ expect(rect.height()).toBe(525)
+ expect(rect.width() / rect.height()).toBe(box.width / box.height)
+ })
})
describe('scale()', function() {