From accd13281352d4419ce113db2c2faae786b4f972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Reinmar=20Koszuli=C5=84ski?= Date: Mon, 16 Jun 2014 10:52:24 +0200 Subject: [PATCH 1/2] Code refactoring: Polished tests. --- tests/plugins/widget/checkdirty.html | 6 +++ tests/plugins/widget/checkdirty.js | 55 +++++++++++++++------------- 2 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 tests/plugins/widget/checkdirty.html diff --git a/tests/plugins/widget/checkdirty.html b/tests/plugins/widget/checkdirty.html new file mode 100644 index 00000000000..8d428ce46d5 --- /dev/null +++ b/tests/plugins/widget/checkdirty.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/plugins/widget/checkdirty.js b/tests/plugins/widget/checkdirty.js index 7249b870a67..4065ec6092a 100644 --- a/tests/plugins/widget/checkdirty.js +++ b/tests/plugins/widget/checkdirty.js @@ -1,8 +1,12 @@ +/* bender-tags: editor,unit,widgetcore */ /* bender-ckeditor-plugins: widget */ -(function() { +( function() { 'use strict'; + var data = '

foobar

', + getWidgetById = widgetTestsTools.getWidgetById; + bender.test( { 'async:init': function() { var tc = this; @@ -10,53 +14,52 @@ bender.tools.setUpEditors( { editor: { name: 'editor1', - startupData: 'foofoo', + 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; - assert.isFalse( this.editor.checkDirty() ); - widget.focus(); - assert.isFalse( this.editor.checkDirty() ); - }, + this.editorBots.editor.setData( data, function() { + var widget = getWidgetById( editor, 'w1' ); - 'test check dirty is true after modifications': function() { - var widget = this.editor.widgets.instances[ 1 ]; + editor.resetDirty(); + widget.focus(); + assert.isFalse( editor.checkDirty() ); + } ); + }, - assert.isFalse( this.editor.checkDirty() ); + 'test check dirty keeps to be true after widget focus': function() { + var editor = this.editors.editor; - // 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 ] ); + this.editorBots.editor.setData( data, function() { + var widget = getWidgetById( editor, 'w1' ); - assert.isFalse( this.editor.checkDirty() ); + editor.resetDirty(); - // Make some changes in editor - widget.addClass( 'test' ); + // Make some changes in editor. + widget.addClass( 'test' ); - assert.isTrue( this.editor.checkDirty() ); - widget.focus(); - assert.isTrue( this.editor.checkDirty() ); + assert.isTrue( editor.checkDirty() ); + widget.focus(); + assert.isTrue( editor.checkDirty() ); + } ); } } ); -})(); \ No newline at end of file +} )(); \ No newline at end of file From 09abecc0c203365b8da20a78ae9994e6f042e8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Reinmar=20Koszuli=C5=84ski?= Date: Mon, 16 Jun 2014 10:59:49 +0200 Subject: [PATCH 2/2] Tests: Added missing tests. --- tests/plugins/widget/checkdirty.js | 41 +++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/tests/plugins/widget/checkdirty.js b/tests/plugins/widget/checkdirty.js index 4065ec6092a..bb33ec37ae1 100644 --- a/tests/plugins/widget/checkdirty.js +++ b/tests/plugins/widget/checkdirty.js @@ -4,7 +4,7 @@ ( function() { 'use strict'; - var data = '

foobar

', + var data = '

barfoo

', getWidgetById = widgetTestsTools.getWidgetById; bender.test( { @@ -44,20 +44,53 @@ } ); }, - 'test check dirty keeps to be true after widget focus': function() { + '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' ); + 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 keeps to be true after widget focus': function() { + var editor = this.editors.editor; + + this.editorBots.editor.setData( data, function() { + var widget = getWidgetById( editor, 'w1' ); + // Make some changes in editor. widget.addClass( 'test' ); + assert.isTrue( editor.checkDirty(), 'before focus' ); - assert.isTrue( editor.checkDirty() ); widget.focus(); - assert.isTrue( editor.checkDirty() ); + assert.isTrue( editor.checkDirty(), 'after focus' ); + } ); + }, + + 'test check dirty keeps to be false after widget blur': function() { + var editor = this.editors.editor; + + this.editorBots.editor.setData( data, function() { + var widget = getWidgetById( editor, 'w1' ); + + 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' ); } ); } } );