Kamil Piechaczek il y a 5 ans
Parent
commit
0dc3c550ae

+ 5 - 6
packages/ckeditor5-html-embed/src/htmlembedupdatecommand.js

@@ -15,9 +15,9 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
  *
  * The command is registered by {@link module:html-embed/htmlembedediting~HTMLEmbedEditing} as `'htmlEmbedUpdate'`.
  *
- * To insert a page break at the current selection, execute the command:
+ * To update the value of the raw html element at the current selection, execute the command:
  *
- *		editor.execute( 'htmlEmbedUpdate', 'HTML.' );
+ *		editor.execute( 'htmlEmbedUpdate', '<b>HTML.</b>' );
  *
  * @extends module:core/command~Command
  */
@@ -31,7 +31,6 @@ export default class HTMLEmbedUpdateCommand extends Command {
 		const rawHtmlElement = getSelectedRawHtmlModelWidget( selection );
 
 		this.isEnabled = !!rawHtmlElement;
-		this.value = rawHtmlElement ? rawHtmlElement.getAttribute( 'value' ) : '';
 	}
 
 	/**
@@ -43,11 +42,11 @@ export default class HTMLEmbedUpdateCommand extends Command {
 	execute( value ) {
 		const model = this.editor.model;
 		const selection = model.document.selection;
-		const selectedMedia = getSelectedRawHtmlModelWidget( selection );
+		const selectedRawHtmlElement = getSelectedRawHtmlModelWidget( selection );
 
-		if ( selectedMedia ) {
+		if ( selectedRawHtmlElement ) {
 			model.change( writer => {
-				writer.setAttribute( 'value', value, selectedMedia );
+				writer.setAttribute( 'value', value, selectedRawHtmlElement );
 			} );
 		}
 	}

+ 347 - 0
packages/ckeditor5-html-embed/tests/htmlembedediting.js

@@ -0,0 +1,347 @@
+/**
+ * @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 console, 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 HTMLEmbedUpdateCommand from '../src/htmlembedupdatecommand';
+import HTMLEmbedInsertCommand from '../src/htmlembedinsertcommand';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { isRawHtmlWidget } from '../src/utils';
+
+describe( 'HTMLEMbedEditing', () => {
+	let element, editor, model, view, viewDocument;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+
+		return ClassicTestEditor
+			.create( element, {
+				plugins: [ HTMLEmbedEditing ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+				model = editor.model;
+				view = editor.editing.view;
+				viewDocument = view.document;
+			} );
+	} );
+
+	afterEach( () => {
+		return editor.destroy()
+			.then( () => {
+				element.remove();
+			} );
+	} );
+
+	it( 'should have pluginName', () => {
+		expect( HTMLEmbedEditing.pluginName ).to.equal( 'HTMLEmbedEditing' );
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( HTMLEmbedEditing ) ).to.be.instanceOf( HTMLEmbedEditing );
+	} );
+
+	it( 'should set proper schema rules', () => {
+		expect( model.schema.checkChild( [ '$root' ], 'rawHtml' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', 'rawHtml' ], 'value' ) ).to.be.true;
+
+		expect( model.schema.isObject( 'rawHtml' ) ).to.be.true;
+
+		expect( model.schema.checkChild( [ '$root', 'rawHtml' ], '$text' ) ).to.be.false;
+		expect( model.schema.checkChild( [ '$root', '$block' ], 'rawHtml' ) ).to.be.false;
+	} );
+
+	describe( 'commands', () => {
+		it( 'should register htmlEmbedUpdate command', () => {
+			expect( editor.commands.get( 'htmlEmbedUpdate' ) ).to.be.instanceOf( HTMLEmbedUpdateCommand );
+		} );
+
+		it( 'should register htmlEmbedInsert command', () => {
+			expect( editor.commands.get( 'htmlEmbedInsert' ) ).to.be.instanceOf( HTMLEmbedInsertCommand );
+		} );
+	} );
+
+	describe( 'config', () => {
+		let htmlEmbed;
+
+		beforeEach( () => {
+			htmlEmbed = editor.config.get( 'htmlEmbed' );
+		} );
+
+		describe( 'htmlEmbed.previewsInData', () => {
+			it( 'should be set to `false` by default', () => {
+				expect( htmlEmbed.previewsInData ).to.equal( false );
+			} );
+		} );
+
+		describe( 'htmlEmbed.sanitizeHtml', () => {
+			beforeEach( () => {
+				sinon.stub( console, 'warn' );
+			} );
+
+			it( 'should return an object with cleaned html and a note whether something has changed', () => {
+				expect( htmlEmbed.sanitizeHtml( 'foo' ) ).to.deep.equal( {
+					html: 'foo',
+					hasModified: false
+				} );
+			} );
+
+			it( 'should return an input string (without any modifications)', () => {
+				const unsafeHtml = '<img src="data:/xxx,<script>void</script>" onload="void;">';
+
+				expect( htmlEmbed.sanitizeHtml( unsafeHtml ).html ).to.deep.equal( unsafeHtml );
+			} );
+
+			it( 'should display a warning when using the default sanitizer', () => {
+				htmlEmbed.sanitizeHtml( 'foo' );
+
+				expect( console.warn.callCount ).to.equal( 1 );
+				expect( console.warn.firstCall.args[ 0 ] ).to.equal( 'html-embed-provide-sanitize-function' );
+			} );
+		} );
+	} );
+
+	describe( 'conversion in data pipeline', () => {
+		describe( 'model to view', () => {
+			it( 'should convert an empty `rawHtml` element', () => {
+				setModelData( model, '[<rawHtml></rawHtml>]' );
+
+				expect( editor.getData() ).to.equal( '<div class="raw-html-embed"></div>' );
+			} );
+
+			it( 'should put the HTML from the `value` attribute (in `rawHtml`) into the data', () => {
+				setModelData( model, '[<rawHtml></rawHtml>]' );
+
+				model.change( writer => {
+					writer.setAttribute( 'value', '<b>Foo.</b>', model.document.getRoot().getChild( 0 ) );
+				} );
+
+				expect( editor.getData() ).to.equal(
+					'<div class="raw-html-embed">' +
+						'<b>Foo.</b>' +
+					'</div>'
+				);
+			} );
+		} );
+
+		describe( 'view to model', () => {
+			it( 'should convert innerHTML (single element) of div.raw-html-embed', () => {
+				editor.setData(
+					'<div class="raw-html-embed">' +
+						'<b>Foo.</b>' +
+					'</div>'
+				);
+
+				const rawHtml = model.document.getRoot().getChild( 0 );
+				expect( rawHtml.getAttribute( 'value' ) ).to.equal( '<b>Foo.</b>' );
+			} );
+
+			it( 'should convert innerHTML (single element with children) of div.raw-html-embed', () => {
+				editor.setData(
+					'<div class="raw-html-embed">' +
+						'<p>' +
+							'<b>Foo B.</b>' +
+							'<i>Foo I.</i>' +
+						'</p>' +
+					'</div>'
+				);
+
+				const rawHtml = model.document.getRoot().getChild( 0 );
+
+				expect( rawHtml.getAttribute( 'value' ) ).to.equal(
+					'<p>' +
+						'<b>Foo B.</b>' +
+						'<i>Foo I.</i>' +
+					'</p>'
+				);
+			} );
+
+			it( 'should convert innerHTML (few elements) of div.raw-html-embed', () => {
+				editor.setData(
+					'<div class="raw-html-embed">' +
+						'<b>Foo B.</b>' +
+						'<i>Foo I.</i>' +
+						'<u>Foo U.</u>' +
+					'</div>'
+				);
+
+				const rawHtml = model.document.getRoot().getChild( 0 );
+
+				expect( rawHtml.getAttribute( 'value' ) ).to.equal(
+					'<b>Foo B.</b>' +
+					'<i>Foo I.</i>' +
+					'<u>Foo U.</u>'
+				);
+			} );
+
+			it( 'should not convert in wrong context', () => {
+				model.schema.register( 'div', { inheritAllFrom: '$block' } );
+				model.schema.addChildCheck( ( ctx, childDef ) => {
+					if ( ctx.endsWith( '$root' ) && childDef.name == 'rawHtml' ) {
+						return false;
+					}
+				} );
+
+				editor.conversion.elementToElement( { model: 'div', view: 'div' } );
+
+				editor.setData(
+					'<div>' +
+						'<div class="raw-html-embed">' +
+							'<b>Foo.</b>' +
+						'</div>' +
+					'</div>'
+				);
+
+				expect( getModelData( model, { withoutSelection: true } ) )
+					.to.equal( '<div></div>' );
+			} );
+
+			it( 'should not convert inner `div.raw-html-embed` that is a child of outer div.raw-html-embed', () => {
+				editor.setData(
+					'<div class="raw-html-embed">' +
+						'<div class="raw-html-embed">' +
+							'<b>Foo B.</b>' +
+							'<i>Foo I.</i>' +
+							'<u>Foo U.</u>' +
+						'</div>' +
+					'</div>'
+				);
+
+				const rawHtml = model.document.getRoot().getChild( 0 );
+
+				expect( rawHtml.getAttribute( 'value' ) ).to.equal(
+					'<div class="raw-html-embed">' +
+						'<b>Foo B.</b>' +
+						'<i>Foo I.</i>' +
+						'<u>Foo U.</u>' +
+					'</div>'
+				);
+			} );
+		} );
+	} );
+
+	describe( 'conversion in editing pipeline (model to view)', () => {
+		describe( 'without previews (htmlEmbed.dataInPreviews=false)', () => {
+			it( 'converted element should be widgetized', () => {
+				setModelData( model, '<rawHtml></rawHtml>' );
+				const widget = viewDocument.getRoot().getChild( 0 );
+
+				expect( widget.name ).to.equal( 'div' );
+				expect( isRawHtmlWidget( widget ) ).to.be.true;
+			} );
+
+			it( 'should update the edit source element when the `value` attribute has changed', () => {
+				setModelData( model, '<rawHtml></rawHtml>' );
+
+				model.change( writer => {
+					writer.setAttribute( 'value', '<b>Foo.</b>', model.document.getRoot().getChild( 0 ) );
+				} );
+
+				// TODO: Assertions.
+			} );
+
+			// TODO: More tests.
+			it.skip( 'should render the edit source element', () => {
+			} );
+
+			it.skip( 'should render the preview placeholder element', () => {
+			} );
+
+			it.skip( 'should render the toggle mode icon', () => {
+			} );
+
+			it.skip( 'should update the `value` attribute after applying changes in the edit source element', () => {
+			} );
+
+			it.skip( 'should remove DOM events when destroying the plugin', () => {
+			} );
+
+			it.skip( 'should show the preview element by default', () => {
+			} );
+		} );
+
+		describe( 'with previews (htmlEmbed.dataInPreviews=true)', () => {
+			let element, editor, model, view, viewDocument, sanitizeHtml;
+
+			testUtils.createSinonSandbox();
+
+			beforeEach( () => {
+				element = document.createElement( 'div' );
+				document.body.appendChild( element );
+
+				// The default sanitize function without `console.warn`.
+				sanitizeHtml = input => ( { html: input, hasChanged: false } );
+
+				return ClassicTestEditor
+					.create( element, {
+						plugins: [ HTMLEmbedEditing ],
+						htmlEmbed: {
+							previewsInData: true,
+							sanitizeHtml
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+						view = editor.editing.view;
+						viewDocument = view.document;
+					} );
+			} );
+
+			afterEach( () => {
+				return editor.destroy()
+					.then( () => {
+						element.remove();
+					} );
+			} );
+
+			it( 'converted element should be widgetized', () => {
+				setModelData( model, '<rawHtml></rawHtml>' );
+				const widget = viewDocument.getRoot().getChild( 0 );
+
+				expect( widget.name ).to.equal( 'div' );
+				expect( isRawHtmlWidget( widget ) ).to.be.true;
+			} );
+
+			it( 'should update the source and preview elements when the `value` attribute has changed', () => {
+				setModelData( model, '<rawHtml></rawHtml>' );
+
+				model.change( writer => {
+					writer.setAttribute( 'value', '<b>Foo.</b>', model.document.getRoot().getChild( 0 ) );
+				} );
+
+				// TODO: Assertions.
+			} );
+
+			// TODO: More tests.
+			it.skip( 'should render the edit source element', () => {
+			} );
+
+			it.skip( 'should render the preview placeholder element', () => {
+			} );
+
+			it.skip( 'should render the toggle mode icon', () => {
+			} );
+
+			it.skip( 'should update the `value` attribute after applying changes in the edit source element', () => {
+			} );
+
+			it.skip( 'should re-render the preview element after applying changes in the edit source element', () => {
+			} );
+
+			it.skip( 'should remove DOM events when destroying the plugin', () => {
+			} );
+
+			it.skip( 'should show the preview element by default', () => {
+			} );
+		} );
+	} );
+} );

+ 169 - 0
packages/ckeditor5-html-embed/tests/htmlembedinsertcommand.js

@@ -0,0 +1,169 @@
+/**
+ * @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( 'HTMLEmbedInsertCommand', () => {
+	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( 'htmlEmbedInsert' );
+			} );
+	} );
+
+	afterEach( () => {
+		return editor.destroy()
+			.then( () => {
+				editorElement.remove();
+			} );
+	} );
+
+	describe( 'isEnabled', () => {
+		it( 'should be true when the selection directly in the root', () => {
+			model.enqueueChange( 'transparent', () => {
+				setModelData( model, '[]' );
+
+				command.refresh();
+				expect( command.isEnabled ).to.be.true;
+			} );
+		} );
+
+		it( 'should be true when the selection is in empty block', () => {
+			setModelData( model, '<paragraph>[]</paragraph>' );
+
+			expect( command.isEnabled ).to.be.true;
+		} );
+
+		it( 'should be true when the selection directly in a paragraph', () => {
+			setModelData( model, '<paragraph>foo[]</paragraph>' );
+			expect( command.isEnabled ).to.be.true;
+		} );
+
+		it( 'should be true when the selection directly in a block', () => {
+			model.schema.register( 'block', { inheritAllFrom: '$block' } );
+			model.schema.extend( '$text', { allowIn: 'block' } );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'block', view: 'block' } );
+
+			setModelData( model, '<block>foo[]</block>' );
+			expect( command.isEnabled ).to.be.true;
+		} );
+
+		it( 'should be false when the selection is on other raw html element', () => {
+			setModelData( model, '[<rawHtml></rawHtml>]' );
+			expect( command.isEnabled ).to.be.false;
+		} );
+
+		it( 'should be false when the selection is on other object', () => {
+			model.schema.register( 'object', { isObject: true, allowIn: '$root' } );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'object', view: 'object' } );
+			setModelData( model, '[<object></object>]' );
+
+			expect( command.isEnabled ).to.be.false;
+		} );
+
+		it( 'should be true when the selection is inside block element inside isLimit element which allows raw html', () => {
+			model.schema.register( 'table', { allowWhere: '$block', isLimit: true, isObject: true, isBlock: true } );
+			model.schema.register( 'tableRow', { allowIn: 'table', isLimit: true } );
+			model.schema.register( 'tableCell', { allowIn: 'tableRow', isLimit: true, isSelectable: true } );
+			model.schema.extend( '$block', { allowIn: 'tableCell' } );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'table', view: 'table' } );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'tableRow', view: 'tableRow' } );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'tableCell', view: 'tableCell' } );
+
+			setModelData( model, '<table><tableRow><tableCell><paragraph>foo[]</paragraph></tableCell></tableRow></table>' );
+		} );
+
+		it( 'should be false when schema disallows raw html', () => {
+			model.schema.register( 'block', { inheritAllFrom: '$block' } );
+			model.schema.extend( 'paragraph', { allowIn: 'block' } );
+			// Block raw html in block.
+			model.schema.addChildCheck( ( context, childDefinition ) => {
+				if ( childDefinition.name === 'rawHtml' && context.last.name === 'block' ) {
+					return false;
+				}
+			} );
+			editor.conversion.for( 'downcast' ).elementToElement( { model: 'block', view: 'block' } );
+
+			setModelData( model, '<block><paragraph>[]</paragraph></block>' );
+
+			expect( command.isEnabled ).to.be.false;
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		beforeEach( () => {
+			model.schema.register( 'heading1', { inheritAllFrom: '$block' } );
+			editor.conversion.elementToElement( { model: 'heading1', view: 'h1' } );
+
+			model.schema.register( 'media', { allowWhere: '$block' } );
+			editor.conversion.elementToElement( { model: 'media', view: 'div' } );
+		} );
+
+		it( 'should create a single batch', () => {
+			setModelData( model, '<paragraph>foo[]</paragraph>' );
+
+			const spy = sinon.spy();
+
+			model.document.on( 'change', spy );
+
+			command.execute();
+
+			sinon.assert.calledOnce( spy );
+		} );
+
+		it( 'should insert a raw html in an empty root and select it (a paragraph cannot be inserted)', () => {
+			// Block a paragraph in $root.
+			model.schema.addChildCheck( ( context, childDefinition ) => {
+				if ( childDefinition.name === 'paragraph' && context.last.name === '$root' ) {
+					return false;
+				}
+			} );
+
+			setModelData( model, '[]' );
+
+			command.execute();
+
+			expect( getModelData( model ) ).to.equal( '[<rawHtml></rawHtml>]' );
+		} );
+
+		it( 'should split an element where selection is placed and insert a raw html (non-collapsed selection)', () => {
+			setModelData( model, '<paragraph>f[o]o</paragraph>' );
+
+			command.execute();
+
+			expect( getModelData( model ) ).to.equal(
+				'<paragraph>f</paragraph>[<rawHtml></rawHtml>]<paragraph>o</paragraph>'
+			);
+		} );
+
+		it( 'should split an element where selection is placed and insert a raw html (collapsed selection)', () => {
+			setModelData( model, '<paragraph>fo[]o</paragraph>' );
+
+			command.execute();
+
+			expect( getModelData( model ) ).to.equal(
+				'<paragraph>fo</paragraph>[<rawHtml></rawHtml>]<paragraph>o</paragraph>'
+			);
+		} );
+	} );
+} );

+ 72 - 0
packages/ckeditor5-html-embed/tests/htmlembedui.js

@@ -0,0 +1,72 @@
+/**
+ * @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' ) );
+	} );
+} );

+ 96 - 0
packages/ckeditor5-html-embed/tests/htmlembedupdatecommand.js

@@ -0,0 +1,96 @@
+/**
+ * @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, '[<rawHtml></rawHtml>]' );
+
+			command.refresh();
+
+			expect( command.isEnabled ).to.equal( true );
+		} );
+
+		it( 'should be false when the selection contains more than single `rawHtml` element', () => {
+			setModelData( model, '[<rawHtml></rawHtml><rawHtml></rawHtml>]' );
+
+			command.refresh();
+
+			expect( command.isEnabled ).to.equal( false );
+		} );
+
+		it( 'should be false when the selection contains other element than the `rawHtml` element', () => {
+			setModelData( model, '[<paragraph></paragraph>]' );
+
+			command.refresh();
+
+			expect( command.isEnabled ).to.equal( false );
+		} );
+	} );
+
+	describe( 'execute()', () => {
+		it( 'should create a single batch', () => {
+			setModelData( model, '[<rawHtml></rawHtml>]' );
+
+			const spy = sinon.spy();
+
+			model.document.on( 'change', spy );
+
+			command.execute( '<b>Foo.</b>' );
+
+			sinon.assert.calledOnce( spy );
+		} );
+
+		it( 'should update the `value` attribute of selected the `rawHtml` element', () => {
+			setModelData( model, '[<rawHtml></rawHtml>]' );
+			command.execute( '<b>Foo.</b>' );
+
+			const rawHtml = model.document.getRoot().getChild( 0 );
+
+			expect( rawHtml.getAttribute( 'value' ) ).to.equal( '<b>Foo.</b>' );
+		} );
+
+		it( 'should update nothing if selected other element than the `rawHtml` element', () => {
+			setModelData( model, '[<paragraph></paragraph>]' );
+			command.execute( '<b>Foo.</b>' );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
+		} );
+	} );
+} );

+ 7 - 0
packages/ckeditor5-html-embed/tests/utils.js

@@ -0,0 +1,7 @@
+/**
+ * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+describe( 'utils', () => {
+} );