|
@@ -41,37 +41,40 @@ describe( 'Document', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return an iterator of all roots without the graveyard', () => {
|
|
it( 'should return an iterator of all roots without the graveyard', () => {
|
|
|
- doc.createRoot( 'a' );
|
|
|
|
|
- doc.createRoot( 'b' );
|
|
|
|
|
|
|
+ doc.createRoot( '$root', 'a' );
|
|
|
|
|
+ doc.createRoot( '$root', 'b' );
|
|
|
|
|
|
|
|
expect( Array.from( doc.rootNames ) ).to.deep.equal( [ 'a', 'b' ] );
|
|
expect( Array.from( doc.rootNames ) ).to.deep.equal( [ 'a', 'b' ] );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'createRoot', () => {
|
|
describe( 'createRoot', () => {
|
|
|
- it( 'should create a new RootElement, add it to roots map and return it', () => {
|
|
|
|
|
- let root = doc.createRoot( 'root' );
|
|
|
|
|
|
|
+ it( 'should create a new RootElement with default element and root names, add it to roots map and return it', () => {
|
|
|
|
|
+ let root = doc.createRoot();
|
|
|
|
|
|
|
|
expect( doc._roots.size ).to.equal( 2 );
|
|
expect( doc._roots.size ).to.equal( 2 );
|
|
|
expect( root ).to.be.instanceof( RootElement );
|
|
expect( root ).to.be.instanceof( RootElement );
|
|
|
expect( root.getChildCount() ).to.equal( 0 );
|
|
expect( root.getChildCount() ).to.equal( 0 );
|
|
|
expect( root ).to.have.property( 'name', '$root' );
|
|
expect( root ).to.have.property( 'name', '$root' );
|
|
|
- expect( root ).to.have.property( 'rootName', 'root' );
|
|
|
|
|
|
|
+ expect( root ).to.have.property( 'rootName', 'main' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should create a new RootElement with the specified name', () => {
|
|
|
|
|
- let root = doc.createRoot( 'root', 'foo' );
|
|
|
|
|
|
|
+ it( 'should create a new RootElement with custom element and root names, add it to roots map and return it', () => {
|
|
|
|
|
+ let root = doc.createRoot( 'customElementName', 'customRootName' );
|
|
|
|
|
|
|
|
- expect( root ).to.have.property( 'name', 'foo' );
|
|
|
|
|
- expect( root ).to.have.property( 'rootName', 'root' );
|
|
|
|
|
|
|
+ expect( doc._roots.size ).to.equal( 2 );
|
|
|
|
|
+ expect( root ).to.be.instanceof( RootElement );
|
|
|
|
|
+ expect( root.getChildCount() ).to.equal( 0 );
|
|
|
|
|
+ expect( root ).to.have.property( 'name', 'customElementName' );
|
|
|
|
|
+ expect( root ).to.have.property( 'rootName', 'customRootName' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should throw an error when trying to create a second root with the same name', () => {
|
|
it( 'should throw an error when trying to create a second root with the same name', () => {
|
|
|
- doc.createRoot( 'root', 'root' );
|
|
|
|
|
|
|
+ doc.createRoot( '$root', 'rootName' );
|
|
|
|
|
|
|
|
expect(
|
|
expect(
|
|
|
() => {
|
|
() => {
|
|
|
- doc.createRoot( 'root', 'root' );
|
|
|
|
|
|
|
+ doc.createRoot( '$root', 'rootName' );
|
|
|
}
|
|
}
|
|
|
).to.throw( CKEditorError, /document-createRoot-name-exists/ );
|
|
).to.throw( CKEditorError, /document-createRoot-name-exists/ );
|
|
|
} );
|
|
} );
|
|
@@ -79,8 +82,8 @@ describe( 'Document', () => {
|
|
|
|
|
|
|
|
describe( 'getRoot', () => {
|
|
describe( 'getRoot', () => {
|
|
|
it( 'should return a RootElement previously created with given name', () => {
|
|
it( 'should return a RootElement previously created with given name', () => {
|
|
|
- let newRoot = doc.createRoot( 'root' );
|
|
|
|
|
- let getRoot = doc.getRoot( 'root' );
|
|
|
|
|
|
|
+ let newRoot = doc.createRoot();
|
|
|
|
|
+ let getRoot = doc.getRoot();
|
|
|
|
|
|
|
|
expect( getRoot ).to.equal( newRoot );
|
|
expect( getRoot ).to.equal( newRoot );
|
|
|
} );
|
|
} );
|
|
@@ -96,9 +99,9 @@ describe( 'Document', () => {
|
|
|
|
|
|
|
|
describe( 'hasRoot', () => {
|
|
describe( 'hasRoot', () => {
|
|
|
it( 'should return true when Document has RootElement with given name', () => {
|
|
it( 'should return true when Document has RootElement with given name', () => {
|
|
|
- doc.createRoot( 'root' );
|
|
|
|
|
|
|
+ doc.createRoot();
|
|
|
|
|
|
|
|
- expect( doc.hasRoot( 'root' ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( doc.hasRoot( 'main' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false when Document does not have RootElement with given name', () => {
|
|
it( 'should return false when Document does not have RootElement with given name', () => {
|
|
@@ -233,9 +236,9 @@ describe( 'Document', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return the first root added to the document', () => {
|
|
it( 'should return the first root added to the document', () => {
|
|
|
- let rootA = doc.createRoot( 'rootA' );
|
|
|
|
|
- doc.createRoot( 'rootB' );
|
|
|
|
|
- doc.createRoot( 'rootC' );
|
|
|
|
|
|
|
+ let rootA = doc.createRoot( '$root', 'rootA' );
|
|
|
|
|
+ doc.createRoot( '$root', 'rootB' );
|
|
|
|
|
+ doc.createRoot( '$root', 'rootC' );
|
|
|
|
|
|
|
|
expect( doc._getDefaultRoot() ).to.equal( rootA );
|
|
expect( doc._getDefaultRoot() ).to.equal( rootA );
|
|
|
} );
|
|
} );
|