/** * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ /* globals document */ import DecoupledDocumentEditor from '../src/ckeditor'; import DecoupledEditor from '@ckeditor/ckeditor5-editor-decoupled/src/decouplededitor'; describe( 'DecoupledDocumentEditor build', () => { let editor, editorData, editorElement; beforeEach( () => { editorData = '
foo bar
'; editorElement = document.createElement( 'div' ); editorElement.innerHTML = editorData; document.body.appendChild( editorElement ); } ); afterEach( () => { editorElement.remove(); editor = null; } ); describe( 'buid', () => { it( 'contains plugins', () => { expect( DecoupledDocumentEditor.build.plugins ).to.not.be.empty; } ); it( 'contains config', () => { expect( DecoupledDocumentEditor.build.config.toolbar ).to.not.be.empty; } ); } ); describe( 'editor with data', () => { test( () => editorData ); it( 'does not define the UI DOM structure', () => { return DecoupledDocumentEditor.create( editorData ) .then( newEditor => { expect( newEditor.ui.view.element ).to.be.null; expect( newEditor.ui.view.toolbar.element.parentElement ).to.be.null; expect( newEditor.ui.view.editable.element.parentElement ).to.be.null; } ); } ); } ); describe( 'editor with editable element', () => { test( () => editorElement ); it( 'uses the provided editable element', () => { return DecoupledDocumentEditor.create( editorElement ) .then( newEditor => { expect( newEditor.ui.view.editable.element.parentElement ).to.equal( document.body ); } ); } ); } ); function test( getEditorDataOrElement ) { describe( 'create()', () => { beforeEach( () => { return DecoupledDocumentEditor.create( getEditorDataOrElement() ) .then( newEditor => { editor = newEditor; } ); } ); afterEach( () => { return editor.destroy(); } ); it( 'creates an instance which inherits from the DecoupledDocumentEditor', () => { expect( editor ).to.be.instanceof( DecoupledDocumentEditor ); expect( editor ).to.be.instanceof( DecoupledEditor ); } ); it( 'loads passed data', () => { expect( editor.getData() ).to.equal( 'foo bar
' ); } ); } ); describe( 'destroy()', () => { beforeEach( () => { return DecoupledDocumentEditor.create( getEditorDataOrElement() ) .then( newEditor => { editor = newEditor; } ); } ); } ); describe( 'plugins', () => { beforeEach( () => { return DecoupledDocumentEditor.create( getEditorDataOrElement() ) .then( newEditor => { editor = newEditor; } ); } ); afterEach( () => { return editor.destroy(); } ); it( 'paragraph works', () => { const data = 'Some text inside a paragraph.
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'basic-styles work', () => { const data = [ '',
'Test:strong',
'Test:i',
'Test:u',
'Test:s',
'
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'heading works', () => { const data = [ 'Quote

foo
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'font family works', () => { const data = 'foo
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'highlight works', () => { const data = 'foo
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'alignment works', () => { const data = 'foo
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); } ); describe( 'config', () => { afterEach( () => { return editor.destroy(); } ); // https://github.com/ckeditor/ckeditor5/issues/572 it( 'allows configure toolbar items through config.toolbar', () => { return DecoupledDocumentEditor .create( getEditorDataOrElement(), { toolbar: [ 'bold' ] } ) .then( newEditor => { editor = newEditor; expect( editor.ui.view.toolbar.items.length ).to.equal( 1 ); } ); } ); } ); } } );