8
0

htmlembedui.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import HtmlEmbedEditing from '../src/htmlembedediting';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import HtmlEmbedUI from '../src/htmlembedui';
  10. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  11. describe( 'HtmlEmbedEditing', () => {
  12. let element, editor, htmlEmbedView;
  13. testUtils.createSinonSandbox();
  14. beforeEach( () => {
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. return ClassicTestEditor
  18. .create( element, {
  19. plugins: [ HtmlEmbedUI, HtmlEmbedEditing ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. htmlEmbedView = editor.ui.componentFactory.create( 'htmlEmbed' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. element.remove();
  28. return editor.destroy();
  29. } );
  30. it( 'should register htmlEmbed feature component', () => {
  31. expect( htmlEmbedView ).to.be.instanceOf( ButtonView );
  32. expect( htmlEmbedView.label ).to.equal( 'Insert HTML' );
  33. expect( htmlEmbedView.icon ).to.match( /<svg / );
  34. expect( htmlEmbedView.isToggleable ).to.be.false;
  35. } );
  36. it( 'should execute insertHtmlEmbed command on model execute event', () => {
  37. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  38. htmlEmbedView.fire( 'execute' );
  39. sinon.assert.calledOnce( executeSpy );
  40. sinon.assert.calledWithExactly( executeSpy, 'insertHtmlEmbed' );
  41. } );
  42. it( 'should bind model to insertHtmlEmbed command', () => {
  43. const command = editor.commands.get( 'insertHtmlEmbed' );
  44. expect( htmlEmbedView.isEnabled ).to.be.true;
  45. command.isEnabled = false;
  46. expect( htmlEmbedView.isEnabled ).to.be.false;
  47. } );
  48. it( 'should switch to edit source mode after inserting the element', () => {
  49. htmlEmbedView.fire( 'execute' );
  50. expect( document.activeElement.tagName ).to.equal( 'TEXTAREA' );
  51. } );
  52. } );