added a test (#5462)

This commit is contained in:
Andrea Bogazzi 2019-01-06 01:30:35 +01:00 committed by GitHub
parent 1bb1f8eb85
commit 38af9f0e02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@
QUnit.module('iText click interaction', {
afterEach: function() {
canvas.clear();
canvas.cancelRequestedRender();
}
});
@ -107,4 +108,45 @@
assert.equal(iText.isEditing, false, 'iText did not entered editing');
iText.exitEditing();
});
QUnit.test('click on editing itext make selection:changed fire', function(assert) {
var done = assert.async();
var eventData = {
which: 1,
target: canvas.upperCanvasEl,
clientX: 30,
clientY: 10
};
var count = 0;
var countCanvas = 0;
var iText = new fabric.IText('test test');
canvas.on('text:selection:changed', function() {
countCanvas++;
});
iText.on('selection:changed', function() {
count++;
});
canvas.add(iText);
assert.equal(canvas.getActiveObject(), null, 'no active object exist');
assert.equal(count, 0, 'no selection:changed fired yet');
assert.equal(countCanvas, 0, 'no text:selection:changed fired yet');
canvas._onMouseDown(eventData);
canvas._onMouseUp(eventData);
assert.equal(canvas.getActiveObject(), iText, 'Itext got selected');
assert.equal(iText.isEditing, false, 'Itext is not editing yet');
assert.equal(count, 0, 'no selection:changed fired yet');
assert.equal(countCanvas, 0, 'no text:selection:changed fired yet');
assert.equal(iText.selectionStart, 0, 'Itext did not set the selectionStart');
assert.equal(iText.selectionEnd, 0, 'Itext did not set the selectionend');
// make a little delay or it will act as double click and select everything
setTimeout(function() {
canvas._onMouseDown(eventData);
canvas._onMouseUp(eventData);
assert.equal(iText.isEditing, true, 'Itext entered editing');
assert.equal(iText.selectionStart, 2, 'Itext set the selectionStart');
assert.equal(iText.selectionEnd, 2, 'Itext set the selectionend');
assert.equal(count, 1, 'no selection:changed fired yet');
assert.equal(countCanvas, 1, 'no text:selection:changed fired yet');
done();
}, 500);
});
})();