/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /* globals document */ import ClassicEditor from '../src/ckeditor'; import BaseClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory'; describe( 'ClassicEditor build', () => { let editor, editorElement; beforeEach( () => { editorElement = document.createElement( 'div' ); editorElement.innerHTML = '

foo bar

'; document.body.appendChild( editorElement ); } ); afterEach( () => { editorElement.remove(); editor = null; } ); describe( 'build', () => { it( 'contains plugins', () => { expect( ClassicEditor.builtinPlugins ).to.not.be.empty; } ); it( 'contains config', () => { expect( ClassicEditor.defaultConfig.toolbar ).to.not.be.empty; } ); } ); describe( 'create()', () => { beforeEach( () => { return ClassicEditor.create( editorElement ) .then( newEditor => { editor = newEditor; } ); } ); afterEach( () => { return editor.destroy(); } ); it( 'creates an instance which inherits from the ClassicEditor', () => { expect( editor ).to.be.instanceof( ClassicEditor ); expect( editor ).to.be.instanceof( BaseClassicEditor ); } ); it( 'loads data from the editor element', () => { expect( editor.getData() ).to.equal( '

foo bar

' ); } ); } ); describe( 'destroy()', () => { beforeEach( () => { return ClassicEditor.create( editorElement ) .then( newEditor => { editor = newEditor; } ); } ); it( 'sets the data back to the editor element', () => { editor.setData( '

foo

' ); return editor.destroy() .then( () => { expect( editorElement.innerHTML ).to.equal( '

foo

' ); } ); } ); it( 'restores the editor element', () => { expect( editor.sourceElement.style.display ).to.equal( 'none' ); return editor.destroy() .then( () => { expect( editor.sourceElement.style.display ).to.equal( '' ); } ); } ); } ); describe( 'plugins', () => { beforeEach( () => { return ClassicEditor.create( editorElement ) .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', '

' ].join( '' ); editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'block-quote works', () => { const data = '

Quote

'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'heading works', () => { const data = [ '

Heading 1.

', '

Heading 1.1

', '

Heading 1.1.1

', '

Heading 1.1.2

', '

Heading 1.2

', '

Heading 1.2.1

', '

Heading 2

' ].join( '' ); editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'image works', () => { const data = '
'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'list works', () => { const data = [ '', '
    ', '
  1. Item 1.
  2. ', '
  3. Item 2.
  4. ', '
' ].join( '' ); editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); it( 'link works', () => { const data = '

CKEditor.com

'; editor.setData( data ); expect( editor.getData() ).to.equal( data ); } ); } ); describe( 'config', () => { afterEach( () => { return editor.destroy(); } ); // https://github.com/ckeditor/ckeditor5/issues/572 it( 'allows configuring toolbar items through config.toolbar', () => { return ClassicEditor .create( editorElement, { toolbar: [ 'bold' ] } ) .then( newEditor => { editor = newEditor; expect( editor.ui.view.toolbar.items.length ).to.equal( 1 ); } ); } ); // https://github.com/ckeditor/ckeditor5/issues/572 it( 'allows configuring toolbar offset without overriding toolbar items', () => { return ClassicEditor .create( editorElement, { toolbar: { viewportTopOffset: 42 } } ) .then( newEditor => { editor = newEditor; expect( editor.ui.view.toolbar.items.length ).to.equal( 17 ); expect( editor.ui.view.stickyPanel.viewportTopOffset ).to.equal( 42 ); } ); } ); } ); describeMemoryUsage( () => { testMemoryUsage( 'should not grow on multiple create/destroy', () => ClassicEditor.create( document.querySelector( '#mem-editor' ) ) ); } ); } );