|
|
@@ -8,19 +8,19 @@ import Editor from '../../src/editor/editor';
|
|
|
|
|
|
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
|
|
|
import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
|
|
|
-import View from '@ckeditor/ckeditor5-ui/src/view';
|
|
|
|
|
|
import testUtils from '../_utils/utils';
|
|
|
|
|
|
+/* global document */
|
|
|
+
|
|
|
describe( 'EditorUI', () => {
|
|
|
- let editor, view, ui;
|
|
|
+ let editor, ui;
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
beforeEach( () => {
|
|
|
editor = new Editor();
|
|
|
- view = new View();
|
|
|
- ui = new EditorUI( editor, view );
|
|
|
+ ui = new EditorUI( editor );
|
|
|
} );
|
|
|
|
|
|
afterEach( () => {
|
|
|
@@ -32,10 +32,6 @@ describe( 'EditorUI', () => {
|
|
|
expect( ui.editor ).to.equal( editor );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set #view', () => {
|
|
|
- expect( ui.view ).to.equal( view );
|
|
|
- } );
|
|
|
-
|
|
|
it( 'should create #componentFactory factory', () => {
|
|
|
expect( ui.componentFactory ).to.be.instanceOf( ComponentFactory );
|
|
|
} );
|
|
|
@@ -44,6 +40,10 @@ describe( 'EditorUI', () => {
|
|
|
expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should have #element getter', () => {
|
|
|
+ expect( ui.element ).to.null;
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should fire update event after viewDocument#layoutChanged', () => {
|
|
|
const spy = sinon.spy();
|
|
|
|
|
|
@@ -84,12 +84,65 @@ describe( 'EditorUI', () => {
|
|
|
sinon.assert.called( spy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should destroy the #view', () => {
|
|
|
- const spy = sinon.spy( view, 'destroy' );
|
|
|
+ it( 'should reset editables array', () => {
|
|
|
+ ui._editableElements.set( 'foo', {} );
|
|
|
+ ui._editableElements.set( 'bar', {} );
|
|
|
+
|
|
|
+ expect( ui._editableElements.size ).to.equal( 2 );
|
|
|
|
|
|
ui.destroy();
|
|
|
|
|
|
- sinon.assert.called( spy );
|
|
|
+ expect( ui._editableElements.size ).to.equal( 0 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'getEditableElement()', () => {
|
|
|
+ it( 'should return editable element (default root name)', () => {
|
|
|
+ const ui = new EditorUI( editor );
|
|
|
+ const editableMock = { name: 'main', element: document.createElement( 'div' ) };
|
|
|
+
|
|
|
+ ui._editableElements.set( editableMock.name, editableMock.element );
|
|
|
+
|
|
|
+ expect( ui.getEditableElement() ).to.equal( editableMock.element );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return editable element (custom root name)', () => {
|
|
|
+ const ui = new EditorUI( editor );
|
|
|
+ const editableMock1 = { name: 'root1', element: document.createElement( 'div' ) };
|
|
|
+ const editableMock2 = { name: 'root2', element: document.createElement( 'p' ) };
|
|
|
+
|
|
|
+ ui._editableElements.set( editableMock1.name, editableMock1.element );
|
|
|
+ ui._editableElements.set( editableMock2.name, editableMock2.element );
|
|
|
+
|
|
|
+ expect( ui.getEditableElement( 'root1' ) ).to.equal( editableMock1.element );
|
|
|
+ expect( ui.getEditableElement( 'root2' ) ).to.equal( editableMock2.element );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return null if editable with specified name does not exist', () => {
|
|
|
+ const ui = new EditorUI( editor );
|
|
|
+
|
|
|
+ expect( ui.getEditableElement() ).to.be.undefined;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'getEditableElementsNames()', () => {
|
|
|
+ it( 'should return iterable object of names', () => {
|
|
|
+ const ui = new EditorUI( editor );
|
|
|
+ const editableMock1 = { name: 'main', element: document.createElement( 'div' ) };
|
|
|
+ const editableMock2 = { name: 'root2', element: document.createElement( 'p' ) };
|
|
|
+
|
|
|
+ ui._editableElements.set( editableMock1.name, editableMock1.element );
|
|
|
+ ui._editableElements.set( editableMock2.name, editableMock2.element );
|
|
|
+
|
|
|
+ const names = ui.getEditableElementsNames();
|
|
|
+ expect( names[ Symbol.iterator ] ).to.instanceof( Function );
|
|
|
+ expect( Array.from( names ) ).to.deep.equal( [ 'main', 'root2' ] );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return empty array if no editables', () => {
|
|
|
+ const ui = new EditorUI( editor );
|
|
|
+
|
|
|
+ expect( ui.getEditableElementsNames() ).to.be.empty;
|
|
|
} );
|
|
|
} );
|
|
|
} );
|