1
1
/* bender-tags: editor,unit */
2
2
/* bender-ckeditor-plugins: entities,enterkey */
3
3
4
- bender . editor = {
5
- config : {
6
- enterMode : CKEDITOR . ENTER_P ,
7
- allowedContent : true
4
+ ( function ( ) {
5
+ 'use strict' ;
6
+
7
+ var selectionTools = bender . tools . selection ,
8
+ matchOpts = {
9
+ compareSelection : true ,
10
+ normalizeSelection : true
11
+ } ;
12
+
13
+ function se ( editorName , htmlWithSeleciton , expectedHtmlWithSelection ) {
14
+ return function ( ) {
15
+ var editor = this . editors [ editorName ] ;
16
+
17
+ selectionTools . setWithHtml ( editor , htmlWithSeleciton ) ;
18
+ editor . execCommand ( 'shiftEnter' ) ;
19
+
20
+ var output = selectionTools . getWithHtml ( editor ) ;
21
+
22
+ assert . isInnerHtmlMatching ( expectedHtmlWithSelection , output , matchOpts ) ;
23
+ } ;
8
24
}
9
- } ;
10
-
11
- bender . test (
12
- {
13
- // #7912
14
- 'test enterkey after invisible element' : function ( ) {
15
- // IE restrain making selection in invisible element.
16
- if ( CKEDITOR . env . ie )
17
- assert . ignore ( ) ;
18
-
19
- var bot = this . editorBot ;
20
- bot . setHtmlWithSelection ( '<p>foo<span style="display:none;">bar^</span></p>' ) ;
21
- bot . execCommand ( 'enter' ) ;
22
- this . editor . insertText ( 'baz' ) ;
23
-
24
- var output = bender . tools . getHtmlWithSelection ( bot . editor ) ;
25
- output = bot . editor . dataProcessor . toDataFormat ( output ) ;
26
-
27
- var expected =
28
- CKEDITOR . env . safari ?
29
- '<p>foo</p><p>baz^<span style="display:none;">bar</span></p>' :
30
- '<p>foo<span style="display:none;">bar</span></p><p>baz^</p>' ;
31
-
32
- assert . areSame ( expected , bender . tools . fixHtml ( output ) ) ;
33
- } ,
34
-
35
- // #8321
36
- 'test enter at the end of block with inline styles' : function ( ) {
37
- var bot = this . editorBot ;
38
- bot . setHtmlWithSelection ( '<p><b><i>foo^</i></b></p>' ) ;
39
- bot . execCommand ( 'enter' ) ;
40
- bot . editor . insertText ( 'bar' ) ;
41
- assert . areSame ( '<p><b><i>foo</i></b></p><p><b><i>bar</i></b></p>' , bot . getData ( false , true ) ) ;
42
- } ,
43
-
44
- // #7946 TODO: Add editor doc quirks mode tests.
45
- 'test enter key scrolls document' : function ( ) {
46
- var bot = this . editorBot ;
47
-
48
- bot . editor . focus ( ) ;
49
- bot . setHtmlWithSelection ( '^' ) ;
50
-
51
- // Press enough enter key in order overflow the content area.
52
- var i = 0 ;
53
- while ( i ++ < 20 ) bot . execCommand ( 'enter' ) ;
54
- var start = bot . editor . getSelection ( ) . getStartElement ( ) ;
55
- var rect = start . $ . getBoundingClientRect ( ) ;
56
- var viewport = bot . editor . window . getViewPaneSize ( ) ;
57
-
58
- // Make sure the cursor is inside of viewport.
59
- assert . isTrue ( rect . top < viewport . height && rect . top > 0 ) ;
60
- } ,
61
-
62
- // Start of #8812
63
- 'test Enter key at the end of contents with comment' : function ( ) {
64
- var bot = this . editorBot ;
65
- bot . setHtmlWithSelection ( 'test ^<!-- --> ' ) ;
66
- bot . execCommand ( 'enter' ) ;
67
- assert . areSame ( '<p>test <!-- --></p><p> </p>' , bot . getData ( false , true ) ) ;
68
- } ,
69
-
70
- 'test Enter key in the middle of contents with comments' : function ( ) {
71
- var bot = this . editorBot ;
72
- bot . setHtmlWithSelection ( '<!-- baz -->foo^bar<!-- baz -->' ) ;
73
- bot . execCommand ( 'enter' ) ;
74
-
75
- // IE9+Compat looses the first comment, so we remove it from the assertion (not related to #8812).
76
- assert . areSame ( '<p>foo</p><p>bar</p>' , bot . getData ( false , true ) . replace ( / < ! [ ^ > ] + > / g, '' ) ) ;
77
- } ,
78
-
79
- 'test Enter key in the middle of contents with comments (2)' : function ( ) {
80
- var bot = this . editorBot ;
81
- bot . setHtmlWithSelection ( '<b>foo</b>bar^baz<!-- --><b>qux</b>' ) ;
82
- bot . execCommand ( 'enter' ) ;
83
-
84
- assert . areSame ( '<p><b>foo</b>bar</p><p>baz<!-- --><b>qux</b></p>' , bot . getData ( false , true ) ) ;
85
- } ,
86
- // End of #8812
87
-
88
- 'test Enter key uses editor.activeEnterMode' : function ( ) {
89
- bender . editorBot . create ( {
90
- name : 'test_enter_editor_enter_mode' ,
91
- config : {
92
- autoParagraph : false
25
+
26
+ bender . test ( {
27
+ _should : {
28
+ ignore : {
29
+ 'test shift+enter key - end of block, inside inline element followed by bogus br' : ! CKEDITOR . env . needsBrFiller ,
30
+ 'test shift+enter key - end of list item, inside inline element followed by bogus br' : ! CKEDITOR . env . needsBrFiller ,
93
31
}
94
- } , function ( bot ) {
32
+ } ,
33
+
34
+ 'async:init' : function ( ) {
35
+ var that = this ;
36
+
37
+ bender . tools . setUpEditors ( {
38
+ editor : {
39
+ name : 'editor1' ,
40
+ config : {
41
+ enterMode : CKEDITOR . ENTER_P ,
42
+ allowedContent : true
43
+ }
44
+ } ,
45
+
46
+ editorNoAutoParagraph : {
47
+ name : 'editor2' ,
48
+ config : {
49
+ autoParagraph : false
50
+ }
51
+ }
52
+ } , function ( editors , bots ) {
53
+ that . editorBots = bots ;
54
+ that . editors = editors ;
55
+ that . callback ( ) ;
56
+ } ) ;
57
+ } ,
58
+
59
+ // #7912
60
+ 'test enter key after invisible element' : function ( ) {
61
+ // IE restrain making selection in invisible element.
62
+ if ( CKEDITOR . env . ie )
63
+ assert . ignore ( ) ;
64
+
65
+ var bot = this . editorBots . editor ,
66
+ editor = bot . editor ;
67
+
68
+ bot . setHtmlWithSelection ( '<p>foo<span style="display:none;">bar^</span></p>' ) ;
69
+ bot . execCommand ( 'enter' ) ;
70
+ editor . insertText ( 'baz' ) ;
71
+
72
+ var output = bender . tools . getHtmlWithSelection ( editor ) ;
73
+ output = editor . dataProcessor . toDataFormat ( output ) ;
74
+
75
+ var expected =
76
+ CKEDITOR . env . safari ?
77
+ '<p>foo</p><p>baz^<span style="display:none;">bar</span></p>' :
78
+ '<p>foo<span style="display:none;">bar</span></p><p>baz^</p>' ;
79
+
80
+ assert . areSame ( expected , bender . tools . fixHtml ( output ) ) ;
81
+ } ,
82
+
83
+ // #8321
84
+ 'test enter key at the end of block with inline styles' : function ( ) {
85
+ var bot = this . editorBots . editor ,
86
+ editor = bot . editor ;
87
+
88
+ bot . setHtmlWithSelection ( '<p><b><i>foo^</i></b></p>' ) ;
89
+ bot . execCommand ( 'enter' ) ;
90
+ editor . insertText ( 'bar' ) ;
91
+ assert . areSame ( '<p><b><i>foo</i></b></p><p><b><i>bar</i></b></p>' , bot . getData ( false , true ) ) ;
92
+ } ,
93
+
94
+ // #7946 TODO: Add editor doc quirks mode tests.
95
+ 'test enter key key scrolls document' : function ( ) {
96
+ var bot = this . editorBots . editor ,
97
+ editor = bot . editor ;
98
+
99
+ editor . focus ( ) ;
100
+ bot . setHtmlWithSelection ( '^' ) ;
101
+
102
+ // Press enough enter key in order overflow the content area.
103
+ var i = 0 ;
104
+ while ( i ++ < 20 ) bot . execCommand ( 'enter' ) ;
105
+ var start = editor . getSelection ( ) . getStartElement ( ) ;
106
+ var rect = start . $ . getBoundingClientRect ( ) ;
107
+ var viewport = bot . editor . window . getViewPaneSize ( ) ;
108
+
109
+ // Make sure the cursor is inside of viewport.
110
+ assert . isTrue ( rect . top < viewport . height && rect . top > 0 ) ;
111
+ } ,
112
+
113
+ // Start of #8812
114
+ 'test ener key at the end of contents with comment' : function ( ) {
115
+ var bot = this . editorBots . editor ;
116
+
117
+ bot . setHtmlWithSelection ( 'test ^<!-- --> ' ) ;
118
+ bot . execCommand ( 'enter' ) ;
119
+ assert . areSame ( '<p>test <!-- --></p><p> </p>' , bot . getData ( false , true ) ) ;
120
+ } ,
121
+
122
+ 'test enter key in the middle of contents with comments' : function ( ) {
123
+ var bot = this . editorBots . editor ;
124
+
125
+ bot . setHtmlWithSelection ( '<!-- baz -->foo^bar<!-- baz -->' ) ;
126
+ bot . execCommand ( 'enter' ) ;
127
+
128
+ // IE9+Compat looses the first comment, so we remove it from the assertion (not related to #8812).
129
+ assert . areSame ( '<p>foo</p><p>bar</p>' , bot . getData ( false , true ) . replace ( / < ! [ ^ > ] + > / g, '' ) ) ;
130
+ } ,
131
+
132
+ 'test enter key in the middle of contents with comments (2)' : function ( ) {
133
+ var bot = this . editorBots . editor ;
134
+
135
+ bot . setHtmlWithSelection ( '<b>foo</b>bar^baz<!-- --><b>qux</b>' ) ;
136
+ bot . execCommand ( 'enter' ) ;
137
+
138
+ assert . areSame ( '<p><b>foo</b>bar</p><p>baz<!-- --><b>qux</b></p>' , bot . getData ( false , true ) ) ;
139
+ } ,
140
+ // End of #8812
141
+
142
+ 'test enter key uses editor.activeEnterMode' : function ( ) {
143
+ var bot = this . editorBots . editorNoAutoParagraph ;
144
+
95
145
bot . editor . setActiveEnterMode ( CKEDITOR . ENTER_BR , CKEDITOR . ENTER_DIV ) ;
96
146
97
147
try {
@@ -112,16 +162,11 @@ bender.test(
112
162
bot . setHtmlWithSelection ( 'foo^bar' ) ;
113
163
bot . execCommand ( 'enter' ) ;
114
164
assert . areSame ( '<p>foo</p><p>bar</p>' , bot . getData ( ) , 'main mode was used' ) ;
115
- } ) ;
116
- } ,
117
-
118
- 'test Enter key is influenced by the active filter' : function ( ) {
119
- bender . editorBot . create ( {
120
- name : 'test_enter_active_filter' ,
121
- config : {
122
- autoParagraph : false
123
- }
124
- } , function ( bot ) {
165
+ } ,
166
+
167
+ 'test enter key is influenced by the active filter' : function ( ) {
168
+ var bot = this . editorBots . editorNoAutoParagraph ;
169
+
125
170
bot . setHtmlWithSelection ( 'foo^bar' ) ;
126
171
127
172
var filter = new CKEDITOR . filter ( 'div' ) ;
@@ -140,27 +185,40 @@ bender.test(
140
185
bot . setHtmlWithSelection ( 'foo^bar' ) ;
141
186
bot . execCommand ( 'enter' ) ;
142
187
assert . areSame ( '<p>foo</p><p>bar</p>' , bot . getData ( ) , 'main mode was used' ) ;
143
- } ) ;
144
- } ,
188
+ } ,
145
189
146
- /*
147
- // Commented out until we decide whether we want to block enter key completely and how.
148
- 'test Enter key is completely blocked if neither p nor br are allowed': function() {
149
- var bot = this.editorBot;
150
- bot.setHtmlWithSelection( '<p>foo^bar</p>' );
190
+ /*
191
+ // Commented out until we decide whether we want to block enter key completely and how.
192
+ 'test enter key is completely blocked if neither p nor br are allowed': function() {
193
+ var bot = this.editorBot;
194
+ bot.setHtmlWithSelection( '<p>foo^bar</p>' );
151
195
152
- var filter = new CKEDITOR.filter( 'x' );
153
- this.editor.setActiveFilter( filter );
196
+ var filter = new CKEDITOR.filter( 'x' );
197
+ this.editor.setActiveFilter( filter );
154
198
155
- try {
156
- bot.execCommand( 'enter' );
157
- assert.areSame( '<p>foobar</p>', bot.getData(), 'enter is blocked' );
158
- } catch ( e ) {
159
- throw e;
160
- } finally {
161
- // Always reset filter - even if previous test failed.
162
- this.editor.setActiveFilter( null );
163
- }
164
- }
165
- */
166
- } ) ;
199
+ try {
200
+ bot.execCommand( 'enter' );
201
+ assert.areSame( '<p>foobar</p>', bot.getData(), 'enter is blocked' );
202
+ } catch ( e ) {
203
+ throw e;
204
+ } finally {
205
+ // Always reset filter - even if previous test failed.
206
+ this.editor.setActiveFilter( null );
207
+ }
208
+ },
209
+ */
210
+
211
+ 'test shift+enter key - middle of block' : se ( 'editor' , '<p>foo{}bar</p>' , '<p>foo<br />^bar@</p>' ) ,
212
+ 'test shift+enter key - list item' : se ( 'editor' , '<ul><li>foo{}bar</li></ul>' , '<ul><li>foo<br />^bar@</li></ul>' ) ,
213
+ 'test shift+enter key - start of block' : se ( 'editor' , '<p>{}foobar</p>' , '<p><br />^foobar@</p>' ) ,
214
+ 'test shift+enter key - end of block' : se ( 'editor' , '<p>foobar{}</p>' , '<p>foobar<br />^@</p>' ) ,
215
+ 'test shift+enter key - before br' : se ( 'editor' , '<p>foo{}<br />bar</p>' , '<p>foo<br />^<br />bar@</p>' ) ,
216
+ 'test shift+enter key - after br' : se ( 'editor' , '<p>foo<br />{}bar</p>' , '<p>foo<br /><br />^bar@</p>' ) ,
217
+ // #11947
218
+ 'test shift+enter key - end of block, inside inline element followed by bogus br' :
219
+ se ( 'editor' , '<p><em>foo{}</em><br /></p>' , '<p><em>foo<br />^</em><br /></p>' ) ,
220
+ 'test shift+enter key - end of list item, inside inline element followed by bogus br' :
221
+ se ( 'editor' , '<ul><li><em>foo{}</em><br /></li></ul>' , '<ul><li><em>foo<br />^</em><br /></li></ul>' ) ,
222
+ } ) ;
223
+
224
+ } ) ( ) ;
0 commit comments