classiceditorui.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document, Event */
  6. /* bender-tags: editor, browser-only */
  7. import ClassicEditorUI from 'ckeditor5/editor-classic/classiceditorui.js';
  8. import BoxedEditorUIView from 'ckeditor5/ui/editorui/boxed/boxededitoruiview.js';
  9. import Model from 'ckeditor5/ui/model.js';
  10. import Button from 'ckeditor5/ui/button/button.js';
  11. import ButtonView from 'ckeditor5/ui/button/buttonview.js';
  12. import Toolbar from 'ckeditor5/ui/toolbar/toolbar.js';
  13. import StickyToolbarView from 'ckeditor5/ui/toolbar/sticky/stickytoolbarview.js';
  14. import EditableUI from 'ckeditor5/ui/editableui/editableui.js';
  15. import InlineEditableUIView from 'ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
  16. import ClassicTestEditor from 'tests/core/_utils/classictesteditor.js';
  17. describe( 'ClassicEditorUI', () => {
  18. let editorElement, editor, editorUI;
  19. beforeEach( () => {
  20. editorElement = document.createElement( 'div' );
  21. document.body.appendChild( editorElement );
  22. editor = new ClassicTestEditor( editorElement, {
  23. toolbar: [ 'foo', 'bar' ]
  24. } );
  25. editor.ui = editorUI = new ClassicEditorUI( editor );
  26. editorUI.view = new BoxedEditorUIView( editor.locale );
  27. editorUI.featureComponents.add( 'foo', Button, ButtonView, new Model( {} ) );
  28. editorUI.featureComponents.add( 'bar', Button, ButtonView, new Model( {} ) );
  29. } );
  30. describe( 'constructor()', () => {
  31. it( 'creates toolbar', () => {
  32. expect( editorUI.toolbar ).to.be.instanceof( Toolbar );
  33. expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
  34. } );
  35. it( 'binds editorUI.toolbar#model to editor.focusTracker', () => {
  36. expect( editorUI.toolbar.model.isActive ).to.false;
  37. editor.focusTracker.isFocused = true;
  38. expect( editorUI.toolbar.model.isActive ).to.true;
  39. } );
  40. it( 'creates editable', () => {
  41. expect( editorUI.editable ).to.be.instanceof( EditableUI );
  42. expect( editorUI.editable.view ).to.be.instanceof( InlineEditableUIView );
  43. } );
  44. it( 'registers editable element in editor Focus Tracker', () => {
  45. return editorUI.init()
  46. .then( () => {
  47. editor.focusTracker.isFocused = false;
  48. editorUI.editable.view.element.dispatchEvent( new Event( 'focus' ) );
  49. expect( editor.focusTracker.isFocused ).to.true;
  50. } );
  51. } );
  52. } );
  53. describe( 'editableElement', () => {
  54. it( 'returns editable\'s view element', () => {
  55. document.body.appendChild( editorUI.view.element );
  56. return editorUI.init()
  57. .then( () => {
  58. expect( editorUI.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  59. } );
  60. } );
  61. } );
  62. describe( 'init', () => {
  63. it( 'returns a promise', () => {
  64. document.body.appendChild( editorUI.view.element );
  65. expect( editorUI.init() ).to.be.instanceof( Promise );
  66. } );
  67. it( 'sets toolbar.model#limiterElement', ( done ) => {
  68. editorUI.init().then( () => {
  69. expect( editorUI.toolbar.model.limiterElement ).to.equal( editorUI.view.element );
  70. done();
  71. } );
  72. } );
  73. } );
  74. describe( '_createToolbar', () => {
  75. it( 'passes toolbar config to the model', () => {
  76. expect( editorUI.toolbar.model.config ).to.have.members( [ 'foo', 'bar' ] );
  77. } );
  78. } );
  79. } );