8
0

decouplededitoruiview.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import DecoupledEditorUIView from '../src/decouplededitoruiview';
  7. import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
  8. import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
  9. import Locale from '@ckeditor/ckeditor5-utils/src/locale';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. describe( 'DecoupledEditorUIView', () => {
  12. let locale, view;
  13. testUtils.createSinonSandbox();
  14. beforeEach( () => {
  15. locale = new Locale( 'en' );
  16. view = new DecoupledEditorUIView( locale );
  17. } );
  18. describe( 'constructor()', () => {
  19. it( 'is virtual', () => {
  20. expect( view.template ).to.be.undefined;
  21. expect( view.element ).to.be.null;
  22. } );
  23. describe( '#toolbar', () => {
  24. it( 'is created', () => {
  25. expect( view.toolbar ).to.be.instanceof( ToolbarView );
  26. } );
  27. it( 'is given a locale object', () => {
  28. expect( view.toolbar.locale ).to.equal( locale );
  29. } );
  30. it( 'is not rendered', () => {
  31. expect( view.toolbar.isRendered ).to.be.false;
  32. } );
  33. } );
  34. describe( '#editable', () => {
  35. it( 'is created', () => {
  36. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  37. } );
  38. it( 'is given a locale object', () => {
  39. expect( view.editable.locale ).to.equal( locale );
  40. } );
  41. it( 'is not rendered', () => {
  42. expect( view.editable.isRendered ).to.be.false;
  43. } );
  44. it( 'can be created out of an existing DOM element', () => {
  45. const editableElement = document.createElement( 'div' );
  46. const testView = new DecoupledEditorUIView( locale, editableElement );
  47. testView.render();
  48. expect( testView.editable.element ).to.equal( editableElement );
  49. testView.destroy();
  50. } );
  51. } );
  52. } );
  53. describe( 'render()', () => {
  54. beforeEach( () => {
  55. view.render();
  56. } );
  57. afterEach( () => {
  58. view.destroy();
  59. } );
  60. describe( '#toolbar', () => {
  61. it( 'is rendered but gets no parent', () => {
  62. expect( view.isRendered ).to.be.true;
  63. expect( view.toolbar.element.parentElement ).to.be.null;
  64. } );
  65. it( 'gets the CSS classes', () => {
  66. expect( view.toolbar.element.classList.contains( 'ck-reset_all' ) ).to.be.true;
  67. expect( view.toolbar.element.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
  68. } );
  69. } );
  70. describe( '#editable', () => {
  71. it( 'is rendered but gets no parent', () => {
  72. expect( view.isRendered ).to.be.true;
  73. expect( view.editable.element.parentElement ).to.be.null;
  74. } );
  75. } );
  76. } );
  77. describe( 'destroy', () => {
  78. beforeEach( () => {
  79. view.render();
  80. } );
  81. it( 'destroys #toolbar and #editable', () => {
  82. const toolbarSpy = sinon.spy( view.toolbar, 'destroy' );
  83. const editableSpy = sinon.spy( view.editable, 'destroy' );
  84. view.destroy();
  85. sinon.assert.calledOnce( toolbarSpy );
  86. sinon.assert.calledOnce( editableSpy );
  87. } );
  88. it( 'does not touch the toolbar#element and editable#element by default', () => {
  89. document.body.appendChild( view.toolbar.element );
  90. document.body.appendChild( view.editable.element );
  91. view.destroy();
  92. expect( view.toolbar.element.parentElement ).to.equal( document.body );
  93. expect( view.editable.element.parentElement ).to.equal( document.body );
  94. view.toolbar.element.remove();
  95. view.editable.element.remove();
  96. } );
  97. } );
  98. } );