classic.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 ClassicEditorUIView from 'ckeditor5/editor-classic/classiceditoruiview.js';
  8. import HtmlDataProcessor from 'ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  9. import ClassicEditor from 'ckeditor5/editor-classic/classic.js';
  10. import Paragraph from 'ckeditor5/paragraph/paragraph.js';
  11. import Bold from 'ckeditor5/basic-styles/bold.js';
  12. import testUtils from 'tests/core/_utils/utils.js';
  13. import count from 'ckeditor5/utils/count.js';
  14. testUtils.createSinonSandbox();
  15. describe( 'ClassicEditor', () => {
  16. let editor, editorElement;
  17. beforeEach( () => {
  18. editorElement = document.createElement( 'div' );
  19. editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
  20. document.body.appendChild( editorElement );
  21. } );
  22. afterEach( () => {
  23. editorElement.remove();
  24. } );
  25. describe( 'constructor()', () => {
  26. beforeEach( () => {
  27. editor = new ClassicEditor( editorElement );
  28. } );
  29. it( 'creates a single div editable root in the view', () => {
  30. expect( editor.editing.view.getRoot() ).to.have.property( 'name', 'div' );
  31. } );
  32. it( 'creates a single document root', () => {
  33. expect( count( editor.document.getRootNames() ) ).to.equal( 1 );
  34. expect( editor.document.getRoot() ).to.have.property( 'name', '$root' );
  35. } );
  36. it( 'creates the UI using BoxedEditorUI classes', () => {
  37. expect( editor.ui ).to.be.instanceof( ClassicEditorUIView );
  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, 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.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.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. } );