| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: creator */
- 'use strict';
- import Editor from '/ckeditor5/editor.js';
- import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
- import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/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 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 );
- } );
- it( 'calls _replaceElement', () => {
- const spy = testUtils.sinon.spy( creator, '_replaceElement' );
- 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;
- } );
- } );
- 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;
- } );
- } );
- it( 'calls loadDataFromEditorElement', () => {
- const spy = testUtils.sinon.spy( creator, 'loadDataFromEditorElement' );
- return creator.create().then( () => {
- expect( spy.calledOnce ).to.be.true;
- } );
- } );
- } );
- 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' );
- return creator.create().then( () => {
- return creator.destroy().then( () => {
- expect( spy.calledOnce ).to.be.true;
- } );
- } );
- } );
- it( 'destroys the UI', () => {
- return creator.create().then( () => {
- return creator.destroy().then( () => {
- expect( editor.ui.collections ).to.be.null;
- } );
- } );
- } );
- } );
- describe( '_createToolbar', () => {
- it( 'creates toolbar using StickyToolbar and StickyToolbarView', () => {
- return creator.create().then( () => {
- expect( editor.ui.collections.get( 'top' ) ).to.have.length( 1 );
- const toolbar = editor.ui.collections.get( 'top' ).get( 0 );
- expect( toolbar ).to.be.instanceof( StickyToolbar );
- expect( toolbar.view ).to.be.instanceof( StickyToolbarView );
- } );
- } );
- } );
- } );
|