Use comparePixels() instead of compareCanvas()

This commit is contained in:
Jürg Lehni 2019-06-05 18:16:56 +02:00
parent 2cb55a839d
commit da137fa8e4
3 changed files with 24 additions and 25 deletions

View file

@ -88,6 +88,10 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
} }
}, },
getContext: function() {
return this._context;
},
/** /**
* Converts the provide size in any of the units allowed in the browser to * Converts the provide size in any of the units allowed in the browser to
* pixels. * pixels.

View file

@ -345,25 +345,24 @@ var compareItem = function(actual, expected, message, options, properties) {
* @param {function} actualCallback the function producing the actual result * @param {function} actualCallback the function producing the actual result
* @param {number} tolerance between 0 and 1 * @param {number} tolerance between 0 and 1
*/ */
var compareCanvas = function(width, height, expectedCallback, actualCallback, var compareCanvas = function(width, height, expected, actual, tolerance) {
tolerance) {
function getImageData(width, height, callback) { function getImageData(width, height, callback) {
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = width; canvas.width = width;
canvas.height = height; canvas.height = height;
var project = new Project(canvas); var project = new Project(canvas);
var view = project.view;
callback(); callback();
project.view.update(); view.update();
var context = canvas.getContext('2d'); var imageData = view.context.getImageData(0, 0, width, height);
var imageData = context.getImageData(0, 0, width, height);
canvas.remove();
project.remove(); project.remove();
canvas.remove();
return imageData; return imageData;
} }
compareImageData( compareImageData(
getImageData(width, height, expectedCallback), getImageData(width, height, expected),
getImageData(width, height, actualCallback), getImageData(width, height, actual),
tolerance tolerance
); );

View file

@ -137,21 +137,17 @@ test('group.addChildren()', function() {
}); });
test('group.setSelectedColor() with selected bound and position', function() { test('group.setSelectedColor() with selected bound and position', function() {
compareCanvas(100, 100, // Working: Set selected color first then add child.
function() { var group1 = new Group();
// working: set selected color first then add child group1.bounds.selected = true;
var group = new Group(); group1.position.selected = true;
group.bounds.selected = true; group1.selectedColor = 'black';
group.position.selected = true; group1.addChild(new Path.Circle([50, 50], 40));
group.selectedColor = 'black'; // Failing: Add child first then set selected color.
group.addChild(new Path.Circle([50, 50], 40)); var group2 = new Group();
}, function() { group2.bounds.selected = true;
// failing: add child first then set selected color group2.position.selected = true;
var group = new Group(); group2.addChild(new Path.Circle([50, 50], 40));
group.bounds.selected = true; group2.selectedColor = 'black';
group.position.selected = true; comparePixels(group1, group2);
group.addChild(new Path.Circle([50, 50], 40));
group.selectedColor = 'black';
}
);
}); });