diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-01 20:00:38 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-01 20:00:38 +0100 |
commit | 5a6a9148f84928980dfc0756fe6a36ef0f57481d (patch) | |
tree | 9548e8363fab2037c7359badfff8e44f49364f6c /spec | |
parent | 9fbf3a17de0dd7f3d82e4362760434bc24b4a3b5 (diff) | |
download | svg.js-5a6a9148f84928980dfc0756fe6a36ef0f57481d.tar.gz svg.js-5a6a9148f84928980dfc0756fe6a36ef0f57481d.zip |
added test cases to increase coverage
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/element.js | 12 | ||||
-rw-r--r-- | spec/spec/fx.js | 64 |
2 files changed, 76 insertions, 0 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js index dfb73d7..35f62b5 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -286,6 +286,18 @@ describe('Element', function() { rect.transform({ a: 0.5, c: 0.5 }).transform(new SVG.Matrix({ e: 20, f: 20 }), true) expect(rect.node.getAttribute('transform')).toBe('matrix(0.5,0,0.5,1,20,20)') }) + it('flips the element', function() { + rect.transform({ flip: 'x' }) + expect(rect.node.getAttribute('transform')).toBe('matrix(-1,0,0,1,100,0)') + }) + it('flips the element with offset', function() { + rect.transform({ flip: 'x', offset: 20 }) + expect(rect.node.getAttribute('transform')).toBe('matrix(-1,0,0,1,40,0)') + }) + it('flips the element on y axis with offset', function() { + rect.transform({ flip: 'y', offset: 20 }) + expect(rect.node.getAttribute('transform')).toBe('matrix(1,0,0,-1,0,40)') + }) }) describe('untransform()', function() { diff --git a/spec/spec/fx.js b/spec/spec/fx.js index ded5829..1c5fb16 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -2457,6 +2457,70 @@ describe('FX', function() { expect(fx.add).not.toHaveBeenCalled() }) }) + + describe('transform()', function() { + it('gets the current transforms', function() { + expect(fx.transform()).toEqual(new SVG.Matrix(rect).extract()) + }) + it('gets a certain transformation if used with an argument', function() { + expect(fx.transform('x')).toEqual(0) + }) + it('adds an entry to transforms when matrix given', function() { + var matrix = new SVG.Matrix(1,2,3,4,5,6) + fx.transform(matrix) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(matrix)) + }) + it('sets relative flag when given', function() { + var matrix = new SVG.Matrix(1,2,3,4,5,6) + fx.transform(matrix, true) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(matrix)) + expect(fx.situation.transforms[0].relative).toBe(true) + }) + it('adds an entry to transforms when rotation given', function() { + fx.transform({rotation: 30, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Rotate(30, 0, 0))) + }) + it('adds an entry to transforms when scale given', function() { + fx.transform({scale: 2, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Scale(2, 2, 0, 0))) + }) + it('adds an entry to transforms when scaleX given', function() { + fx.transform({scaleX: 2, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Scale(2, 1, 0, 0))) + }) + it('adds an entry to transforms when scaleY given', function() { + fx.transform({scaleY: 2, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Scale(1, 2, 0, 0))) + }) + it('adds an entry to transforms when skewX given', function() { + fx.transform({skewX: 2, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Skew(2, 0, 0, 0))) + }) + it('adds an entry to transforms when skewY given', function() { + fx.transform({skewY: 2, cx:0, cy:0}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Skew(0, 2, 0, 0))) + }) + it('adds an entry to transforms when flip x given', function() { + fx.transform({flip: 'x'}) + expect(fx.situation.transforms[0].destination).toEqual(jasmine.objectContaining((new SVG.Matrix()).flip('x', 150))) + }) + it('adds an entry to transforms when flip x with offset given', function() { + fx.transform({flip: 'x', offset: 100}) + expect(fx.situation.transforms[0].destination).toEqual(jasmine.objectContaining((new SVG.Matrix()).flip('x', 100))) + }) + it('adds an entry to transforms when flip y given', function() { + fx.transform({flip: 'y'}) + expect(fx.situation.transforms[0].destination).toEqual(jasmine.objectContaining((new SVG.Matrix()).flip('y', 150))) + }) + it('adds an entry to transforms when x given', function() { + fx.transform({x:20}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Translate(20, undefined))) + }) + it('adds an entry to transforms when y given', function() { + fx.transform({y:20}) + expect(fx.situation.transforms[0]).toEqual(jasmine.objectContaining(new SVG.Translate(undefined, 20))) + }) + }) /* shortcuts for animation */ describe('animate()', function() { |