htmlembedui.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, view, viewDocument, 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. view = editor.editing.view;
  24. viewDocument = view.document;
  25. htmlEmbedView = editor.ui.componentFactory.create( 'htmlEmbed' );
  26. } );
  27. } );
  28. afterEach( () => {
  29. element.remove();
  30. return editor.destroy();
  31. } );
  32. it( 'should register htmlEmbed feature component', () => {
  33. expect( htmlEmbedView ).to.be.instanceOf( ButtonView );
  34. expect( htmlEmbedView.label ).to.equal( 'Insert HTML' );
  35. expect( htmlEmbedView.icon ).to.match( /<svg / );
  36. expect( htmlEmbedView.isToggleable ).to.be.false;
  37. } );
  38. it( 'should execute htmlEmbedInsert command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. htmlEmbedView.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'htmlEmbedInsert' );
  43. } );
  44. it( 'should bind model to htmlEmbedInsert command', () => {
  45. const command = editor.commands.get( 'htmlEmbedInsert' );
  46. expect( htmlEmbedView.isEnabled ).to.be.true;
  47. command.isEnabled = false;
  48. expect( htmlEmbedView.isEnabled ).to.be.false;
  49. } );
  50. it( 'should switch to edit source mode after inserting the element', () => {
  51. htmlEmbedView.fire( 'execute' );
  52. const editSourceView = viewDocument.getRoot().getChild( 0 ).getChild( 1 );
  53. expect( document.activeElement ).to.equal( editSourceView.getCustomProperty( 'DOMElement' ) );
  54. } );
  55. } );