|
|
@@ -8,6 +8,7 @@ import BalloonToolbar from '../../../src/toolbar/balloon/balloontoolbar';
|
|
|
import ContextualBalloon from '../../../src/panel/balloon/contextualballoon';
|
|
|
import BalloonPanelView from '../../../src/panel/balloon/balloonpanelview';
|
|
|
import ToolbarView from '../../../src/toolbar/toolbarview';
|
|
|
+import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
|
|
|
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
|
|
|
@@ -143,6 +144,28 @@ describe( 'BalloonToolbar', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'focusTracker', () => {
|
|
|
+ it( 'should be defined', () => {
|
|
|
+ expect( balloonToolbar.focusTracker ).to.instanceof( FocusTracker );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'it should track focus of #editableElement', () => {
|
|
|
+ expect( balloonToolbar.focusTracker.isFocused ).to.false;
|
|
|
+
|
|
|
+ editor.ui.view.editableElement.dispatchEvent( new Event( 'focus' ) );
|
|
|
+
|
|
|
+ expect( balloonToolbar.focusTracker.isFocused ).to.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'it should track focus of #toolbarView.element', () => {
|
|
|
+ expect( balloonToolbar.focusTracker.isFocused ).to.false;
|
|
|
+
|
|
|
+ balloonToolbar.toolbarView.element.dispatchEvent( new Event( 'focus' ) );
|
|
|
+
|
|
|
+ expect( balloonToolbar.focusTracker.isFocused ).to.true;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'show()', () => {
|
|
|
let balloonAddSpy, backwardSelectionRect, forwardSelectionRect;
|
|
|
|
|
|
@@ -459,72 +482,49 @@ describe( 'BalloonToolbar', () => {
|
|
|
sinon.assert.calledOnce( hidePanelSpy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should hide on editable blur', () => {
|
|
|
- editingView.document.isFocused = true;
|
|
|
-
|
|
|
- balloonToolbar.fire( '_selectionChangeDebounced' );
|
|
|
+ it( 'should show on #focusTracker focus', () => {
|
|
|
+ balloonToolbar.focusTracker.isFocused = false;
|
|
|
|
|
|
- const stub = sandbox.stub( balloon, 'visibleView' ).get( () => balloonToolbar.toolbarView );
|
|
|
-
|
|
|
- sinon.assert.calledOnce( showPanelSpy );
|
|
|
+ sinon.assert.notCalled( showPanelSpy );
|
|
|
sinon.assert.notCalled( hidePanelSpy );
|
|
|
|
|
|
- editingView.document.isFocused = false;
|
|
|
+ balloonToolbar.focusTracker.isFocused = true;
|
|
|
|
|
|
sinon.assert.calledOnce( showPanelSpy );
|
|
|
- sinon.assert.calledOnce( hidePanelSpy );
|
|
|
-
|
|
|
- stub.restore();
|
|
|
+ sinon.assert.notCalled( hidePanelSpy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not hide on editable blur when #toolbarView gets focus', () => {
|
|
|
- editingView.document.isFocused = true;
|
|
|
-
|
|
|
- balloonToolbar.fire( '_selectionChangeDebounced' );
|
|
|
+ it( 'should hide on #focusTracker blur', () => {
|
|
|
+ balloonToolbar.focusTracker.isFocused = true;
|
|
|
|
|
|
const stub = sandbox.stub( balloon, 'visibleView' ).get( () => balloonToolbar.toolbarView );
|
|
|
|
|
|
sinon.assert.calledOnce( showPanelSpy );
|
|
|
sinon.assert.notCalled( hidePanelSpy );
|
|
|
|
|
|
- balloonToolbar.toolbarView.focusTracker.isFocused = true;
|
|
|
- editingView.document.isFocused = false;
|
|
|
+ balloonToolbar.focusTracker.isFocused = false;
|
|
|
|
|
|
sinon.assert.calledOnce( showPanelSpy );
|
|
|
- sinon.assert.notCalled( hidePanelSpy );
|
|
|
+ sinon.assert.calledOnce( hidePanelSpy );
|
|
|
|
|
|
stub.restore();
|
|
|
} );
|
|
|
|
|
|
- it( 'should not hide on editable blur when #toolbarView is not visible', () => {
|
|
|
- editingView.document.isFocused = true;
|
|
|
-
|
|
|
- balloonToolbar.fire( '_selectionChangeDebounced' );
|
|
|
+ it( 'should not hide on #focusTracker blur when toolbar is not in the balloon stack', () => {
|
|
|
+ balloonToolbar.focusTracker.isFocused = true;
|
|
|
|
|
|
const stub = sandbox.stub( balloon, 'visibleView' ).get( () => null );
|
|
|
|
|
|
sinon.assert.calledOnce( showPanelSpy );
|
|
|
sinon.assert.notCalled( hidePanelSpy );
|
|
|
|
|
|
- editingView.document.isFocused = false;
|
|
|
+ balloonToolbar.focusTracker.isFocused = false;
|
|
|
|
|
|
sinon.assert.calledOnce( showPanelSpy );
|
|
|
sinon.assert.notCalled( hidePanelSpy );
|
|
|
|
|
|
stub.restore();
|
|
|
} );
|
|
|
-
|
|
|
- it( 'should show when editable gets focus', () => {
|
|
|
- editingView.document.isFocused = false;
|
|
|
-
|
|
|
- sinon.assert.notCalled( showPanelSpy );
|
|
|
- sinon.assert.notCalled( hidePanelSpy );
|
|
|
-
|
|
|
- editingView.document.isFocused = true;
|
|
|
-
|
|
|
- sinon.assert.calledOnce( showPanelSpy );
|
|
|
- sinon.assert.notCalled( hidePanelSpy );
|
|
|
- } );
|
|
|
} );
|
|
|
|
|
|
describe( 'show event', () => {
|