classiceditorui.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Toolbar from '/ckeditor5/ui/toolbar/toolbar.js';
  10. import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
  11. import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
  12. import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
  13. import ClassicTestEditor from '/tests/ckeditor5/_utils/classictesteditor.js';
  14. describe( 'ClassicEditorUI', () => {
  15. let editorElement, editor, editorUI;
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. editor = new ClassicTestEditor( editorElement );
  20. editorUI = new ClassicEditorUI( editor );
  21. editorUI.view = new BoxedEditorUIView( editorUI.viewModel, editor.locale );
  22. } );
  23. describe( 'constructor', () => {
  24. it( 'creates toolbar', () => {
  25. expect( editorUI.toolbar ).to.be.instanceof( Toolbar );
  26. expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
  27. } );
  28. it( 'creates editable', () => {
  29. expect( editorUI.editable ).to.be.instanceof( EditableUI );
  30. expect( editorUI.editable.view ).to.be.instanceof( InlineEditableUIView );
  31. } );
  32. } );
  33. describe( 'editableElement', () => {
  34. it( 'returns editable\'s view element', () => {
  35. document.body.appendChild( editorUI.view.element );
  36. return editorUI.init()
  37. .then( () => {
  38. expect( editorUI.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  39. } );
  40. } );
  41. } );
  42. describe( 'init', () => {
  43. it( 'adds buttons', () => {
  44. editor.config.set( 'toolbar', [ 'foo', 'bar' ] );
  45. document.body.appendChild( editorUI.view.element );
  46. const spy = sinon.stub( editorUI.toolbar, 'addButtons' );
  47. return editorUI.init()
  48. .then( () => {
  49. expect( spy.calledOnce ).to.be.true;
  50. expect( spy.args[ 0 ][ 0 ] ).to.deep.equal( [ 'foo', 'bar' ] );
  51. } );
  52. } );
  53. it( 'returns a promise', () => {
  54. document.body.appendChild( editorUI.view.element );
  55. expect( editorUI.init() ).to.be.instanceof( Promise );
  56. } );
  57. } );
  58. } );