decouplededitoruiview.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @license Copyright (c) 2003-2018, 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. describe( 'DecoupledEditorUIView', () => {
  11. let locale, view;
  12. beforeEach( () => {
  13. locale = new Locale( 'en' );
  14. view = new DecoupledEditorUIView( locale );
  15. view.render();
  16. } );
  17. afterEach( () => {
  18. view.destroy();
  19. } );
  20. describe( 'constructor()', () => {
  21. it( 'is virtual', () => {
  22. expect( view.template ).to.be.undefined;
  23. expect( view.element ).to.be.null;
  24. } );
  25. describe( '#toolbar', () => {
  26. it( 'is created', () => {
  27. expect( view.toolbar ).to.be.instanceof( ToolbarView );
  28. } );
  29. it( 'is given a locate object', () => {
  30. expect( view.toolbar.locale ).to.equal( locale );
  31. } );
  32. it( 'is rendered but gets no parent', () => {
  33. expect( view.isRendered ).to.be.true;
  34. expect( view.toolbar.element.parentElement ).to.be.null;
  35. } );
  36. it( 'gets the CSS classes', () => {
  37. expect( view.toolbar.element.classList.contains( 'ck-reset_all' ) ).to.be.true;
  38. expect( view.toolbar.element.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
  39. } );
  40. } );
  41. describe( '#editable', () => {
  42. it( 'is created', () => {
  43. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  44. } );
  45. it( 'is given a locale object', () => {
  46. expect( view.editable.locale ).to.equal( locale );
  47. } );
  48. it( 'is rendered but gets no parent', () => {
  49. expect( view.isRendered ).to.be.true;
  50. expect( view.editable.element.parentElement ).to.be.null;
  51. } );
  52. it( 'can be created out of an existing DOM element', () => {
  53. const editableElement = document.createElement( 'div' );
  54. const testView = new DecoupledEditorUIView( locale, editableElement );
  55. testView.render();
  56. expect( testView.editable.element ).to.equal( editableElement );
  57. testView.destroy();
  58. } );
  59. } );
  60. } );
  61. describe( 'destroy', () => {
  62. it( 'destroys #toolbar and #editable', () => {
  63. const toolbarSpy = sinon.spy( view.toolbar, 'destroy' );
  64. const editableSpy = sinon.spy( view.editable, 'destroy' );
  65. view.destroy();
  66. sinon.assert.calledOnce( toolbarSpy );
  67. sinon.assert.calledOnce( editableSpy );
  68. } );
  69. it( 'does not touch the toolbar#element and editable#element by default', () => {
  70. document.body.appendChild( view.toolbar.element );
  71. document.body.appendChild( view.editable.element );
  72. view.destroy();
  73. expect( view.toolbar.element.parentElement ).to.equal( document.body );
  74. expect( view.editable.element.parentElement ).to.equal( document.body );
  75. view.toolbar.element.remove();
  76. view.editable.element.remove();
  77. } );
  78. } );
  79. describe( 'editableElement', () => {
  80. it( 'returns editable\'s view element', () => {
  81. expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  82. view.destroy();
  83. } );
  84. } );
  85. } );