|
3 | 3 | * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license |
4 | 4 | */ |
5 | 5 |
|
6 | | -/* globals document, Event */ |
| 6 | +/* globals document */ |
7 | 7 |
|
8 | 8 | import InlineEditorUI from '../src/inlineeditorui'; |
9 | 9 | import InlineEditorUIView from '../src/inlineeditoruiview'; |
@@ -68,37 +68,6 @@ describe( 'InlineEditor', () => { |
68 | 68 | expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement ); |
69 | 69 | } ); |
70 | 70 |
|
71 | | - it( 'handles form element', () => { |
72 | | - const form = document.createElement( 'form' ); |
73 | | - const textarea = document.createElement( 'textarea' ); |
74 | | - form.appendChild( textarea ); |
75 | | - document.body.appendChild( form ); |
76 | | - |
77 | | - // Prevents page realods in Firefox ;| |
78 | | - form.addEventListener( 'submit', evt => { |
79 | | - evt.preventDefault(); |
80 | | - } ); |
81 | | - |
82 | | - return InlineEditor.create( textarea, { |
83 | | - plugins: [ Paragraph ] |
84 | | - } ).then( editor => { |
85 | | - expect( textarea.value ).to.equal( '' ); |
86 | | - |
87 | | - editor.setData( '<p>Foo</p>' ); |
88 | | - |
89 | | - form.dispatchEvent( new Event( 'submit', { |
90 | | - // We need to be able to do preventDefault() to prevent page reloads in Firefox. |
91 | | - cancelable: true |
92 | | - } ) ); |
93 | | - |
94 | | - expect( textarea.value ).to.equal( '<p>Foo</p>' ); |
95 | | - |
96 | | - return editor.destroy().then( () => { |
97 | | - form.remove(); |
98 | | - } ); |
99 | | - } ); |
100 | | - } ); |
101 | | - |
102 | 71 | it( 'should have undefined the #sourceElement if editor was initialized with data', () => { |
103 | 72 | return InlineEditor.create( '<p>Hello world!</p>', { |
104 | 73 | plugins: [ Paragraph ] |
@@ -185,9 +154,19 @@ describe( 'InlineEditor', () => { |
185 | 154 | InlineEditor.create( '<p>Hello world!</p>', { |
186 | 155 | initialData: '<p>I am evil!</p>', |
187 | 156 | plugins: [ Paragraph ] |
188 | | - } ).catch( () => { |
189 | | - done(); |
190 | | - } ); |
| 157 | + } ) |
| 158 | + .then( |
| 159 | + () => { |
| 160 | + expect.fail( 'Inline editor should throw an error when both initial data are passed' ); |
| 161 | + }, |
| 162 | + err => { |
| 163 | + expect( err ).to.be.an( 'error' ).with.property( 'message' ).and |
| 164 | + // eslint-disable-next-line max-len |
| 165 | + .match( /^editor-create-initial-data: The config\.initialData option cannot be used together with initial data passed in Editor\.create\(\)\./ ); |
| 166 | + } |
| 167 | + ) |
| 168 | + .then( done ) |
| 169 | + .catch( done ); |
191 | 170 | } ); |
192 | 171 |
|
193 | 172 | // #25 |
@@ -216,6 +195,21 @@ describe( 'InlineEditor', () => { |
216 | 195 | return newEditor.destroy(); |
217 | 196 | } ); |
218 | 197 | } ); |
| 198 | + |
| 199 | + it( 'throws an error when is initialized in textarea', done => { |
| 200 | + InlineEditor.create( document.createElement( 'textarea' ) ) |
| 201 | + .then( |
| 202 | + () => { |
| 203 | + expect.fail( 'Inline editor should throw an error when is initialized in textarea.' ); |
| 204 | + }, |
| 205 | + err => { |
| 206 | + expect( err ).to.be.an( 'error' ).with.property( 'message' ).and |
| 207 | + .match( /^editor-wrong-element: This type of editor cannot be initialized inside <textarea> element\./ ); |
| 208 | + } |
| 209 | + ) |
| 210 | + .then( done ) |
| 211 | + .catch( done ); |
| 212 | + } ); |
219 | 213 | } ); |
220 | 214 |
|
221 | 215 | describe( 'create - events', () => { |
|
0 commit comments