From 41b55427a71f85e444a8729a552b4db5aa9ac772 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Mon, 6 Mar 2017 18:52:28 +0100 Subject: make flip working with both axis when no parameter / only offset is passed --- spec/spec/element.js | 12 ++++++++++-- spec/spec/sugar.js | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/spec/element.js b/spec/spec/element.js index 378505f..e05f596 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -295,11 +295,11 @@ 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() { + it('flips the element on x axis', 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() { + it('flips the element on x axis with offset', function() { rect.transform({ flip: 'x', offset: 20 }) expect(rect.node.getAttribute('transform')).toBe('matrix(-1,0,0,1,40,0)') }) @@ -307,6 +307,14 @@ describe('Element', function() { rect.transform({ flip: 'y', offset: 20 }) expect(rect.node.getAttribute('transform')).toBe('matrix(1,0,0,-1,0,40)') }) + it('flips the element on both axis with offset', function() { + rect.transform({ flip: 'both', offset: 20 }) + expect(rect.node.getAttribute('transform')).toBe('matrix(-1,0,0,-1,40,40)') + }) + it('flips the element on both axis', function() { + rect.transform({ flip: 'both' }) + expect(rect.node.getAttribute('transform')).toBe('matrix(-1,0,0,-1,0,0)') + }) }) describe('untransform()', function() { diff --git a/spec/spec/sugar.js b/spec/spec/sugar.js index 0aef812..df43610 100644 --- a/spec/spec/sugar.js +++ b/spec/spec/sugar.js @@ -171,8 +171,19 @@ describe('Sugar', function() { }) it('redirects to transform()', function() { - rect.flip(1,2) - expect(rect.transform).toHaveBeenCalledWith({ flip: 1, offset: 2 }) + rect.flip('x',2) + expect(rect.transform).toHaveBeenCalledWith({ flip: 'x', offset: 2 }) + }) + + it('sets flip to "both" when calling without anything', function() { + rect.flip() + expect(rect.transform).toHaveBeenCalledWith({ flip: 'both', offset: undefined }) + }) + + // this works because only x and y are valid flip values. Evereything else flips on both axis + it('sets flip to number and offset to number when called with offset only', function() { + rect.flip(5) + expect(rect.transform).toHaveBeenCalledWith({ flip: 5, offset: 5 }) }) }) -- cgit v1.2.3