|
|
@@ -13,6 +13,8 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
|
|
|
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
|
|
|
|
+/* global Event */
|
|
|
+
|
|
|
describe( 'ImageAlternateText', () => {
|
|
|
let editor, plugin, command, balloonPanel, form;
|
|
|
|
|
|
@@ -72,31 +74,6 @@ describe( 'ImageAlternateText', () => {
|
|
|
sinon.assert.calledOnce( spy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should hide ImageToolbar on execute', () => {
|
|
|
- const editorElement = global.document.createElement( 'div' );
|
|
|
- global.document.body.appendChild( editorElement );
|
|
|
-
|
|
|
- return ClassicTestEditor.create( editorElement, {
|
|
|
- plugins: [ ImageAlternateText, Image, ImageToolbar ],
|
|
|
- image: {
|
|
|
- toolbar: [ 'imageAlternateText' ]
|
|
|
- }
|
|
|
- } )
|
|
|
- .then( newEditor => {
|
|
|
- newEditor.editing.view.attachDomRoot( editorElement );
|
|
|
- const button = newEditor.ui.componentFactory.create( 'imageAlternateText' );
|
|
|
- const toolbarPlugin = newEditor.plugins.get( ImageToolbar );
|
|
|
-
|
|
|
- const spy = sinon.spy( toolbarPlugin, 'hide' );
|
|
|
- setData( newEditor.document, '[<image src="" alt="foo bar"></image>]' );
|
|
|
- button.fire( 'execute' );
|
|
|
-
|
|
|
- sinon.assert.calledOnce( spy );
|
|
|
-
|
|
|
- newEditor.destroy();
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
it( 'should set alt attribute value to textarea and select it', () => {
|
|
|
const spy = sinon.spy( form.lebeledInput, 'select' );
|
|
|
setData( editor.document, '[<image src="" alt="foo bar"></image>]' );
|
|
|
@@ -175,6 +152,73 @@ describe( 'ImageAlternateText', () => {
|
|
|
sinon.assert.called( hidePanelSpy );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'mouse', () => {
|
|
|
+ it( 'should close and not focus editable on click outside the panel', () => {
|
|
|
+ balloonPanel.isVisible = true;
|
|
|
+ global.document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
|
|
|
+
|
|
|
+ sinon.assert.called( hidePanelSpy );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not close on click inside the panel', () => {
|
|
|
+ balloonPanel.isVisible = true;
|
|
|
+ balloonPanel.element.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
|
|
|
+
|
|
|
+ sinon.assert.notCalled( hidePanelSpy );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'working with ImageToolbar', () => {
|
|
|
+ let editor, button, imageToolbarPlugin, plugin;
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ const editorElement = global.document.createElement( 'div' );
|
|
|
+ global.document.body.appendChild( editorElement );
|
|
|
+
|
|
|
+ return ClassicTestEditor.create( editorElement, {
|
|
|
+ plugins: [ ImageAlternateText, Image, ImageToolbar ],
|
|
|
+ image: {
|
|
|
+ toolbar: [ 'imageAlternateText' ]
|
|
|
+ }
|
|
|
+ } )
|
|
|
+ .then( newEditor => {
|
|
|
+ editor = newEditor;
|
|
|
+ editor.editing.view.attachDomRoot( editorElement );
|
|
|
+ button = newEditor.ui.componentFactory.create( 'imageAlternateText' );
|
|
|
+ imageToolbarPlugin = newEditor.plugins.get( ImageToolbar );
|
|
|
+ plugin = editor.plugins.get( ImageAlternateText );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ afterEach( () => editor.destroy() );
|
|
|
+
|
|
|
+ it( 'should hide ImageToolbar when visible', () => {
|
|
|
+ setData( editor.document, '[<image src="" alt="foo bar"></image>]' );
|
|
|
+ const spy = sinon.spy( imageToolbarPlugin, 'hide' );
|
|
|
+ button.fire( 'execute' );
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'ImageToolbar should not show when alternate text panel is visible', () => {
|
|
|
+ setData( editor.document, '[<image src="" alt="foo bar"></image>]' );
|
|
|
+ button.fire( 'execute' );
|
|
|
+ const spy = sinon.spy( imageToolbarPlugin, 'show' );
|
|
|
+ editor.editing.view.render();
|
|
|
+
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'ImageToolbar should show when alternate text panel is not visible', () => {
|
|
|
+ setData( editor.document, '[<image src="" alt="foo bar"></image>]' );
|
|
|
+ button.fire( 'execute' );
|
|
|
+ const spy = sinon.spy( imageToolbarPlugin, 'show' );
|
|
|
+ plugin.balloonPanel.isVisible = false;
|
|
|
+
|
|
|
+ sinon.assert.called( spy );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|