Skip to content

Commit

Permalink
Add more tests to SelectionRegion
Browse files Browse the repository at this point in the history
Fixes #155
  • Loading branch information
ipeychev committed Mar 26, 2015
1 parent 4a120fb commit 4db238c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/core/selection-region.js
Expand Up @@ -87,8 +87,6 @@

selection.unlock();

debugger;

range = document.body.createTextRange();
range.moveToPoint(startX, startY);

Expand Down Expand Up @@ -171,7 +169,7 @@
getSelectionRegion: function() {
var region = this.getClientRectsRegion();

region.direction = this._getSelectionDirection();
region.direction = this.getSelectionDirection();

region.height = region.bottom - region.top;
region.width = region.right - region.left;
Expand Down Expand Up @@ -304,13 +302,12 @@
* Retrieves the direction of the selection. The direction is from top to bottom or from bottom to top.
* For IE < 9 it is not possible, so the direction for these browsers will be always CKEDITOR.SELECTION_TOP_TO_BOTTOM.
*
* @method _getSelectionDirection
* @protected
* @method getSelectionDirection
* @return {Number} Returns a number which represents selection direction. It might be one of these:
* - CKEDITOR.SELECTION_TOP_TO_BOTTOM;
* - CKEDITOR.SELECTION_BOTTOM_TO_TOP;
*/
_getSelectionDirection: function() {
getSelectionDirection: function() {
var selection = this.getSelection();
var nativeSelection = selection.getNative();

Expand Down
1 change: 1 addition & 0 deletions src/ui/react/karma.js
Expand Up @@ -30,6 +30,7 @@ var filesToLoad = [
},

'src/ui/react/test/vendor/zepto.js',
'src/ui/react/test/vendor/happen.js',

/* CKEditor JS files */
{
Expand Down
66 changes: 66 additions & 0 deletions src/ui/react/test/selection-region.js
Expand Up @@ -25,4 +25,70 @@ describe('SelectionRegion', function() {

assert.isFalse(this.nativeEditor.isSelectionEmpty());
});

it('should create empty selection from point', function() {
this.nativeEditor.setData('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rhoncus augue a scelerisque imperdiet. Nunc quis nunc dolor. Nunc nisl felis, lacinia eu condimentum quis, interdum in tellus. Donec eget ipsum sed felis egestas euismod ultricies at arcu. Suspendisse potenti. Curabitur sed augue in sem efficitur fermentum ac quis mi. Fusce volutpat feugiat justo, non hendrerit justo bibendum eu. Maecenas pellentesque urna vitae odio condimentum, suscipit tempus nibh interdum. Fusce lacinia magna et nisl vestibulum, nec viverra nisl tempus. Curabitur viverra, arcu a vehicula imperdiet, lectus nisi faucibus velit, eget sodales ante lacus nec ligula. Morbi in placerat ligula. Maecenas volutpat sem id augue elementum auctor.');

var editable = this.nativeEditor.editable();

var region = editable.getClientRect();

// Add - 5 or + 5 to make sure the points are in the editable area
this.nativeEditor.createSelectionFromPoint(region.left + 5, region.top + 5);

assert.isTrue(this.nativeEditor.isSelectionEmpty());
});

it('should retrieve the caret region', function() {
bender.tools.selection.setWithHtml(this.nativeEditor, 'The caret shoud be in this {selection}.');

var caretRegion = this.nativeEditor.getCaretRegion();

assert.isObject(caretRegion);
assert.property(caretRegion, 'bottom');
assert.property(caretRegion, 'left');
assert.property(caretRegion, 'right');
assert.property(caretRegion, 'top');
});

it('should check if the selection is empty', function() {
bender.tools.selection.setWithHtml(this.nativeEditor, 'The selection should be empty in this case.');
var isSelectionEmpty = this.nativeEditor.isSelectionEmpty();
assert.isTrue(isSelectionEmpty);

bender.tools.selection.setWithHtml(this.nativeEditor, 'The selection should {not} be empty in this case.');
isSelectionEmpty = this.nativeEditor.isSelectionEmpty();
assert.isFalse(isSelectionEmpty);
});

it('should retrieve client selection regions', function () {
bender.tools.selection.setWithHtml(this.nativeEditor, 'Here we should have {selection}.');

var rect = this.nativeEditor.getClientRectsRegion();

assert.isObject(rect);
assert.property(rect, 'bottom');
assert.property(rect, 'left');
assert.property(rect, 'right');
assert.property(rect, 'top');


bender.tools.selection.setWithHtml(this.nativeEditor, 'Here we should have an empty selection.');

rect = this.nativeEditor.getClientRectsRegion();

assert.isObject(rect);
assert.property(rect, 'bottom');
assert.property(rect, 'left');
assert.property(rect, 'right');
assert.property(rect, 'top');
});

it('should retrieve selection direction', function() {
bender.tools.selection.setWithHtml(this.nativeEditor, 'Here we should have {selection}.');

var direction = this.nativeEditor.getSelectionDirection();

assert.strictEqual(CKEDITOR.SELECTION_TOP_TO_BOTTOM, direction);
});
});
8 changes: 4 additions & 4 deletions src/ui/react/test/tools.js
Expand Up @@ -7,19 +7,19 @@ describe('Tools', function() {

it('should merge objects and ignore inherited properties', function() {
var obj1 = {
prop1: 'prop1'
prop1: 'val1'
};

Object.prototype.test123 = 'test123';
Object.prototype.prop123 = 'val123';

var obj2 = {};

var obj3 = CKEDITOR.tools.merge(obj1, obj2);

delete Object.prototype.test123;

assert.strictEqual('prop1', obj3.prop1);
assert.isUndefined(obj3.test123);
assert.propertyVal(obj3, 'prop1', 'val1');
assert.notProperty(obj3, 'test123');
});

it('should simulate events on DOM elements', function() {
Expand Down

0 comments on commit 4db238c

Please sign in to comment.