summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-07-25 17:47:03 +0200
committerwout <wout@impinc.co.uk>2014-07-25 17:47:03 +0200
commit9842187d84e71e736ada6a2e9444bab592945600 (patch)
tree3b2e67ca99fd881d0d6a8e2ab6358c4ef077a74a /spec
parent94077ff77815f622f6ad0daebf26160ec33e0271 (diff)
downloadsvg.js-9842187d84e71e736ada6a2e9444bab592945600.tar.gz
svg.js-9842187d84e71e736ada6a2e9444bab592945600.zip
Various small fixes
Diffstat (limited to 'spec')
-rwxr-xr-xspec/spec/element.js37
-rw-r--r--spec/spec/matrix.js48
-rw-r--r--spec/spec/regex.js27
3 files changed, 88 insertions, 24 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js
index d98aa45..8864afa 100755
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -151,40 +151,61 @@ describe('Element', function() {
})
describe('transform()', function() {
+ var rect
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ })
+
it('gets the current transformations', function() {
- var rect = draw.rect(100,100)
expect(rect.transform()).toEqual(new SVG.Matrix(rect).extract())
})
it('sets the translation of and element', function() {
- var rect = draw.rect(100,100).transform({ x: 10, y: 11 })
+ rect.transform({ x: 10, y: 11 })
expect(rect.node.getAttribute('transform')).toBe('matrix(1,0,0,1,10,11)')
})
it('sets the scaleX and scaleY of and element', function() {
- var rect = draw.rect(100,100).transform({ scaleX: 0.5, scaleY: 2 })
+ rect.transform({ scaleX: 0.5, scaleY: 2 })
expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0,2,0,0)')
})
it('sets the skewX of and element', function() {
- var rect = draw.rect(100,100).transform({ skewX: 10 })
+ rect.transform({ skewX: 10 })
expect(rect.node.getAttribute('transform')).toBe('matrix(1,0,0.17632698070846498,1,0,0)')
})
it('sets the skewY of and element', function() {
- var rect = draw.rect(100,100).transform({ skewY: -10 })
+ rect.transform({ skewY: -10 })
expect(rect.node.getAttribute('transform')).toBe('matrix(1,-0.17632698070846498,0,1,0,0)')
})
it('rotates the element around its centre if no rotation point is given', function() {
- var rect = draw.rect(100,100).center(150,150).transform({ rotation: 45 })
+ rect.center(150,150).transform({ rotation: 45 })
expect(rect.node.getAttribute('transform')).toBe('matrix(0.7071067811865475,0.7071067811865475,-0.7071067811865475,0.7071067811865475,150,-62.13203435596424)')
expect(rect.transform('rotation')).toBe(45)
})
it('rotates the element around the given rotation point', function() {
- var rect = draw.rect(100,100).transform({ rotation: 55, cx: 80, cy:2 })
+ rect.transform({ rotation: 55, cx: 80, cy:2 })
expect(rect.node.getAttribute('transform')).toBe('matrix(0.573576436351046,0.8191520442889917,-0.8191520442889917,0.573576436351046,35.7521891804943,-64.67931641582143)')
})
it('transforms element using a matrix', function() {
- var rect = draw.rect(100,100).transform({ a: 0.5, c: 0.5 })
+ rect.transform({ a: 0.5, c: 0.5 })
expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0.5,1,0,0)')
})
})
+
+ describe('ctm()', function() {
+ var rect
+
+ beforeEach(function() {
+ rect = draw.rect(100,100)
+ })
+
+ it('gets the current transform matrix of the element', function() {
+ rect.translate(10, 20)
+ expect(rect.ctm().toString()).toBe('matrix(1,0,0,1,10,20)')
+ })
+ it('returns an instance of SVG.Matrix', function() {
+ expect(rect.ctm() instanceof SVG.Matrix).toBeTruthy()
+ })
+ })
describe('data()', function() {
it('sets a data attribute and convert value to json', function() {
diff --git a/spec/spec/matrix.js b/spec/spec/matrix.js
index 5c2286e..feed9b4 100644
--- a/spec/spec/matrix.js
+++ b/spec/spec/matrix.js
@@ -37,25 +37,55 @@ describe('Matrix', function() {
expect(extract.scaleX).toBe(1)
expect(extract.scaleY).toBe(1)
})
- it('parses rotaton value', function() {
+ it('parses rotatoin value', function() {
expect(extract.rotation).toBe(0)
})
})
})
describe('with an element given', function() {
-
+ var rect
+
beforeEach(function() {
- matrix = new SVG.Matrix(draw.rect(100, 100).skew(10, 20).translate(40, 50).scale(3, 2))
+ rect = draw.rect(100, 100)
+ matrix = new SVG.Matrix(rect)
})
it('parses the current transform matrix form an element', function() {
- expect(matrix.a).toBe(3.192533254623413)
- expect(matrix.b).toBe(1.091910719871521)
- expect(matrix.c).toBe(0.35265403985977173)
- expect(matrix.d).toBe(2)
- expect(matrix.e).toBe(51.383460998535156)
- expect(matrix.f).toBe(64.55880737304688)
+ rect.rotate(-10).translate(40, 50).scale(2)
+ expect(matrix.a).toBe(1.9696155786514282)
+ expect(matrix.b).toBe(-0.3472963869571686)
+ expect(matrix.c).toBe(0.3472963869571686)
+ expect(matrix.d).toBe(1.9696155786514282)
+ expect(matrix.e).toBe(-8.373950958251953)
+ expect(matrix.f).toBe(7.758301258087158)
+ })
+
+ describe('extract()', function() {
+
+ it('parses translation values', function() {
+ var extract = new SVG.Matrix(draw.rect(100, 100).translate(40, 50)).extract()
+ expect(extract.x).toBe(40)
+ expect(extract.y).toBe(50)
+ })
+ it('parses skewX value', function() {
+ var extract = new SVG.Matrix(draw.rect(100, 100).skew(10, 0)).extract()
+ expect(approximately(extract.skewX, 0.01)).toBe(10)
+ })
+ it('parses skewX value', function() {
+ var extract = new SVG.Matrix(draw.rect(100, 100).skew(0, 20)).extract()
+ expect(approximately(extract.skewY, 0.01)).toBe(20)
+ })
+ it('parses scale values', function() {
+ var extract = new SVG.Matrix(draw.rect(100, 100).scale(2, 3)).extract()
+ expect(extract.scaleX).toBe(2)
+ expect(extract.scaleY).toBe(3)
+ })
+ it('parses rotatoin value', function() {
+ var extract = new SVG.Matrix(draw.rect(100, 100).rotate(-100)).extract()
+ expect(approximately(extract.rotation, 0.01)).toBe(-100)
+ })
+
})
})
diff --git a/spec/spec/regex.js b/spec/spec/regex.js
index 4b36175..f017059 100644
--- a/spec/spec/regex.js
+++ b/spec/spec/regex.js
@@ -22,17 +22,30 @@ describe('Regex', function() {
})
describe('testers', function() {
- describe('isEvent', function() {
- it('is true with a namespaced and lowercase name', function() {
- expect(SVG.regex.isEvent.test('my:event')).toBeTruthy()
+
+ describe('isHex', function() {
+ it('is true with a three based hex', function() {
+ expect(SVG.regex.isHex.test('#f09')).toBeTruthy()
+ })
+ it('is true with a six based hex', function() {
+ expect(SVG.regex.isHex.test('#fe0198')).toBeTruthy()
+ })
+ it('is false with a faulty hex', function() {
+ expect(SVG.regex.isHex.test('###')).toBeFalsy()
+ expect(SVG.regex.isHex.test('#0')).toBeFalsy()
+ expect(SVG.regex.isHex.test('f06')).toBeFalsy()
})
- it('is true with a namespaced and camelCase name', function() {
- expect(SVG.regex.isEvent.test('mt:fabulousEvent')).toBeTruthy()
+ })
+
+ describe('isRgb', function() {
+ it('is true with an rgb value', function() {
+ expect(SVG.regex.isRgb.test('rgb(255,66,100)')).toBeTruthy()
})
- it('is false without a namespace', function() {
- expect(SVG.regex.isEvent.test('idontlinkenamespaces')).toBeFalsy()
+ it('is false with a non-rgb value', function() {
+ expect(SVG.regex.isRgb.test('hsb(255, 100, 100)')).toBeFalsy()
})
})
+
})
}) \ No newline at end of file