8
0

decouplededitoruiview.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 .ck-reset_all class', () => {
  37. expect( view.toolbar.element.classList.contains( 'ck-reset_all' ) ).to.be.true;
  38. } );
  39. } );
  40. describe( '#editable', () => {
  41. it( 'is created', () => {
  42. expect( view.editable ).to.be.instanceof( InlineEditableUIView );
  43. } );
  44. it( 'is given a locale object', () => {
  45. expect( view.editable.locale ).to.equal( locale );
  46. } );
  47. it( 'is rendered but gets no parent', () => {
  48. expect( view.isRendered ).to.be.true;
  49. expect( view.editable.element.parentElement ).to.be.null;
  50. } );
  51. it( 'can be created out of an existing DOM element', () => {
  52. const editableElement = document.createElement( 'div' );
  53. const testView = new DecoupledEditorUIView( locale, editableElement );
  54. testView.render();
  55. expect( testView.editable.element ).to.equal( editableElement );
  56. testView.destroy();
  57. } );
  58. } );
  59. } );
  60. describe( 'destroy', () => {
  61. it( 'destroys #toolbar and #editable', () => {
  62. const toolbarSpy = sinon.spy( view.toolbar, 'destroy' );
  63. const editableSpy = sinon.spy( view.editable, 'destroy' );
  64. view.destroy();
  65. sinon.assert.calledOnce( toolbarSpy );
  66. sinon.assert.calledOnce( editableSpy );
  67. } );
  68. it( 'does not touch the toolbar#element and editable#element by default', () => {
  69. document.body.appendChild( view.toolbar.element );
  70. document.body.appendChild( view.editable.element );
  71. view.destroy();
  72. expect( view.toolbar.element.parentElement ).to.equal( document.body );
  73. expect( view.editable.element.parentElement ).to.equal( document.body );
  74. view.toolbar.element.remove();
  75. view.editable.element.remove();
  76. } );
  77. } );
  78. describe( 'editableElement', () => {
  79. it( 'returns editable\'s view element', () => {
  80. expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
  81. view.destroy();
  82. } );
  83. } );
  84. } );