Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge e5cfec1 into 05cd917
Browse files Browse the repository at this point in the history
  • Loading branch information
msamsel committed May 16, 2019
2 parents 05cd917 + e5cfec1 commit 9db6fd1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/inlineeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export default class InlineEditor extends Editor {
*/
static create( sourceElementOrData, config = {} ) {
return new Promise( resolve => {
Editor._assertAllowedSourceElement( sourceElementOrData );

const editor = new this( sourceElementOrData, config );

resolve(
Expand Down
64 changes: 29 additions & 35 deletions tests/inlineeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals document, Event */
/* globals document */

import InlineEditorUI from '../src/inlineeditorui';
import InlineEditorUIView from '../src/inlineeditoruiview';
Expand Down Expand Up @@ -68,37 +68,6 @@ describe( 'InlineEditor', () => {
expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );
} );

it( 'handles form element', () => {
const form = document.createElement( 'form' );
const textarea = document.createElement( 'textarea' );
form.appendChild( textarea );
document.body.appendChild( form );

// Prevents page realods in Firefox ;|
form.addEventListener( 'submit', evt => {
evt.preventDefault();
} );

return InlineEditor.create( textarea, {
plugins: [ Paragraph ]
} ).then( editor => {
expect( textarea.value ).to.equal( '' );

editor.setData( '<p>Foo</p>' );

form.dispatchEvent( new Event( 'submit', {
// We need to be able to do preventDefault() to prevent page reloads in Firefox.
cancelable: true
} ) );

expect( textarea.value ).to.equal( '<p>Foo</p>' );

return editor.destroy().then( () => {
form.remove();
} );
} );
} );

it( 'should have undefined the #sourceElement if editor was initialized with data', () => {
return InlineEditor.create( '<p>Hello world!</p>', {
plugins: [ Paragraph ]
Expand Down Expand Up @@ -185,9 +154,19 @@ describe( 'InlineEditor', () => {
InlineEditor.create( '<p>Hello world!</p>', {
initialData: '<p>I am evil!</p>',
plugins: [ Paragraph ]
} ).catch( () => {
done();
} );
} )
.then(
() => {
expect.fail( 'Inline editor should throw an error when both initial data are passed' );
},
err => {
expect( err ).to.be.an( 'error' ).with.property( 'message' ).and
// eslint-disable-next-line max-len
.match( /^editor-create-initial-data: The config\.initialData option cannot be used together with initial data passed in Editor\.create\(\)\./ );
}
)
.then( done )
.catch( done );
} );

// #25
Expand Down Expand Up @@ -216,6 +195,21 @@ describe( 'InlineEditor', () => {
return newEditor.destroy();
} );
} );

it( 'throws an error when is initialized in textarea', done => {
InlineEditor.create( document.createElement( 'textarea' ) )
.then(
() => {
expect.fail( 'Inline editor should throw an error when is initialized in textarea.' );
},
err => {
expect( err ).to.be.an( 'error' ).with.property( 'message' ).and
.match( /^editor-wrong-element: This type of editor cannot be initialized inside <textarea> element\./ );
}
)
.then( done )
.catch( done );
} );
} );

describe( 'create - events', () => {
Expand Down

0 comments on commit 9db6fd1

Please sign in to comment.