| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals describe, it, expect, beforeEach, sinon, document */
- 'use strict';
- var modules = bender.amd.require( 'editor', 'editorconfig', 'plugin', 'promise' );
- var editor;
- var element;
- beforeEach( function() {
- var Editor = modules.editor;
- element = document.createElement( 'div' );
- document.body.appendChild( element );
- editor = new Editor( element );
- } );
- // Define fake plugins to be used in tests.
- CKEDITOR.define( 'plugin!A', [ 'plugin' ], function() {
- return modules.plugin.extend( {
- init: sinon.spy().named( 'A' )
- } );
- } );
- CKEDITOR.define( 'plugin!B', [ 'plugin' ], function() {
- return modules.plugin.extend( {
- init: sinon.spy().named( 'B' )
- } );
- } );
- CKEDITOR.define( 'plugin!C', [ 'plugin', 'plugin!B' ], function() {
- return modules.plugin.extend( {
- init: sinon.spy().named( 'C' )
- } );
- } );
- CKEDITOR.define( 'plugin!D', [ 'plugin', 'plugin!C' ], function() {
- return modules.plugin.extend( {
- init: sinon.spy().named( 'D' )
- } );
- } );
- ///////////////////
- describe( 'constructor', function() {
- it( 'should create a new editor instance', function() {
- expect( editor ).to.have.property( 'element' ).to.equal( element );
- } );
- } );
- describe( 'config', function() {
- it( 'should be an instance of EditorConfig', function() {
- var EditorConfig = modules.editorconfig;
- expect( editor.config ).to.be.an.instanceof( EditorConfig );
- } );
- } );
- describe( 'init', function() {
- it( 'should return a promise that resolves properly', function() {
- var Promise = modules.promise;
- var promise = editor.init();
- expect( promise ).to.be.an.instanceof( Promise );
- return promise;
- } );
- it( 'should return the same promise for sucessive calls', function() {
- var promise = editor.init();
- expect( editor.init() ).to.equal( promise );
- } );
- it( 'should fill `plugins`', function() {
- var Editor = modules.editor;
- var Plugin = modules.plugin;
- editor = new Editor( element, {
- plugins: 'A,B'
- } );
- expect( editor.plugins.length ).to.equal( 0 );
- return editor.init().then( function() {
- expect( editor.plugins.length ).to.equal( 2 );
- expect( editor.plugins.get( 'A' ) ).to.be.an.instanceof( Plugin );
- expect( editor.plugins.get( 'B' ) ).to.be.an.instanceof( Plugin );
- } );
- } );
- it( 'should initialize plugins in the right order', function() {
- var Editor = modules.editor;
- editor = new Editor( element, {
- plugins: 'A,D'
- } );
- return editor.init().then( function() {
- sinon.assert.callOrder(
- editor.plugins.get( 'A' ).init,
- editor.plugins.get( 'B' ).init,
- editor.plugins.get( 'C' ).init,
- editor.plugins.get( 'D' ).init
- );
- } );
- } );
- } );
- describe( 'plugins', function() {
- it( 'should be empty on new editor', function() {
- expect( editor.plugins.length ).to.equal( 0 );
- } );
- } );
- describe( 'destroy', function() {
- it( 'should fire "destroy"', function() {
- var spy = sinon.spy();
- editor.on( 'destroy', spy );
- editor.destroy();
- sinon.assert.called( spy );
- } );
- it( 'should delete the "element" property', function() {
- editor.destroy();
- expect( editor ).to.not.have.property( 'element' );
- } );
- } );
|