classic.js 3.2 KB

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