ckeditor.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, beforeEach, document */
  6. 'use strict';
  7. var modules = bender.amd.require( 'ckeditor', 'editor', 'promise' );
  8. var content = document.getElementById( content );
  9. beforeEach( function() {
  10. var CKEDITOR = modules.ckeditor;
  11. // Destroy all editor instances.
  12. while ( CKEDITOR.instances.length ) {
  13. CKEDITOR.instances.get( 0 ).destroy();
  14. }
  15. } );
  16. describe( 'create', function() {
  17. it( 'should return a promise', function() {
  18. var CKEDITOR = modules.ckeditor;
  19. var Promise = modules.promise;
  20. expect( CKEDITOR.create( content ) ).to.be.instanceof( Promise );
  21. } );
  22. it( 'should create a new editor instance', function() {
  23. var CKEDITOR = modules.ckeditor;
  24. var Editor = modules.editor;
  25. return CKEDITOR.create( content ).then( function( editor ) {
  26. expect( editor ).to.be.instanceof( Editor );
  27. expect( editor.element ).to.equal( content );
  28. } );
  29. } );
  30. it( 'should create a new editor instance (using a selector)', function() {
  31. var CKEDITOR = modules.ckeditor;
  32. var Editor = modules.editor;
  33. return CKEDITOR.create( '.editor' ).then( function( editor ) {
  34. expect( editor ).to.be.instanceof( Editor );
  35. expect( editor.element ).to.equal( document.querySelector( '.editor' ) );
  36. } );
  37. } );
  38. it( 'should add the editor to the `instances` collection', function() {
  39. var CKEDITOR = modules.ckeditor;
  40. return CKEDITOR.create( content ).then( function( editor ) {
  41. expect( CKEDITOR.instances ).to.have.length( 1 );
  42. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor );
  43. } );
  44. } );
  45. it( 'should remove the editor from the `instances` collection on `destroy` event', function() {
  46. var CKEDITOR = modules.ckeditor;
  47. var editor1, editor2;
  48. // Create the first editor.
  49. return CKEDITOR.create( content ).then( function( editor ) {
  50. editor1 = editor;
  51. // Create the second editor.
  52. return CKEDITOR.create( content ).then( function( editor ) {
  53. editor2 = editor;
  54. // It should have 2 editors.
  55. expect( CKEDITOR.instances ).to.have.length( 2 );
  56. // Destroy one of them.
  57. editor1.destroy();
  58. // It should have 1 editor now.
  59. expect( CKEDITOR.instances ).to.have.length( 1 );
  60. // Ensure that the remaining is the right one.
  61. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor2 );
  62. } );
  63. } );
  64. } );
  65. it( 'should be rejected on element not found', function() {
  66. var CKEDITOR = modules.ckeditor;
  67. return CKEDITOR.create( '.undefined' ).then( function() {
  68. throw( 'It should not enter this function' );
  69. } ).catch( function( error ) {
  70. expect( error ).to.be.instanceof( Error );
  71. expect( error.message ).to.equal( 'Element not found' );
  72. } );
  73. } );
  74. } );