editor.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals describe, it, expect, before, beforeEach, sinon, document */
  6. 'use strict';
  7. var modules = bender.amd.require( 'editor', 'editorconfig', 'plugin', 'promise' );
  8. var editor;
  9. var element;
  10. var PluginA, PluginB;
  11. before( function() {
  12. var Plugin = modules.plugin;
  13. PluginA = Plugin.extend();
  14. PluginB = Plugin.extend();
  15. } );
  16. beforeEach( function() {
  17. var Editor = modules.editor;
  18. element = document.createElement( 'div' );
  19. document.body.appendChild( element );
  20. editor = new Editor( element );
  21. } );
  22. // Define two fake plugins to be used in tests.
  23. CKEDITOR.define( 'plugin!A', [ 'plugin' ], function() {
  24. return PluginA;
  25. } );
  26. CKEDITOR.define( 'plugin!B', [ 'plugin' ], function() {
  27. return PluginB;
  28. } );
  29. ///////////////////
  30. describe( 'constructor', function() {
  31. it( 'should create a new editor instance', function() {
  32. expect( editor ).to.have.property( 'element' ).to.equal( element );
  33. } );
  34. } );
  35. describe( 'config', function() {
  36. it( 'should be an instance of EditorConfig', function() {
  37. var EditorConfig = modules.editorconfig;
  38. expect( editor.config ).to.be.an.instanceof( EditorConfig );
  39. } );
  40. } );
  41. describe( 'init', function() {
  42. it( 'should return a promise that resolves properly', function() {
  43. var Promise = modules.promise;
  44. var promise = editor.init();
  45. expect( promise ).to.be.an.instanceof( Promise );
  46. return promise;
  47. } );
  48. it( 'should return the same promise for sucessive calls', function() {
  49. var promise = editor.init();
  50. expect( editor.init() ).to.equal( promise );
  51. } );
  52. } );
  53. describe( 'plugins', function() {
  54. it( 'should be empty on new editor', function() {
  55. expect( editor.plugins.length ).to.equal( 0 );
  56. } );
  57. it( 'should be filled on `init()`', function() {
  58. var Editor = modules.editor;
  59. var Plugin = modules.plugin;
  60. editor = new Editor( element, {
  61. plugins: 'A,B'
  62. } );
  63. expect( editor.plugins.length ).to.equal( 0 );
  64. return editor.init().then( function() {
  65. expect( editor.plugins.length ).to.equal( 2 );
  66. expect( editor.plugins.get( 'A' ) ).to.be.an.instanceof( Plugin );
  67. expect( editor.plugins.get( 'B' ) ).to.be.an.instanceof( Plugin );
  68. } );
  69. } );
  70. } );
  71. describe( 'destroy', function() {
  72. it( 'should fire "destroy"', function() {
  73. var spy = sinon.spy();
  74. editor.on( 'destroy', spy );
  75. editor.destroy();
  76. sinon.assert.called( spy );
  77. } );
  78. it( 'should delete the "element" property', function() {
  79. editor.destroy();
  80. expect( editor ).to.not.have.property( 'element' );
  81. } );
  82. } );