diff --git a/test/unit/itext_click_behaviour.js b/test/unit/itext_click_behaviour.js index 7a9ce012..e111f1eb 100644 --- a/test/unit/itext_click_behaviour.js +++ b/test/unit/itext_click_behaviour.js @@ -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); + }); })();