ckeditor.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. /* bender-include: ../_tools/tools.js */
  7. 'use strict';
  8. var modules = bender.amd.require( 'ckeditor', 'editor', 'promise', 'config' );
  9. var content = document.getElementById( 'content' );
  10. var editorConfig = { plugins: 'creator-test' };
  11. before( function() {
  12. bender.tools.core.defineEditorCreatorMock( 'test' );
  13. } );
  14. beforeEach( function() {
  15. var CKEDITOR = modules.ckeditor;
  16. // Destroy all editor instances.
  17. while ( CKEDITOR.instances.length ) {
  18. CKEDITOR.instances.get( 0 ).destroy();
  19. }
  20. } );
  21. describe( 'create', function() {
  22. it( 'should return a promise', function() {
  23. var CKEDITOR = modules.ckeditor;
  24. var Promise = modules.promise;
  25. expect( CKEDITOR.create( content, editorConfig ) ).to.be.instanceof( Promise );
  26. } );
  27. it( 'should create a new editor instance', function() {
  28. var CKEDITOR = modules.ckeditor;
  29. var Editor = modules.editor;
  30. return CKEDITOR.create( content, editorConfig ).then( function( editor ) {
  31. expect( editor ).to.be.instanceof( Editor );
  32. expect( editor.element ).to.equal( content );
  33. } );
  34. } );
  35. it( 'should create a new editor instance (using a selector)', function() {
  36. var CKEDITOR = modules.ckeditor;
  37. var Editor = modules.editor;
  38. return CKEDITOR.create( '.editor', editorConfig ).then( function( editor ) {
  39. expect( editor ).to.be.instanceof( Editor );
  40. expect( editor.element ).to.equal( document.querySelector( '.editor' ) );
  41. } );
  42. } );
  43. it( 'should set configurations on the new editor', function() {
  44. var CKEDITOR = modules.ckeditor;
  45. return CKEDITOR.create( content, { test: 1, plugins: 'creator-test' } ).then( function( editor ) {
  46. expect( editor.config.test ).to.equal( 1 );
  47. } );
  48. } );
  49. it( 'should add the editor to the `instances` collection', function() {
  50. var CKEDITOR = modules.ckeditor;
  51. return CKEDITOR.create( content, editorConfig ).then( function( editor ) {
  52. expect( CKEDITOR.instances ).to.have.length( 1 );
  53. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor );
  54. } );
  55. } );
  56. it( 'should remove the editor from the `instances` collection on `destroy` event', function() {
  57. var CKEDITOR = modules.ckeditor;
  58. var editor1, editor2;
  59. // Create the first editor.
  60. return CKEDITOR.create( content, editorConfig ).then( function( editor ) {
  61. editor1 = editor;
  62. // Create the second editor.
  63. return CKEDITOR.create( '.editor', editorConfig ).then( function( editor ) {
  64. editor2 = editor;
  65. // It should have 2 editors.
  66. expect( CKEDITOR.instances ).to.have.length( 2 );
  67. // Destroy one of them.
  68. editor1.destroy();
  69. // It should have 1 editor now.
  70. expect( CKEDITOR.instances ).to.have.length( 1 );
  71. // Ensure that the remaining is the right one.
  72. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor2 );
  73. } );
  74. } );
  75. } );
  76. it( 'should be rejected on element not found', function() {
  77. var CKEDITOR = modules.ckeditor;
  78. return CKEDITOR.create( '.undefined' ).then( function() {
  79. throw new Error( 'It should not enter this function' );
  80. } ).catch( function( error ) {
  81. expect( error ).to.be.instanceof( Error );
  82. expect( error.message ).to.equal( 'Element not found' );
  83. } );
  84. } );
  85. } );
  86. describe( 'config', function() {
  87. it( 'should be an instance of Config', function() {
  88. var CKEDITOR = modules.ckeditor;
  89. var Config = modules.config;
  90. expect( CKEDITOR.config ).to.be.an.instanceof( Config );
  91. } );
  92. } );