mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-01 02:24:42 +00:00
added a test (#5462)
This commit is contained in:
parent
1bb1f8eb85
commit
38af9f0e02
1 changed files with 42 additions and 0 deletions
|
|
@ -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);
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue