/
checkdirty.js
91 lines (71 loc) · 2.34 KB
/
checkdirty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* bender-tags: widgetcore */
/* bender-ckeditor-plugins: widget */
/* bender-include: _helpers/tools.js */
/* global widgetTestsTools */
( function() {
'use strict';
var data = '<p id="p1">bar<b id="w1" data-widget="testwidget">foo</b></p>',
getWidgetById = widgetTestsTools.getWidgetById;
bender.editors = {
editor: {
name: 'editor1',
creator: 'inline',
config: {
allowedContent: true,
on: {
pluginsLoaded: function( evt ) {
evt.editor.widgets.add( 'testwidget', {} );
}
}
}
}
};
bender.test( {
'test check dirty is false after widget focus': function() {
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' );
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' );
widget.focus();
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' );
} );
}
} );
} )();