8
0

inlineeditoruiview.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import InlineEditorUIView from '../src/inlineeditoruiview';
  6. import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
  7. import FloatingPanelView from '@ckeditor/ckeditor5-ui/src/panel/floating/floatingpanelview';
  8. import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
  9. import Locale from '@ckeditor/ckeditor5-utils/src/locale';
  10. describe( 'InlineEditorUIView', () => {
  11. let locale, view;
  12. beforeEach( () => {
  13. locale = new Locale( 'en' );
  14. view = new InlineEditorUIView( locale );
  15. } );
  16. describe( 'constructor()', () => {
  17. describe( '#toolbar', () => {
  18. it( 'is created', () => {
  19. expect( view.toolbar ).to.be.instanceof( ToolbarView );
  20. } );
  21. it( 'is given a locale object', () => {
  22. expect( view.toolbar.locale ).to.equal( locale );
  23. } );
  24. } );
  25. describe( '#panel', () => {
  26. it( 'is created', () => {
  27. expect( view.panel ).to.be.instanceof( FloatingPanelView );
  28. } );
  29. it( 'is given a locale object', () => {
  30. expect( view.panel.locale ).to.equal( locale );
  31. } );
  32. it( 'is given the right CSS class', () => {
  33. expect( view.panel.element.classList.contains( 'ck-toolbar__container' ) ).to.be.true;
  34. } );
  35. it( 'is put into the #body collection', () => {
  36. expect( view.body.get( 0 ) ).to.equal( view.panel );
  37. } );
  38. } );
  39. describe( '#editable', () => {
  40. it( 'is created', () => {
  41. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  42. } );
  43. it( 'is given a locate object', () => {
  44. expect( view.editable.locale ).to.equal( locale );
  45. } );
  46. it( 'is registered as a child', () => {
  47. const spy = sinon.spy( view.editable, 'destroy' );
  48. return view.init()
  49. .then( () => view.destroy() )
  50. .then( () => {
  51. sinon.assert.calledOnce( spy );
  52. } );
  53. } );
  54. } );
  55. } );
  56. describe( 'init', () => {
  57. it( 'appends #toolbar to panel#content', () => {
  58. expect( view.panel.content ).to.have.length( 0 );
  59. return view.init()
  60. .then( () => {
  61. expect( view.panel.content.get( 0 ) ).to.equal( view.toolbar );
  62. } )
  63. .then( () => view.destroy() );
  64. } );
  65. } );
  66. describe( 'editableElement', () => {
  67. it( 'returns editable\'s view element', () => {
  68. return view.init()
  69. .then( () => {
  70. expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  71. } )
  72. .then( () => view.destroy() );
  73. } );
  74. } );
  75. } );