Skip to content

Commit

Permalink
Tests: Implement additional tests for SvgImport.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Feb 11, 2016
1 parent 6797d2e commit c0b39c4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/assets/clipping.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test/assets/gradients-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/assets/gradients-2-.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/assets/gradients-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/assets/viewbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

var isNode = typeof global === 'object',
isPhantom = !!window.callPhantom,
root;

if (isNode) {
Expand Down
55 changes: 40 additions & 15 deletions test/tests/SvgImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

0 comments on commit c0b39c4

Please sign in to comment.