|
@@ -3,47 +3,183 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/* global console:false */
|
|
|
|
|
|
|
+/* bender-tags: creator */
|
|
|
|
|
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
-import CKEDITOR from '/ckeditor.js';
|
|
|
|
|
|
|
+import Editor from '/ckeditor5/editor.js';
|
|
|
|
|
+
|
|
|
|
|
+import BoxedEditorUI from '/ckeditor5/ui/boxededitorui/boxededitorui.js';
|
|
|
|
|
+import BoxedEditorUIView from '/ckeditor5/ui/boxededitorui/boxededitoruiview.js';
|
|
|
|
|
+
|
|
|
|
|
+import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
|
|
|
|
|
+import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
|
|
|
|
|
+
|
|
|
|
|
+import StickyToolbar from '/ckeditor5/ui/bindings/stickytoolbar.js';
|
|
|
|
|
+import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
|
|
|
|
|
+
|
|
|
|
|
+import StandardCreator from '/ckeditor5/creator/standardcreator.js';
|
|
|
import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
|
|
import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
|
|
|
-import testUtils from '/tests/utils/_utils/utils.js';
|
|
|
|
|
|
|
+import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
|
|
|
|
|
+
|
|
|
|
|
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
|
|
|
|
|
+
|
|
|
|
|
+testUtils.createSinonSandbox();
|
|
|
|
|
+
|
|
|
|
|
+describe( 'ClassicCreator', () => {
|
|
|
|
|
+ let creator, editor, fooElement, barElement;
|
|
|
|
|
+
|
|
|
|
|
+ beforeEach( function() {
|
|
|
|
|
+ fooElement = document.createElement( 'div' );
|
|
|
|
|
+ fooElement.setAttribute( 'class', 'first' );
|
|
|
|
|
+ fooElement.setAttribute( 'data-test', this.currentTest.title );
|
|
|
|
|
+
|
|
|
|
|
+ document.body.appendChild( fooElement );
|
|
|
|
|
+
|
|
|
|
|
+ barElement = document.createElement( 'div' );
|
|
|
|
|
+ barElement.setAttribute( 'class', 'second' );
|
|
|
|
|
+ barElement.setAttribute( 'data-test', this.currentTest.title );
|
|
|
|
|
+
|
|
|
|
|
+ document.body.appendChild( barElement );
|
|
|
|
|
+
|
|
|
|
|
+ editor = new Editor(
|
|
|
|
|
+ {
|
|
|
|
|
+ foo: fooElement,
|
|
|
|
|
+ bar: barElement
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ toolbar: [ 'bold', 'italic' ]
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ creator = new ClassicCreator( editor, new HtmlDataProcessor() );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'constructor', () => {
|
|
|
|
|
+ it( 'inherits from the StandardCreator', () => {
|
|
|
|
|
+ expect( creator ).to.be.instanceof( StandardCreator );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'creates a single instance of Editable ', () => {
|
|
|
|
|
+ expect( editor.editables ).to.have.length( 1 );
|
|
|
|
|
+ expect( editor.editables.get( 0 ).name ).to.equal( 'foo' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'creates the UI using BoxedEditorUI classes', () => {
|
|
|
|
|
+ expect( editor.ui ).to.be.instanceof( BoxedEditorUI );
|
|
|
|
|
+ expect( editor.ui.view ).to.be.instanceof( BoxedEditorUIView );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'creates a single document root', () => {
|
|
|
|
|
+ expect( editor.document.rootNames ).to.have.members( [ 'foo' ] );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'create', () => {
|
|
|
|
|
+ it( 'returns a promise', () => {
|
|
|
|
|
+ expect( creator.create() ).to.be.instanceof( Promise );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
-let editor, editable, observer;
|
|
|
|
|
|
|
+ it( 'calls _replaceElement', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( creator, '_replaceElement' );
|
|
|
|
|
|
|
|
-function initEditor() {
|
|
|
|
|
- CKEDITOR.create( '#editor', {
|
|
|
|
|
- creator: ClassicCreator,
|
|
|
|
|
- toolbar: [ 'bold', 'italic' ]
|
|
|
|
|
- } )
|
|
|
|
|
- .then( ( newEditor ) => {
|
|
|
|
|
- console.log( 'Editor was initialized', newEditor );
|
|
|
|
|
- console.log( 'You can now play with it using global `editor` and `editable` variables.' );
|
|
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'calls _createToolbar', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( creator, '_createToolbar' );
|
|
|
|
|
+
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- window.editor = editor = newEditor;
|
|
|
|
|
- window.editable = editable = editor.editables.get( 0 );
|
|
|
|
|
|
|
+ it( 'creates the editable using EditableUI Controller in main region', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( editor.ui.collections.get( 'main' ) ).to.have.length( 1 );
|
|
|
|
|
+ expect( editor.ui.collections.get( 'main' ).get( 0 ) ).to.be.instanceof( EditableUI );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'creates the editable using InlineEditableUIView in main region', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( editor.ui.collections.get( 'main' ).get( 0 ).view ).to.be.instanceof( InlineEditableUIView );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'binds the editable to InlineEditableUIView', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ const editableUIView = editor.ui.collections.get( 'main' ).get( 0 ).view;
|
|
|
|
|
+
|
|
|
|
|
+ expect( editor.editables.get( 0 ).domElement ).to.equal( editableUIView.element );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'initializes the editor.ui', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( editor.ui, 'init' );
|
|
|
|
|
+
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- observer = testUtils.createObserver();
|
|
|
|
|
- observer.observe( 'Editable', editable );
|
|
|
|
|
|
|
+ it( 'calls loadDataFromEditorElement', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( creator, 'loadDataFromEditorElement' );
|
|
|
|
|
+
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-function destroyEditor() {
|
|
|
|
|
- editor.destroy()
|
|
|
|
|
- .then( () => {
|
|
|
|
|
- window.editor = editor = null;
|
|
|
|
|
- window.editable = editable = null;
|
|
|
|
|
|
|
+ describe( 'destroy', () => {
|
|
|
|
|
+ it( 'returns a promise', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( creator.destroy() ).to.be.instanceof( Promise );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'destroys parent class', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( StandardCreator.prototype, 'destroy' );
|
|
|
|
|
+
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ return creator.destroy().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'calls updateEditorElement', () => {
|
|
|
|
|
+ const spy = testUtils.sinon.spy( creator, 'updateEditorElement' );
|
|
|
|
|
|
|
|
- observer.stopListening();
|
|
|
|
|
- observer = null;
|
|
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ return creator.destroy().then( () => {
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- console.log( 'Editor was destroyed' );
|
|
|
|
|
|
|
+ it( 'destroys the UI', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ return creator.destroy().then( () => {
|
|
|
|
|
+ expect( editor.ui.collections ).to.be.null;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
-}
|
|
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
-document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
|
|
|
|
|
-document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
|
|
|
|
|
|
|
+ describe( '_createToolbar', () => {
|
|
|
|
|
+ it( 'creates toolbar using StickyToolbar and StickyToolbarView', () => {
|
|
|
|
|
+ return creator.create().then( () => {
|
|
|
|
|
+ expect( editor.ui.collections.get( 'top' ) ).to.have.length( 1 );
|
|
|
|
|
|
|
|
-initEditor();
|
|
|
|
|
|
|
+ const toolbar = editor.ui.collections.get( 'top' ).get( 0 );
|
|
|
|
|
+
|
|
|
|
|
+ expect( toolbar ).to.be.instanceof( StickyToolbar );
|
|
|
|
|
+ expect( toolbar.view ).to.be.instanceof( StickyToolbarView );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+} );
|