/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/* globals document */
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import HTMLEmbedEditing from '../src/htmlembedediting';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
describe( 'HTMLEmbedUpdateCommand', () => {
let editor, model, editorElement, command;
testUtils.createSinonSandbox();
beforeEach( () => {
editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );
return ClassicTestEditor
.create( editorElement, {
plugins: [ HTMLEmbedEditing, Paragraph ]
} )
.then( newEditor => {
editor = newEditor;
model = editor.model;
command = editor.commands.get( 'htmlEmbedUpdate' );
} );
} );
afterEach( () => {
return editor.destroy()
.then( () => {
editorElement.remove();
} );
} );
describe( 'isEnabled', () => {
it( 'should be true when the selection contains single the `rawHtml` element', () => {
setModelData( model, '[]' );
command.refresh();
expect( command.isEnabled ).to.equal( true );
} );
it( 'should be false when the selection contains more than single `rawHtml` element', () => {
setModelData( model, '[]' );
command.refresh();
expect( command.isEnabled ).to.equal( false );
} );
it( 'should be false when the selection contains other element than the `rawHtml` element', () => {
setModelData( model, '[]' );
command.refresh();
expect( command.isEnabled ).to.equal( false );
} );
} );
describe( 'execute()', () => {
it( 'should create a single batch', () => {
setModelData( model, '[]' );
const spy = sinon.spy();
model.document.on( 'change', spy );
command.execute( 'Foo.' );
sinon.assert.calledOnce( spy );
} );
it( 'should update the `value` attribute of selected the `rawHtml` element', () => {
setModelData( model, '[]' );
command.execute( 'Foo.' );
const rawHtml = model.document.getRoot().getChild( 0 );
expect( rawHtml.getAttribute( 'value' ) ).to.equal( 'Foo.' );
} );
it( 'should update nothing if selected other element than the `rawHtml` element', () => {
setModelData( model, '[]' );
command.execute( 'Foo.' );
expect( getModelData( model ) ).to.equal( '[]' );
} );
} );
} );