From fe402538f24ee8fc1c4d378bb6776a0a217d6740 Mon Sep 17 00:00:00 2001 From: Saivan Date: Sun, 4 Mar 2018 08:54:28 +1100 Subject: Fixed all transformation tests, the new transforms are ready This commit fixes all of the tests to reflect all of the changes to our transform code. It also makes the default test output dots instead of anything else. --- spec/spec/boxes.js | 2 +- spec/spec/element.js | 22 ++++++++-------------- spec/spec/helper.js | 14 +++++++++++++- 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'spec') diff --git a/spec/spec/boxes.js b/spec/spec/boxes.js index 1f4aee9..934f472 100644 --- a/spec/spec/boxes.js +++ b/spec/spec/boxes.js @@ -163,7 +163,7 @@ describe('Boxes', function() { offset = draw.screenCTM() draw.viewbox(100,100, 200, 200) nested = draw.nested().size(200, 200).move(100,100).viewbox(0, 0, 100, 100) - rect = nested.rect(50, 180).stroke({width:0}).move(25, 90).transform({scale: 2, origin: [0, 0]}).translate(10, 10) + rect = nested.rect(50, 180).stroke({width:0}).move(25, 90).transform({scale: 2, origin: [0, 0]}).relative(10, 10) }) afterEach(function() { draw.clear().attr('viewBox', null) diff --git a/spec/spec/element.js b/spec/spec/element.js index d21b965..d6e2783 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -421,9 +421,11 @@ describe('Element', function() { }) it('moves the element to other parent while maintaining the same visal representation', function() { - expect(rect1.toParent(nested).transform('matrix')).toBeCloseTo(new SVG.Matrix(2, 0, 0, 2, 120, 120)) + expect(window.roundMatrix(rect1.toParent(nested).transform('matrix'))) + .toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) expect(rect1.parent()).toEqual(nested) - expect(rect2.toParent(g2).transform('matrix')).toBeCloseTo(new SVG.Matrix(0.5, 0, 0, 0.5, -120, -120)) + expect(window.roundMatrix(rect2.toParent(g2).transform('matrix'))) + .toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, -120, -120)) expect(rect2.parent()).toEqual(g2) }) }) @@ -475,12 +477,8 @@ describe('Element', function() { expect(g1.node.parentNode).toBeFalsy() expect(g2.node.parentNode).toBeFalsy() - expect(rect1.transform()).toEqual(jasmine.objectContaining({ - a:2, b:0, c:0, d:2, e:120, f:120 - })) - expect(rect2.transform()).toEqual(jasmine.objectContaining({ - a:0.5, b:0, c:0, d:0.5, e:20, f:20 - })) + expect(window.roundMatrix(rect1.transform().matrix)).toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) + expect(window.roundMatrix(rect2.transform().matrix)).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 20, 20)) }) it('ungroups everything to the doc root when called on SVG.Doc / does not ungroup defs/parser', function() { @@ -493,12 +491,8 @@ describe('Element', function() { expect(g2.node.parentNode).toBeFalsy() expect(nested.node.parentNode).toBeFalsy() - expect(rect1.transform()).toEqual(jasmine.objectContaining({ - a:2, b:0, c:0, d:2, e:120, f:120 - })) - expect(rect2.transform()).toEqual(jasmine.objectContaining({ - a:0.5, b:0, c:0, d:0.5, e:20, f:20 - })) + expect(window.roundMatrix(rect1.transform().matrix)).toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) + expect(window.roundMatrix(rect2.transform().matrix)).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 20, 20)) expect(draw.children().length).toBe(3+parserInDoc) // 2 * rect + defs }) diff --git a/spec/spec/helper.js b/spec/spec/helper.js index 4c15acd..a77b3e7 100644 --- a/spec/spec/helper.js +++ b/spec/spec/helper.js @@ -10,7 +10,7 @@ if(typeof exports === 'object'){ drawing = document.documentElement imageUrl = 'spec/fixtures/pixel.png' parserInDoc = true - + function tag(name, attrs, children) { var el = document.createElement(name) for(var i in attrs){ @@ -175,3 +175,15 @@ window.roundBox = function(box) { Math.round(box.height) ) } + +// Same thing here with matrices +window.roundMatrix = function (mat) { + return new SVG.Matrix( + +(mat.a.toFixed(5)), + +(mat.b.toFixed(5)), + +(mat.c.toFixed(5)), + +(mat.d.toFixed(5)), + +(mat.e.toFixed(5)), + +(mat.f.toFixed(5)), + ) +} -- cgit v1.2.3