|
|
@@ -11,10 +11,12 @@ import ContainerElement from '/ckeditor5/engine/view/containerelement.js';
|
|
|
import EditableElement from '/ckeditor5/engine/view/editableelement.js';
|
|
|
import RootEditableElement from '/ckeditor5/engine/view/rooteditableelement.js';
|
|
|
|
|
|
+import createDocumentMock from '/tests/engine/view/_utils/createdocumentmock.js';
|
|
|
+
|
|
|
describe( 'RootEditableElement', () => {
|
|
|
describe( 'constructor', () => {
|
|
|
it( 'should create an element with default root name', () => {
|
|
|
- const root = new RootEditableElement( {}, 'div' );
|
|
|
+ const root = new RootEditableElement( createDocumentMock(), 'div' );
|
|
|
|
|
|
expect( root ).to.be.instanceof( EditableElement );
|
|
|
expect( root ).to.be.instanceof( ContainerElement );
|
|
|
@@ -27,7 +29,7 @@ describe( 'RootEditableElement', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should create an element with custom root name', () => {
|
|
|
- const root = new RootEditableElement( {}, 'h1', 'header' );
|
|
|
+ const root = new RootEditableElement( createDocumentMock(), 'h1', 'header' );
|
|
|
|
|
|
expect( root.rootName ).to.equal( 'header' );
|
|
|
expect( root.name ).to.equal( 'h1' );
|
|
|
@@ -38,8 +40,17 @@ describe( 'RootEditableElement', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'isFocused', () => {
|
|
|
+ let docMock, viewMain, viewHeader;
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ docMock = createDocumentMock();
|
|
|
+
|
|
|
+ viewMain = new RootEditableElement( docMock, 'div' );
|
|
|
+ viewHeader = new RootEditableElement( docMock, 'h1', 'header' );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should be observable', () => {
|
|
|
- const root = new RootEditableElement( {}, 'div' );
|
|
|
+ const root = new RootEditableElement( createDocumentMock(), 'div' );
|
|
|
|
|
|
expect( root.isFocused ).to.be.false;
|
|
|
|
|
|
@@ -53,11 +64,28 @@ describe( 'RootEditableElement', () => {
|
|
|
|
|
|
expect( isFocusedSpy.calledOnce ).to.be.true;
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should change isFocused when focusedEditable changes', () => {
|
|
|
+ docMock.focusedEditable = viewMain;
|
|
|
+
|
|
|
+ expect( viewMain.isFocused ).to.be.true;
|
|
|
+ expect( viewHeader.isFocused ).to.be.false;
|
|
|
+
|
|
|
+ docMock.focusedEditable = viewHeader;
|
|
|
+
|
|
|
+ expect( viewMain.isFocused ).to.be.false;
|
|
|
+ expect( viewHeader.isFocused ).to.be.true;
|
|
|
+
|
|
|
+ docMock.focusedEditable = null;
|
|
|
+
|
|
|
+ expect( viewMain.isFocused ).to.be.false;
|
|
|
+ expect( viewHeader.isFocused ).to.be.false;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'isReadOnly', () => {
|
|
|
it( 'should be observable', () => {
|
|
|
- const root = new RootEditableElement( {}, 'div' );
|
|
|
+ const root = new RootEditableElement( createDocumentMock(), 'div' );
|
|
|
|
|
|
expect( root.isReadOnly ).to.be.false;
|
|
|
|
|
|
@@ -75,7 +103,7 @@ describe( 'RootEditableElement', () => {
|
|
|
|
|
|
describe( 'getDocument', ()=> {
|
|
|
it( 'should return document', () => {
|
|
|
- const docMock = {};
|
|
|
+ const docMock = createDocumentMock();
|
|
|
const root = new RootEditableElement( docMock, 'div' );
|
|
|
|
|
|
expect( root.getDocument() ).to.equal( docMock );
|