classic.js 3.1 KB

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