/** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ /* globals describe, it, expect, before, beforeEach, sinon, document */ 'use strict'; var modules = bender.amd.require( 'editor', 'editorconfig', 'plugin', 'promise' ); var editor; var element; var PluginA, PluginB; before( function() { var Plugin = modules.plugin; PluginA = Plugin.extend(); PluginB = Plugin.extend(); } ); beforeEach( function() { var Editor = modules.editor; element = document.createElement( 'div' ); document.body.appendChild( element ); editor = new Editor( element ); } ); // Define two fake plugins to be used in tests. CKEDITOR.define( 'plugin!A', [ 'plugin' ], function() { return PluginA; } ); CKEDITOR.define( 'plugin!B', [ 'plugin' ], function() { return PluginB; } ); /////////////////// 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 ); } ); } ); describe( 'plugins', function() { it( 'should be empty on new editor', function() { expect( editor.plugins.length ).to.equal( 0 ); } ); it( 'should be filled on `init()`', 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 ); } ); } ); } ); 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' ); } ); } );