|
@@ -13,12 +13,14 @@ import ImageTextAlternative from '../src/imagetextalternative';
|
|
|
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
|
|
+import ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
|
|
|
|
|
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
|
|
|
|
|
describe( 'Image', () => {
|
|
describe( 'Image', () => {
|
|
|
- let editor, document, viewDocument;
|
|
|
|
|
|
|
+ let editorElement, editor, document, viewDocument;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
- const editorElement = window.document.createElement( 'div' );
|
|
|
|
|
|
|
+ editorElement = window.document.createElement( 'div' );
|
|
|
window.document.body.appendChild( editorElement );
|
|
window.document.body.appendChild( editorElement );
|
|
|
|
|
|
|
|
return ClassicTestEditor.create( editorElement, {
|
|
return ClassicTestEditor.create( editorElement, {
|
|
@@ -31,6 +33,12 @@ describe( 'Image', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ afterEach( () => {
|
|
|
|
|
+ editorElement.remove();
|
|
|
|
|
+
|
|
|
|
|
+ return editor.destroy();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should be loaded', () => {
|
|
it( 'should be loaded', () => {
|
|
|
expect( editor.plugins.get( Image ) ).to.instanceOf( Image );
|
|
expect( editor.plugins.get( Image ) ).to.instanceOf( Image );
|
|
|
} );
|
|
} );
|
|
@@ -47,6 +55,39 @@ describe( 'Image', () => {
|
|
|
expect( editor.plugins.get( ImageTextAlternative ) ).to.instanceOf( ImageTextAlternative );
|
|
expect( editor.plugins.get( ImageTextAlternative ) ).to.instanceOf( ImageTextAlternative );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should prevent ContextualToolbar of being displayed when Image is selected', () => {
|
|
|
|
|
+ return ClassicTestEditor.create( editorElement, {
|
|
|
|
|
+ plugins: [ Image, ContextualToolbar, Paragraph ]
|
|
|
|
|
+ } )
|
|
|
|
|
+ .then( newEditor => {
|
|
|
|
|
+ const balloon = newEditor.plugins.get( 'ui/contextualballoon' );
|
|
|
|
|
+ const contextualToolbar = newEditor.plugins.get( 'ui/contextualtoolbar' );
|
|
|
|
|
+
|
|
|
|
|
+ newEditor.editing.view.isFocused = true;
|
|
|
|
|
+
|
|
|
|
|
+ // When image is selected along with text.
|
|
|
|
|
+ setModelData( newEditor.document, '<paragraph>fo[o</paragraph><image alt="alt text" src="foo.png"></image>]' );
|
|
|
|
|
+
|
|
|
|
|
+ contextualToolbar._showPanel();
|
|
|
|
|
+
|
|
|
|
|
+ // ContextualToolbar should be visible.
|
|
|
|
|
+ expect( balloon.visibleView ).to.equal( contextualToolbar.toolbarView );
|
|
|
|
|
+
|
|
|
|
|
+ // When only image is selected.
|
|
|
|
|
+ setModelData( newEditor.document, '<paragraph>foo</paragraph>[<image alt="alt text" src="foo.png"></image>]' );
|
|
|
|
|
+
|
|
|
|
|
+ contextualToolbar._showPanel();
|
|
|
|
|
+
|
|
|
|
|
+ // ContextualToolbar should not be visible.
|
|
|
|
|
+ expect( balloon.visibleView ).to.null;
|
|
|
|
|
+
|
|
|
|
|
+ // Cleaning up.
|
|
|
|
|
+ editorElement.remove();
|
|
|
|
|
+
|
|
|
|
|
+ return newEditor.destroy();
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'selection', () => {
|
|
describe( 'selection', () => {
|
|
|
it( 'should create fake selection', () => {
|
|
it( 'should create fake selection', () => {
|
|
|
setModelData( document, '[<image alt="alt text" src="foo.png"></image>]' );
|
|
setModelData( document, '[<image alt="alt text" src="foo.png"></image>]' );
|