Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<head> | ||
<script src="_helpers/tools.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ); | ||
} ); | ||
} | ||
} ); | ||
|
||
})(); | ||
} )(); |