Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Used EditorUI as a BalloonEditorUI parent class. #21

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 3 additions & 39 deletions src/ballooneditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,15 @@
* @module editor-balloon/ballooneditorui
*/

import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus';

/**
* The balloon editor UI class.
*
* @implements module:core/editor/editorui~EditorUI
* @extends module:core/editor/editorui~EditorUI
*/
export default class BalloonEditorUI {
/**
* Creates an instance of the balloon editor UI class.
*
* @param {module:core/editor/editor~Editor} editor The editor instance.
* @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI.
*/
constructor( editor, view ) {
/**
* @inheritDoc
*/
this.editor = editor;

/**
* @inheritDoc
*/
this.view = view;

/**
* @inheritDoc
*/
this.componentFactory = new ComponentFactory( editor );

/**
* @inheritDoc
*/
this.focusTracker = new FocusTracker();
}

export default class BalloonEditorUI extends EditorUI {
/**
* Initializes the UI.
*/
Expand Down Expand Up @@ -80,11 +51,4 @@ export default class BalloonEditorUI {
}
} );
}

/**
* Destroys the UI.
*/
destroy() {
this.view.destroy();
}
}
42 changes: 11 additions & 31 deletions tests/ballooneditorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@

/* globals Event */

import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
import BalloonEditorUI from '../src/ballooneditorui';
import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui';
import BalloonEditorUIView from '../src/ballooneditoruiview';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import BalloonToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/balloon/balloontoolbar';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';

import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

testUtils.createSinonSandbox();

describe( 'BalloonEditorUI', () => {
let editor, view, ui;
Expand All @@ -34,20 +37,8 @@ describe( 'BalloonEditorUI', () => {
} );

describe( 'constructor()', () => {
it( 'sets #editor', () => {
expect( ui.editor ).to.equal( editor );
} );

it( 'sets #view', () => {
expect( ui.view ).to.be.instanceOf( BalloonEditorUIView );
} );

it( 'creates #componentFactory factory', () => {
expect( ui.componentFactory ).to.be.instanceOf( ComponentFactory );
} );

it( 'creates #focusTracker', () => {
expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
it( 'extends EditorUI', () => {
expect( ui ).to.instanceof( EditorUI );
} );
} );

Expand All @@ -58,10 +49,10 @@ describe( 'BalloonEditorUI', () => {

it( 'initializes keyboard navigation between view#toolbar and view#editable', () => {
const toolbar = editor.plugins.get( 'BalloonToolbar' );
const toolbarFocusSpy = sinon.stub( toolbar.toolbarView, 'focus' ).returns( {} );
const toolbarShowSpy = sinon.stub( toolbar, 'show' ).returns( {} );
const toolbarHideSpy = sinon.stub( toolbar, 'hide' ).returns( {} );
const editingFocusSpy = sinon.stub( editor.editing.view, 'focus' ).returns( {} );
const toolbarFocusSpy = testUtils.sinon.stub( toolbar.toolbarView, 'focus' ).returns( {} );
const toolbarShowSpy = testUtils.sinon.stub( toolbar, 'show' ).returns( {} );
const toolbarHideSpy = testUtils.sinon.stub( toolbar, 'hide' ).returns( {} );
const editingFocusSpy = testUtils.sinon.stub( editor.editing.view, 'focus' ).returns( {} );

ui.focusTracker.isFocused = true;

Expand Down Expand Up @@ -132,17 +123,6 @@ describe( 'BalloonEditorUI', () => {
} );
} );
} );

describe( 'destroy()', () => {
it( 'destroys the #view', () => {
const spy = sinon.spy( view, 'destroy' );

return editor.destroy()
.then( () => {
sinon.assert.calledOnce( spy );
} );
} );
} );
} );

class VirtualBalloonTestEditor extends VirtualTestEditor {
Expand Down