ckeditor.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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', 'config' );
  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 set configurations on the new editor', function() {
  39. var CKEDITOR = modules.ckeditor;
  40. return CKEDITOR.create( content, { test: 1 } ).then( function( editor ) {
  41. expect( editor.config.test ).to.equal( 1 );
  42. } );
  43. } );
  44. it( 'should add the editor to the `instances` collection', function() {
  45. var CKEDITOR = modules.ckeditor;
  46. return CKEDITOR.create( content ).then( function( editor ) {
  47. expect( CKEDITOR.instances ).to.have.length( 1 );
  48. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor );
  49. } );
  50. } );
  51. it( 'should remove the editor from the `instances` collection on `destroy` event', function() {
  52. var CKEDITOR = modules.ckeditor;
  53. var editor1, editor2;
  54. // Create the first editor.
  55. return CKEDITOR.create( content ).then( function( editor ) {
  56. editor1 = editor;
  57. // Create the second editor.
  58. return CKEDITOR.create( '.editor' ).then( function( editor ) {
  59. editor2 = editor;
  60. // It should have 2 editors.
  61. expect( CKEDITOR.instances ).to.have.length( 2 );
  62. // Destroy one of them.
  63. editor1.destroy();
  64. // It should have 1 editor now.
  65. expect( CKEDITOR.instances ).to.have.length( 1 );
  66. // Ensure that the remaining is the right one.
  67. expect( CKEDITOR.instances.get( 0 ) ).to.equal( editor2 );
  68. } );
  69. } );
  70. } );
  71. it( 'should be rejected on element not found', function() {
  72. var CKEDITOR = modules.ckeditor;
  73. return CKEDITOR.create( '.undefined' ).then( function() {
  74. throw new Error( 'It should not enter this function' );
  75. } ).catch( function( error ) {
  76. expect( error ).to.be.instanceof( Error );
  77. expect( error.message ).to.equal( 'Element not found' );
  78. } );
  79. } );
  80. } );
  81. describe( 'config', function() {
  82. it( 'should be an instance of Config', function() {
  83. var CKEDITOR = modules.ckeditor;
  84. var Config = modules.config;
  85. expect( CKEDITOR.config ).to.be.an.instanceof( Config );
  86. } );
  87. } );