| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- /* global document */
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- import HTMLEmbedEditing from '../src/htmlembedediting';
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import HTMLEmbedUI from '../src/htmlembedui';
- import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
- describe( 'HTMLEMbedEditing', () => {
- let element, editor, view, viewDocument, htmlEmbedView;
- testUtils.createSinonSandbox();
- beforeEach( () => {
- element = document.createElement( 'div' );
- document.body.appendChild( element );
- return ClassicTestEditor
- .create( element, {
- plugins: [ HTMLEmbedUI, HTMLEmbedEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- view = editor.editing.view;
- viewDocument = view.document;
- htmlEmbedView = editor.ui.componentFactory.create( 'htmlEmbed' );
- } );
- } );
- afterEach( () => {
- element.remove();
- return editor.destroy();
- } );
- it( 'should register htmlEmbed feature component', () => {
- expect( htmlEmbedView ).to.be.instanceOf( ButtonView );
- expect( htmlEmbedView.label ).to.equal( 'Insert HTML' );
- expect( htmlEmbedView.icon ).to.match( /<svg / );
- expect( htmlEmbedView.isToggleable ).to.be.false;
- } );
- it( 'should execute htmlEmbedInsert command on model execute event', () => {
- const executeSpy = testUtils.sinon.spy( editor, 'execute' );
- htmlEmbedView.fire( 'execute' );
- sinon.assert.calledOnce( executeSpy );
- sinon.assert.calledWithExactly( executeSpy, 'htmlEmbedInsert' );
- } );
- it( 'should bind model to htmlEmbedInsert command', () => {
- const command = editor.commands.get( 'htmlEmbedInsert' );
- expect( htmlEmbedView.isEnabled ).to.be.true;
- command.isEnabled = false;
- expect( htmlEmbedView.isEnabled ).to.be.false;
- } );
- it( 'should switch to edit source mode after inserting the element', () => {
- htmlEmbedView.fire( 'execute' );
- const editSourceView = viewDocument.getRoot().getChild( 0 ).getChild( 1 );
- expect( document.activeElement ).to.equal( editSourceView.getCustomProperty( 'DOMElement' ) );
- } );
- } );
|