Skip to content

Commit

Permalink
Merge branch 't/11753'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jun 17, 2014
2 parents 4d0d69f + 09abecc commit 294b62c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 25 deletions.
6 changes: 6 additions & 0 deletions tests/plugins/widget/checkdirty.html
@@ -0,0 +1,6 @@
<head>
<script src="_helpers/tools.js"></script>
</head>
<body>

</body>
86 changes: 61 additions & 25 deletions tests/plugins/widget/checkdirty.js
@@ -1,62 +1,98 @@
/* bender-tags: editor,unit,widgetcore */
/* bender-ckeditor-plugins: widget */

(function() {
( function() {
'use strict';

var data = '<p id="p1">bar<b id="w1" data-widget="testwidget">foo</b></p>',
getWidgetById = widgetTestsTools.getWidgetById;

bender.test( {
'async:init': function() {
var tc = this;

bender.tools.setUpEditors( {
editor: {
name: 'editor1',
startupData: '<b id="one" data-widget="testwidget">foo</b><b id="two" data-widget="testwidget">foo</b>',
creator: 'inline',
config: {
allowedContent: true,
on: {
pluginsLoaded: function( evt ) {
var ed = evt.editor;

ed.widgets.add( 'testwidget', {} );
evt.editor.widgets.add( 'testwidget', {} );
}
}
}
}
}, function( editors, bots ) {
tc.editor = bots.editor.editor;
tc.editors = editors;
tc.editorBots = bots;

tc.callback();
} );
},

'test check dirty is false after widget focus': function() {
var widget = this.editor.widgets.instances[ 1 ];
var editor = this.editors.editor;

this.editorBots.editor.setData( data, function() {
var widget = getWidgetById( editor, 'w1' );

editor.resetDirty();
widget.focus();
assert.isFalse( editor.checkDirty() );
} );
},

'test check dirty is false after widget blur': function() {
var editor = this.editors.editor;

this.editorBots.editor.setData( data, function() {
var widget = getWidgetById( editor, 'w1' );

assert.isFalse( this.editor.checkDirty() );
widget.focus();
assert.isFalse( this.editor.checkDirty() );
widget.focus();
editor.resetDirty();

var range = editor.createRange();
range.moveToPosition( editor.document.getById( 'p1' ), CKEDITOR.POSITION_AFTER_START );
editor.getSelection().selectRanges( [ range ] );

assert.isFalse( editor.checkDirty() );
} );
},

'test check dirty is true after modifications': function() {
var widget = this.editor.widgets.instances[ 1 ];
'test check dirty keeps to be true after widget focus': function() {
var editor = this.editors.editor;

this.editorBots.editor.setData( data, function() {
var widget = getWidgetById( editor, 'w1' );

assert.isFalse( this.editor.checkDirty() );
// Make some changes in editor.
widget.addClass( 'test' );
assert.isTrue( editor.checkDirty(), 'before focus' );

// Clear selection
var range = this.editor.createRange();
var lastElement = this.editor.document.getById( 'two' );
range.moveToPosition( lastElement, CKEDITOR.POSITION_BEFORE_END );
this.editor.getSelection().selectRanges( [ range ] );
widget.focus();
assert.isTrue( editor.checkDirty(), 'after focus' );
} );
},

assert.isFalse( this.editor.checkDirty() );
'test check dirty keeps to be false after widget blur': function() {
var editor = this.editors.editor;

// Make some changes in editor
widget.addClass( 'test' );
this.editorBots.editor.setData( data, function() {
var widget = getWidgetById( editor, 'w1' );

assert.isTrue( this.editor.checkDirty() );
widget.focus();
assert.isTrue( this.editor.checkDirty() );
widget.focus();
// Make some changes in editor.
widget.addClass( 'test' );
assert.isTrue( editor.checkDirty(), 'before blur' );

var range = editor.createRange();
range.moveToPosition( editor.document.getById( 'p1' ), CKEDITOR.POSITION_AFTER_START );
editor.getSelection().selectRanges( [ range ] );
assert.isTrue( editor.checkDirty(), 'after blur' );
} );
}
} );

})();
} )();

0 comments on commit 294b62c

Please sign in to comment.