summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/fx.js67
-rw-r--r--spec/spec/number.js30
2 files changed, 97 insertions, 0 deletions
diff --git a/spec/spec/fx.js b/spec/spec/fx.js
index b8357db..3875681 100644
--- a/spec/spec/fx.js
+++ b/spec/spec/fx.js
@@ -1841,6 +1841,48 @@ describe('FX', function() {
fx.step()
expect(text.textPath().attr('startOffset')).toBe(morph.at(1).toString())
})
+
+ it('should allow 0 to be specified without unit', function () {
+ // This code snippet come from issue #552
+
+ var gradient = draw.gradient('linear', function(stop) {
+ s1 = stop.at(0, '#33235b')
+ s2 = stop.at(0.5, '#E97639')
+ s3 = stop.at(1, '#33235b')
+ })
+
+ var r1, r2;
+ var fill = draw.pattern('300%', '100%', function(add) {
+ r1 = add.rect('150%', '100%').fill(gradient)
+ r2 = add.rect('150%', '100%').fill(gradient)
+ });
+ fill.attr({patternUnits: 'userSpaceOnUse'})
+
+ r1.attr('x', 0).animate('0.5s').attr('x', '150%')
+ r2.attr('x', '-150%').animate('0.5s').attr('x', 0)
+
+ var text = draw.text('Manifesto').move('50%', '50%').fill(fill)
+ text.font({
+ size: 70
+ , anchor: 'middle'
+ , leading: 1
+ })
+
+ r1.fx.start()
+ r2.fx.start()
+
+ jasmine.clock().tick(250) // Have the animation be half way
+ r1.fx.step()
+ r2.fx.step()
+ expect(r1.attr('x')).toBe('75%')
+ expect(r2.attr('x')).toBe('-75%')
+
+ jasmine.clock().tick(250) // Have the animation reach its end
+ r1.fx.step()
+ r2.fx.step()
+ expect(r1.attr('x')).toBe('150%')
+ expect(r2.attr('x')).toBe('0%')
+ })
})
@@ -1928,5 +1970,30 @@ describe('FX', function() {
fx.step()
expect(rect.style('stroke-width')).toBe(morph.at(1).toString())
})
+
+ it('should allow 0 to be specified without a unit', function () {
+ var r1 = draw.rect(100,100).move(200,200)
+ , r2 = draw.rect(100,100).move(400,400)
+
+ r1.style('stroke-width', '100%').animate(500).style('stroke-width', 0)
+ r2.style('stroke-width', 0).animate(500).style('stroke-width', '100%')
+
+ r1.fx.start()
+ r2.fx.start()
+ expect(r1.style('stroke-width')).toBe('100%')
+ expect(r2.style('stroke-width')).toBe('0%')
+
+ jasmine.clock().tick(250) // Have the animation be half way
+ r1.fx.step()
+ r2.fx.step()
+ expect(r1.style('stroke-width')).toBe('50%')
+ expect(r2.style('stroke-width')).toBe('50%')
+
+ jasmine.clock().tick(250) // Have the animation reach its end
+ r1.fx.step()
+ r2.fx.step()
+ expect(r1.style('stroke-width')).toBe('0%')
+ expect(r2.style('stroke-width')).toBe('100%')
+ })
})
})
diff --git a/spec/spec/number.js b/spec/spec/number.js
index 890bb2c..e999187 100644
--- a/spec/spec/number.js
+++ b/spec/spec/number.js
@@ -127,6 +127,12 @@ describe('Number', function() {
it('adds a given pixel value', function() {
expect(number.plus('83px').valueOf()).toBe(83)
})
+ it('use the unit of this number as the unit of the returned number by default', function (){
+ expect(new SVG.Number('12s').plus('3%').unit).toBe('s')
+ })
+ it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() {
+ expect(number.plus('15%').unit).toBe('%')
+ })
})
describe('minus()', function() {
@@ -139,6 +145,12 @@ describe('Number', function() {
it('subtracts a given pixel value', function() {
expect(number.minus('85px').valueOf()).toBe(-85)
})
+ it('use the unit of this number as the unit of the returned number by default', function (){
+ expect(new SVG.Number('12s').minus('3%').unit).toBe('s')
+ })
+ it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() {
+ expect(number.minus('15%').unit).toBe('%')
+ })
})
describe('times()', function() {
@@ -154,6 +166,12 @@ describe('Number', function() {
it('multiplies with a given pixel value', function() {
expect(number.times('85px').valueOf()).toBe(340)
})
+ it('use the unit of this number as the unit of the returned number by default', function (){
+ expect(new SVG.Number('12s').times('3%').unit).toBe('s')
+ })
+ it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() {
+ expect(number.times('15%').unit).toBe('%')
+ })
})
describe('divide()', function() {
@@ -169,6 +187,12 @@ describe('Number', function() {
it('divides by a given pixel value', function() {
expect(number.divide('45px').valueOf()).toBe(2)
})
+ it('use the unit of this number as the unit of the returned number by default', function (){
+ expect(new SVG.Number('12s').divide('3%').unit).toBe('s')
+ })
+ it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() {
+ expect(number.divide('15%').unit).toBe('%')
+ })
})
describe('morph()', function() {
@@ -207,6 +231,12 @@ describe('Number', function() {
var morphed = number.morph(destination).at(0.72)
expect(morphed.toString()).toBe('72%')
})
+ it('use the unit of the destination number as the unit of the returned number by default', function() {
+ expect(new SVG.Number('100s').morph('50%').at(0.5).unit).toBe('%')
+ })
+ it('use the unit of this number as the unit of the returned number when the destination number as no unit', function() {
+ expect(expect(new SVG.Number('100s').morph(50).at(0.5).unit).toBe('s'))
+ })
})
})