From c0b39c4b8f62e9d3b1ed9c906ad2bc0c0fbff576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 11 Feb 2016 12:51:48 +0100 Subject: [PATCH] Tests: Implement additional tests for SvgImport. --- test/assets/clipping.svg | 2 +- test/assets/gradients-1.svg | 12 ++++++++ test/assets/gradients-2-.svg | 11 ++++++++ test/assets/gradients-2.svg | 11 ++++++++ test/assets/viewbox.svg | 10 +++++++ test/helpers.js | 1 + test/tests/SvgImport.js | 55 ++++++++++++++++++++++++++---------- 7 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 test/assets/gradients-1.svg create mode 100644 test/assets/gradients-2-.svg create mode 100644 test/assets/gradients-2.svg create mode 100644 test/assets/viewbox.svg diff --git a/test/assets/clipping.svg b/test/assets/clipping.svg index a9fa2bae..79381bfc 100644 --- a/test/assets/clipping.svg +++ b/test/assets/clipping.svg @@ -1,5 +1,5 @@ +width="275" height="1041" viewBox="81 55 275 1041" xml:space="preserve"> Clipping a path with a path: diff --git a/test/assets/gradients-1.svg b/test/assets/gradients-1.svg new file mode 100644 index 00000000..d3235b6a --- /dev/null +++ b/test/assets/gradients-1.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/test/assets/gradients-2-.svg b/test/assets/gradients-2-.svg new file mode 100644 index 00000000..0fd6c3bd --- /dev/null +++ b/test/assets/gradients-2-.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/test/assets/gradients-2.svg b/test/assets/gradients-2.svg new file mode 100644 index 00000000..c80c6243 --- /dev/null +++ b/test/assets/gradients-2.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/test/assets/viewbox.svg b/test/assets/viewbox.svg new file mode 100644 index 00000000..558c5aea --- /dev/null +++ b/test/assets/viewbox.svg @@ -0,0 +1,10 @@ + + + + + Stretch to fit + + diff --git a/test/helpers.js b/test/helpers.js index 5974613d..4b837637 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -11,6 +11,7 @@ */ var isNode = typeof global === 'object', + isPhantom = !!window.callPhantom, root; if (isNode) { diff --git a/test/tests/SvgImport.js b/test/tests/SvgImport.js index f0026980..cbd8b859 100644 --- a/test/tests/SvgImport.js +++ b/test/tests/SvgImport.js @@ -120,23 +120,48 @@ test('Import complex CompoundPath and clone', function() { equals(item.clone(), item, null, { cloned: true }); }); -if (!isNode) { - test('Import SVG clipping', function(assert) { - importSVG(assert, 'assets/clipping.svg', - 'The imported SVG item should visually be the same as the rasterized original SVG data.'); +function importSVG(assert, url, message, options) { + var done = assert.async(); + if (!message) + message = 'The imported SVG "' + url + '" should visually be the same ' + + 'as the rasterized original SVG data.'; + project.importSVG(url, { + onLoad: function(item, svg) { + function getValue(name) { + return parseFloat(svg.getAttribute(name)); + } + /* + var size = new Size(getValue('width'), getValue('height')); + var group = new Group({ + children: [ + new Shape.Rectangle({ + clipMask: true, + size: size + }), + item + ] + }); + */ + compareSVG(done, item, svg, message, options); + }, + onError: function(error) { + // TODO: Implement in SvgImport first! + pushFailure('Loading SVG from a valid URL should not give an error.'); + done(); + } }); } -function importSVG(assert, url, message, options) { - var done = assert.async(); - project.importSVG(url, { - onLoad: function(item, svg) { - compareSVG(done, item, svg, message, options); - }, - onError: function(error) { - // TODO: Implement in SvgImport first! - pushFailure('Loading SVG from a valid URL should not give an error.'); - done(); - } +if (!isNode) { + // JSDom does not have SVG rendering, so we can't test there. + var svgFiles = ['viewbox', 'clipping', 'gradients-1']; + // TODO: Investigate why Phantom struggles with this file: + if (!isPhantom) + svgFiles.push('gradients-2'); + svgFiles.forEach(function(name) { + name += '.svg'; + test('Import ' + name, function(assert) { + importSVG(assert, 'assets/' + name); }); + }); }