classiceditoruiview.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 ClassicEditorUIView from '/ckeditor5/editor-classic/classiceditoruiview.js';
  8. import ClassicTestEditor from '/tests/core/_utils/classictesteditor.js';
  9. import ButtonView from '/ckeditor5/ui/button/buttonview.js';
  10. import StickyToolbarView from '/ckeditor5/ui/toolbar/sticky/stickytoolbarview.js';
  11. import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
  12. import testUtils from '/tests/utils/_utils/utils.js';
  13. describe( 'ClassicEditorUI', () => {
  14. let editorElement, editor, editable, view;
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. editor = new ClassicTestEditor( editorElement, {
  19. toolbar: [ 'foo', 'bar' ]
  20. } );
  21. editable = editor.editing.view.createRoot( document.createElement( 'div' ) );
  22. editor.ui = view = new ClassicEditorUIView( editor, editor.locale );
  23. function createButton( locale ) {
  24. return new ButtonView( locale );
  25. }
  26. view.featureComponents.add( 'foo', createButton );
  27. view.featureComponents.add( 'bar', createButton );
  28. } );
  29. describe( 'constructor', () => {
  30. describe( 'toolbar', () => {
  31. it( 'creates toolbar', () => {
  32. expect( view.toolbar ).to.be.instanceof( StickyToolbarView );
  33. } );
  34. it( 'binds view.toolbar#isFocused to editor#focusTracker', () => {
  35. editor.focusTracker.isFocused = false;
  36. expect( view.toolbar.isActive ).to.false;
  37. editor.focusTracker.isFocused = true;
  38. expect( view.toolbar.isActive ).to.true;
  39. } );
  40. } );
  41. describe( 'editable', () => {
  42. it( 'creates view#editable', () => {
  43. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  44. } );
  45. it( 'registers editable#element in editor focus tracker', () => {
  46. return view.init()
  47. .then( () => {
  48. editor.focusTracker.isFocused = false;
  49. view.editable.element.dispatchEvent( new Event( 'focus' ) );
  50. expect( editor.focusTracker.isFocused ).to.true;
  51. } );
  52. } );
  53. it( 'sets view.editable#name', () => {
  54. expect( view.editable.name ).to.equal( editable.rootName );
  55. } );
  56. it( 'binds view.editable#isFocused', () => {
  57. testUtils.assertBinding(
  58. view.editable,
  59. { isFocused: false },
  60. [
  61. [ editable, { isFocused: true } ]
  62. ],
  63. { isFocused: true }
  64. );
  65. } );
  66. it( 'binds view.editable#isReadOnly', () => {
  67. testUtils.assertBinding(
  68. view.editable,
  69. { isReadOnly: false },
  70. [
  71. [ editable, { isReadOnly: true } ]
  72. ],
  73. { isReadOnly: true }
  74. );
  75. } );
  76. } );
  77. } );
  78. describe( 'editableElement', () => {
  79. it( 'returns editable\'s view element', () => {
  80. document.body.appendChild( view.element );
  81. return view.init()
  82. .then( () => {
  83. expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  84. } );
  85. } );
  86. } );
  87. describe( 'init', () => {
  88. it( 'returns a promise', () => {
  89. document.body.appendChild( view.element );
  90. expect( view.init() ).to.be.instanceof( Promise );
  91. } );
  92. it( 'sets view.toolbar#limiterElement', ( done ) => {
  93. view.init().then( () => {
  94. expect( view.toolbar.limiterElement ).to.equal( view.element );
  95. done();
  96. } );
  97. } );
  98. } );
  99. } );