classic.js 3.0 KB

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