Skip to content

Commit 294b62c

Browse files
committed
Merge branch 't/11753'
2 parents 4d0d69f + 09abecc commit 294b62c

File tree

2 files changed

+67
-25
lines changed

2 files changed

+67
-25
lines changed

tests/plugins/widget/checkdirty.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<head>
2+
<script src="_helpers/tools.js"></script>
3+
</head>
4+
<body>
5+
6+
</body>

tests/plugins/widget/checkdirty.js

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,98 @@
1+
/* bender-tags: editor,unit,widgetcore */
12
/* bender-ckeditor-plugins: widget */
23

3-
(function() {
4+
( function() {
45
'use strict';
56

7+
var data = '<p id="p1">bar<b id="w1" data-widget="testwidget">foo</b></p>',
8+
getWidgetById = widgetTestsTools.getWidgetById;
9+
610
bender.test( {
711
'async:init': function() {
812
var tc = this;
913

1014
bender.tools.setUpEditors( {
1115
editor: {
1216
name: 'editor1',
13-
startupData: '<b id="one" data-widget="testwidget">foo</b><b id="two" data-widget="testwidget">foo</b>',
17+
creator: 'inline',
1418
config: {
1519
allowedContent: true,
1620
on: {
1721
pluginsLoaded: function( evt ) {
18-
var ed = evt.editor;
19-
20-
ed.widgets.add( 'testwidget', {} );
22+
evt.editor.widgets.add( 'testwidget', {} );
2123
}
2224
}
2325
}
2426
}
2527
}, function( editors, bots ) {
26-
tc.editor = bots.editor.editor;
28+
tc.editors = editors;
29+
tc.editorBots = bots;
2730

2831
tc.callback();
2932
} );
3033
},
3134

3235
'test check dirty is false after widget focus': function() {
33-
var widget = this.editor.widgets.instances[ 1 ];
36+
var editor = this.editors.editor;
37+
38+
this.editorBots.editor.setData( data, function() {
39+
var widget = getWidgetById( editor, 'w1' );
40+
41+
editor.resetDirty();
42+
widget.focus();
43+
assert.isFalse( editor.checkDirty() );
44+
} );
45+
},
46+
47+
'test check dirty is false after widget blur': function() {
48+
var editor = this.editors.editor;
49+
50+
this.editorBots.editor.setData( data, function() {
51+
var widget = getWidgetById( editor, 'w1' );
3452

35-
assert.isFalse( this.editor.checkDirty() );
36-
widget.focus();
37-
assert.isFalse( this.editor.checkDirty() );
53+
widget.focus();
54+
editor.resetDirty();
55+
56+
var range = editor.createRange();
57+
range.moveToPosition( editor.document.getById( 'p1' ), CKEDITOR.POSITION_AFTER_START );
58+
editor.getSelection().selectRanges( [ range ] );
59+
60+
assert.isFalse( editor.checkDirty() );
61+
} );
3862
},
3963

40-
'test check dirty is true after modifications': function() {
41-
var widget = this.editor.widgets.instances[ 1 ];
64+
'test check dirty keeps to be true after widget focus': function() {
65+
var editor = this.editors.editor;
66+
67+
this.editorBots.editor.setData( data, function() {
68+
var widget = getWidgetById( editor, 'w1' );
4269

43-
assert.isFalse( this.editor.checkDirty() );
70+
// Make some changes in editor.
71+
widget.addClass( 'test' );
72+
assert.isTrue( editor.checkDirty(), 'before focus' );
4473

45-
// Clear selection
46-
var range = this.editor.createRange();
47-
var lastElement = this.editor.document.getById( 'two' );
48-
range.moveToPosition( lastElement, CKEDITOR.POSITION_BEFORE_END );
49-
this.editor.getSelection().selectRanges( [ range ] );
74+
widget.focus();
75+
assert.isTrue( editor.checkDirty(), 'after focus' );
76+
} );
77+
},
5078

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

53-
// Make some changes in editor
54-
widget.addClass( 'test' );
82+
this.editorBots.editor.setData( data, function() {
83+
var widget = getWidgetById( editor, 'w1' );
5584

56-
assert.isTrue( this.editor.checkDirty() );
57-
widget.focus();
58-
assert.isTrue( this.editor.checkDirty() );
85+
widget.focus();
86+
// Make some changes in editor.
87+
widget.addClass( 'test' );
88+
assert.isTrue( editor.checkDirty(), 'before blur' );
89+
90+
var range = editor.createRange();
91+
range.moveToPosition( editor.document.getById( 'p1' ), CKEDITOR.POSITION_AFTER_START );
92+
editor.getSelection().selectRanges( [ range ] );
93+
assert.isTrue( editor.checkDirty(), 'after blur' );
94+
} );
5995
}
6096
} );
6197

62-
})();
98+
} )();

0 commit comments

Comments
 (0)