|
|
@@ -0,0 +1,61 @@
|
|
|
+/**
|
|
|
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
|
|
|
+ * For licensing, see LICENSE.md.
|
|
|
+ */
|
|
|
+
|
|
|
+import VirtualTestEditor from 'tests/core/_utils/virtualtesteditor.js';
|
|
|
+import WidgetEngine from 'ckeditor5/image/widget/widgetengine.js';
|
|
|
+import buildModelConverter from 'ckeditor5/engine/conversion/buildmodelconverter.js';
|
|
|
+import { setData as setModelData } from 'ckeditor5/engine/dev-utils/model.js';
|
|
|
+import { getData as getViewData } from 'ckeditor5/engine/dev-utils/view.js';
|
|
|
+import ViewContainer from 'ckeditor5/engine/view/containerelement.js';
|
|
|
+import { widgetize } from 'ckeditor5/image/widget/utils.js';
|
|
|
+
|
|
|
+describe( 'WidgetEngine', () => {
|
|
|
+ let editor, document, viewDocument;
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ return VirtualTestEditor.create( {
|
|
|
+ features: [ WidgetEngine ]
|
|
|
+ } )
|
|
|
+ .then( newEditor => {
|
|
|
+ editor = newEditor;
|
|
|
+ document = editor.document;
|
|
|
+ viewDocument = editor.editing.view;
|
|
|
+ document.schema.registerItem( 'widget', '$block' );
|
|
|
+
|
|
|
+ buildModelConverter().for( editor.editing.modelToView )
|
|
|
+ .fromElement( 'widget' )
|
|
|
+ .toElement( () => widgetize( new ViewContainer( 'div' ) ) );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should be loaded', () => {
|
|
|
+ expect( editor.plugins.get( WidgetEngine ) ).to.be.instanceOf( WidgetEngine );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should apply fake view selection if model selection is on widget element', () => {
|
|
|
+ setModelData( document, '[<widget>foo bar</widget>]' );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[<div class="ck-widget ck-widget_selected" contenteditable="false">foo bar</div>]'
|
|
|
+ );
|
|
|
+ expect( viewDocument.selection.isFake ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should toggle selected class', () => {
|
|
|
+ setModelData( document, '[<widget>foo</widget>]' );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[<div class="ck-widget ck-widget_selected" contenteditable="false">foo</div>]'
|
|
|
+ );
|
|
|
+
|
|
|
+ document.enqueueChanges( () => {
|
|
|
+ document.selection.collapseToStart();
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getViewData( viewDocument ) ).to.equal(
|
|
|
+ '[]<div class="ck-widget" contenteditable="false">foo</div>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+} );
|