classic.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: editor, browser-only */
  6. import ClassicEditorUI from '/ckeditor5/editor-classic/classiceditorui.js';
  7. import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
  8. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  9. import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
  10. import testUtils from '/tests/ckeditor5/_utils/utils.js';
  11. import count from '/ckeditor5/utils/count.js';
  12. testUtils.createSinonSandbox();
  13. describe( 'ClassicEditor', () => {
  14. let editor, editorElement;
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
  18. document.body.appendChild( editorElement );
  19. } );
  20. afterEach( () => {
  21. editorElement.remove();
  22. } );
  23. describe( 'constructor', () => {
  24. beforeEach( () => {
  25. editor = new ClassicEditor( editorElement );
  26. } );
  27. it( 'creates a single div editable root in the view', () => {
  28. expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'div' );
  29. } );
  30. it( 'creates a single document root', () => {
  31. expect( count( editor.document.getRootNames() ) ).to.equal( 1 );
  32. expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
  33. } );
  34. it( 'creates the UI using BoxedEditorUI classes', () => {
  35. expect( editor.ui ).to.be.instanceof( ClassicEditorUI );
  36. expect( editor.ui.view ).to.be.instanceof( BoxedEditorUIView );
  37. } );
  38. it( 'uses HTMLDataProcessor', () => {
  39. expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
  40. } );
  41. } );
  42. describe( 'create', () => {
  43. beforeEach( function() {
  44. return ClassicEditor.create( editorElement, {
  45. features: [ 'paragraph', 'basic-styles/bold' ]
  46. } )
  47. .then( newEditor => {
  48. editor = newEditor;
  49. } );
  50. } );
  51. it( 'creates an instance which inherits from the ClassicEditor', () => {
  52. expect( editor ).to.be.instanceof( ClassicEditor );
  53. } );
  54. it( 'inserts editor UI next to editor element', () => {
  55. expect( editor.ui.view.element.previousSibling ).to.equal( editorElement );
  56. } );
  57. it( 'attaches editable UI as view\'s DOM root', () => {
  58. expect( editor.editing.view.getDomRoot() ).to.equal( editor.ui.editable.view.element );
  59. } );
  60. it( 'loads data from the editor element', () => {
  61. expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
  62. } );
  63. } );
  64. describe( 'destroy', () => {
  65. beforeEach( function() {
  66. return ClassicEditor.create( editorElement, { features: [ 'paragraph' ] } )
  67. .then( newEditor => {
  68. editor = newEditor;
  69. } );
  70. } );
  71. it( 'sets the data back to the editor element', () => {
  72. editor.setData( '<p>foo</p>' );
  73. return editor.destroy()
  74. .then( () => {
  75. expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
  76. } );
  77. } );
  78. it( 'restores the editor element', () => {
  79. expect( editor.element.style.display ).to.equal( 'none' );
  80. return editor.destroy()
  81. .then( () => {
  82. expect( editor.element.style.display ).to.equal( '' );
  83. } );
  84. } );
  85. } );
  86. } );