inlineeditoruiview.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
  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( BalloonPanelView );
  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. it( 'gets view.panel#withArrow set', () => {
  39. expect( view.panel.withArrow ).to.be.false;
  40. } );
  41. } );
  42. describe( '#editable', () => {
  43. it( 'is created', () => {
  44. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  45. } );
  46. it( 'is given a locate object', () => {
  47. expect( view.editable.locale ).to.equal( locale );
  48. } );
  49. it( 'is registered as a child', () => {
  50. const spy = sinon.spy( view.editable, 'destroy' );
  51. return view.init()
  52. .then( () => view.destroy() )
  53. .then( () => {
  54. sinon.assert.calledOnce( spy );
  55. } );
  56. } );
  57. } );
  58. } );
  59. describe( 'init', () => {
  60. it( 'appends #toolbar to panel#content', () => {
  61. expect( view.panel.content ).to.have.length( 0 );
  62. return view.init()
  63. .then( () => {
  64. expect( view.panel.content.get( 0 ) ).to.equal( view.toolbar );
  65. } )
  66. .then( () => view.destroy() );
  67. } );
  68. } );
  69. describe( 'editableElement', () => {
  70. it( 'returns editable\'s view element', () => {
  71. return view.init()
  72. .then( () => {
  73. expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  74. } )
  75. .then( () => view.destroy() );
  76. } );
  77. } );
  78. } );