Skip to content

Commit

Permalink
Merge pull request #1 from Pelckmans/retina-pelck
Browse files Browse the repository at this point in the history
Test fix for PR retina enhance
  • Loading branch information
asturur authored Nov 14, 2019
2 parents 19a99fc + d962bb1 commit 9ea99e8
Showing 1 changed file with 58 additions and 117 deletions.
175 changes: 58 additions & 117 deletions test/unit/brushes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,125 +22,66 @@
assert.deepEqual(brush._points, [], 'points is an empty array');
});

QUnit.module('fabric.BaseBrush with canvas.enableRetinaScaling = false', function(hooks) {
hooks.beforeEach(function() {
canvas.enableRetinaScaling = false;
});
QUnit.test('fabric pencil brush draw point', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 10 L 10.001 10', 'path data create a small line that looks like a point');
});
QUnit.test('fabric pencil brush multiple points', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 10 L 10.001 10', 'path data create a small line that looks like a point');
assert.equal(brush._points.length, 2, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 9.999 Q 10 10 12.5 12.5 Q 15 15 17.5 17.5 Q 20 20 17.5 17.5 Q 15 15 17.5 17.5 L 20.001 20.001', 'path data create a complex path');
assert.equal(brush._points.length, 6, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var fired = false;
var added = null;
canvas.on('path:created', function(opt) {
fired = true;
added = opt.path;
[true, false].forEach(function(val) {
QUnit.module('fabric.BaseBrush with canvas.enableRetinaScaling = ' + val, function(hooks) {
hooks.beforeEach(function() {
canvas.enableRetinaScaling = val;
});
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseUp({ e: {} });
assert.equal(fired, true, 'event is fired');
assert.ok(added instanceof fabric.Path, 'a path is added');
assert.ok(added.path.length, 6, 'path has 6 steps');
canvas.off();
});
});

QUnit.module('fabric.BaseBrush with canvas.enableRetinaScaling = true', function(hooks) {
hooks.beforeEach(function() {
canvas.enableRetinaScaling = true;
});
QUnit.test('fabric pencil brush draw point', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 4.999 5 L 5.001 5', 'path data create a small line that looks like a point');
});
QUnit.test('fabric pencil brush multiple points', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 4.999 5 L 5.001 5', 'path data create a small line that looks like a point');
assert.equal(brush._points.length, 2, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 4.999 4.999 Q 5 5 6.25 6.25 Q 7.5 7.5 8.75 8.75 Q 10 10 8.75 8.75 Q 7.5 7.5 8.75 8.75 L 10.001 10.001', 'path data create a complex path');
assert.equal(brush._points.length, 6, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var fired = false;
var added = null;
canvas.on('path:created', function(opt) {
fired = true;
added = opt.path;
QUnit.test('fabric pencil brush draw point', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 10 L 10.001 10', 'path data create a small line that looks like a point');
});
QUnit.test('fabric pencil brush multiple points', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
brush.onMouseMove(pointer, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 10 L 10.001 10', 'path data create a small line that looks like a point');
assert.equal(brush._points.length, 2, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
var pathData = brush.convertPointsToSVGPath(brush._points).join('');
assert.equal(pathData, 'M 9.999 9.999 Q 10 10 12.5 12.5 Q 15 15 17.5 17.5 Q 20 20 17.5 17.5 Q 15 15 17.5 17.5 L 20.001 20.001', 'path data create a complex path');
assert.equal(brush._points.length, 6, 'concident points are discarded');
});
QUnit.test('fabric pencil brush multiple points not discarded', function(assert) {
var fired = false;
var added = null;
canvas.on('path:created', function(opt) {
fired = true;
added = opt.path;
});
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseUp({ e: {} });
assert.equal(fired, true, 'event is fired');
assert.ok(added instanceof fabric.Path, 'a path is added');
assert.ok(added.path.length, 6, 'path has 6 steps');
canvas.off();
});
var brush = new fabric.PencilBrush(canvas);
var pointer = canvas.getPointer({ clientX: 10, clientY: 10});
var pointer2 = canvas.getPointer({ clientX: 15, clientY: 15});
var pointer3 = canvas.getPointer({ clientX: 20, clientY: 20});
brush.onMouseDown(pointer, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseMove(pointer2, { e: {} });
brush.onMouseMove(pointer3, { e: {} });
brush.onMouseUp({ e: {} });
assert.equal(fired, true, 'event is fired');
assert.ok(added instanceof fabric.Path, 'a path is added');
assert.ok(added.path.length, 6, 'path has 6 steps');
canvas.off();
});
});
});
Expand Down

0 comments on commit 9ea99e8

Please sign in to comment.