classiccreator.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: creator */
  6. 'use strict';
  7. import Editor from '/ckeditor5/editor.js';
  8. import BoxedEditorUI from '/ckeditor5/ui/editorui/boxed/boxededitorui.js';
  9. import BoxedEditorUIView from '/ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
  10. import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
  11. import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
  12. import StickyToolbar from '/ckeditor5/ui/bindings/stickytoolbar.js';
  13. import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
  14. import StandardCreator from '/ckeditor5/creator/standardcreator.js';
  15. import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
  16. import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
  17. import testUtils from '/tests/ckeditor5/_utils/utils.js';
  18. testUtils.createSinonSandbox();
  19. describe( 'ClassicCreator', () => {
  20. let creator, editor, fooElement, barElement;
  21. beforeEach( function() {
  22. fooElement = document.createElement( 'div' );
  23. fooElement.setAttribute( 'class', 'first' );
  24. fooElement.setAttribute( 'data-test', this.currentTest.title );
  25. document.body.appendChild( fooElement );
  26. barElement = document.createElement( 'div' );
  27. barElement.setAttribute( 'class', 'second' );
  28. barElement.setAttribute( 'data-test', this.currentTest.title );
  29. document.body.appendChild( barElement );
  30. editor = new Editor(
  31. {
  32. foo: fooElement,
  33. bar: barElement
  34. },
  35. {
  36. toolbar: [ 'bold', 'italic' ]
  37. }
  38. );
  39. creator = new ClassicCreator( editor, new HtmlDataProcessor() );
  40. } );
  41. describe( 'constructor', () => {
  42. it( 'inherits from the StandardCreator', () => {
  43. expect( creator ).to.be.instanceof( StandardCreator );
  44. } );
  45. it( 'creates a single instance of Editable ', () => {
  46. expect( editor.editables ).to.have.length( 1 );
  47. expect( editor.editables.get( 0 ).name ).to.equal( 'foo' );
  48. } );
  49. it( 'creates the UI using BoxedEditorUI classes', () => {
  50. expect( editor.ui ).to.be.instanceof( BoxedEditorUI );
  51. expect( editor.ui.view ).to.be.instanceof( BoxedEditorUIView );
  52. } );
  53. it( 'creates a single document root', () => {
  54. expect( editor.document.rootNames ).to.have.members( [ 'foo' ] );
  55. } );
  56. } );
  57. describe( 'create', () => {
  58. it( 'returns a promise', () => {
  59. expect( creator.create() ).to.be.instanceof( Promise );
  60. } );
  61. it( 'calls _replaceElement', () => {
  62. const spy = testUtils.sinon.spy( creator, '_replaceElement' );
  63. return creator.create().then( () => {
  64. expect( spy.calledOnce ).to.be.true;
  65. } );
  66. } );
  67. it( 'calls _createToolbar', () => {
  68. const spy = testUtils.sinon.spy( creator, '_createToolbar' );
  69. return creator.create().then( () => {
  70. expect( spy.calledOnce ).to.be.true;
  71. } );
  72. } );
  73. it( 'creates the editable using EditableUI Controller in main region', () => {
  74. return creator.create().then( () => {
  75. expect( editor.ui.collections.get( 'main' ) ).to.have.length( 1 );
  76. expect( editor.ui.collections.get( 'main' ).get( 0 ) ).to.be.instanceof( EditableUI );
  77. } );
  78. } );
  79. it( 'creates the editable using InlineEditableUIView in main region', () => {
  80. return creator.create().then( () => {
  81. expect( editor.ui.collections.get( 'main' ).get( 0 ).view ).to.be.instanceof( InlineEditableUIView );
  82. } );
  83. } );
  84. it( 'binds the editable to InlineEditableUIView', () => {
  85. return creator.create().then( () => {
  86. const editableUIView = editor.ui.collections.get( 'main' ).get( 0 ).view;
  87. expect( editor.editables.get( 0 ).domElement ).to.equal( editableUIView.element );
  88. } );
  89. } );
  90. it( 'initializes the editor.ui', () => {
  91. const spy = testUtils.sinon.spy( editor.ui, 'init' );
  92. return creator.create().then( () => {
  93. expect( spy.calledOnce ).to.be.true;
  94. } );
  95. } );
  96. it( 'calls loadDataFromEditorElement', () => {
  97. const spy = testUtils.sinon.spy( creator, 'loadDataFromEditorElement' );
  98. return creator.create().then( () => {
  99. expect( spy.calledOnce ).to.be.true;
  100. } );
  101. } );
  102. } );
  103. describe( 'destroy', () => {
  104. it( 'returns a promise', () => {
  105. return creator.create().then( () => {
  106. expect( creator.destroy() ).to.be.instanceof( Promise );
  107. } );
  108. } );
  109. it( 'destroys parent class', () => {
  110. const spy = testUtils.sinon.spy( StandardCreator.prototype, 'destroy' );
  111. return creator.create().then( () => {
  112. return creator.destroy().then( () => {
  113. expect( spy.calledOnce ).to.be.true;
  114. } );
  115. } );
  116. } );
  117. it( 'calls updateEditorElement', () => {
  118. const spy = testUtils.sinon.spy( creator, 'updateEditorElement' );
  119. return creator.create().then( () => {
  120. return creator.destroy().then( () => {
  121. expect( spy.calledOnce ).to.be.true;
  122. } );
  123. } );
  124. } );
  125. it( 'destroys the UI', () => {
  126. return creator.create().then( () => {
  127. return creator.destroy().then( () => {
  128. expect( editor.ui.collections ).to.be.null;
  129. } );
  130. } );
  131. } );
  132. } );
  133. describe( '_createToolbar', () => {
  134. it( 'creates toolbar using StickyToolbar and StickyToolbarView', () => {
  135. return creator.create().then( () => {
  136. expect( editor.ui.collections.get( 'top' ) ).to.have.length( 1 );
  137. const toolbar = editor.ui.collections.get( 'top' ).get( 0 );
  138. expect( toolbar ).to.be.instanceof( StickyToolbar );
  139. expect( toolbar.view ).to.be.instanceof( StickyToolbarView );
  140. } );
  141. } );
  142. } );
  143. } );