|
|
@@ -41,81 +41,7 @@ describe( 'Document', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'getRootNames()', () => {
|
|
|
- it( 'should return empty iterator if no roots exist', () => {
|
|
|
- expect( count( doc.getRootNames() ) ).to.equal( 0 );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should return an iterator of all roots without the graveyard', () => {
|
|
|
- doc.createRoot( '$root', 'a' );
|
|
|
- doc.createRoot( '$root', 'b' );
|
|
|
-
|
|
|
- expect( Array.from( doc.getRootNames() ) ).to.deep.equal( [ 'a', 'b' ] );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- describe( 'createRoot()', () => {
|
|
|
- it( 'should create a new RootElement with default element and root names, add it to roots map and return it', () => {
|
|
|
- const root = doc.createRoot();
|
|
|
-
|
|
|
- expect( doc.roots.size ).to.equal( 2 );
|
|
|
- expect( root ).to.be.instanceof( RootElement );
|
|
|
- expect( root.maxOffset ).to.equal( 0 );
|
|
|
- expect( root ).to.have.property( 'name', '$root' );
|
|
|
- expect( root ).to.have.property( 'rootName', 'main' );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should create a new RootElement with custom element and root names, add it to roots map and return it', () => {
|
|
|
- const root = doc.createRoot( 'customElementName', 'customRootName' );
|
|
|
-
|
|
|
- expect( doc.roots.size ).to.equal( 2 );
|
|
|
- expect( root ).to.be.instanceof( RootElement );
|
|
|
- expect( root.maxOffset ).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', () => {
|
|
|
- doc.createRoot( '$root', 'rootName' );
|
|
|
-
|
|
|
- expect(
|
|
|
- () => {
|
|
|
- doc.createRoot( '$root', 'rootName' );
|
|
|
- }
|
|
|
- ).to.throw( CKEditorError, /model-document-createRoot-name-exists/ );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- describe( 'getRoot()', () => {
|
|
|
- it( 'should return a RootElement previously created with given name', () => {
|
|
|
- const newRoot = doc.createRoot();
|
|
|
- const getRoot = doc.getRoot();
|
|
|
-
|
|
|
- expect( getRoot ).to.equal( newRoot );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should throw an error when trying to get non-existent root', () => {
|
|
|
- expect(
|
|
|
- () => {
|
|
|
- doc.getRoot( 'root' );
|
|
|
- }
|
|
|
- ).to.throw( CKEditorError, /model-document-getRoot-root-not-exist/ );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- describe( 'hasRoot()', () => {
|
|
|
- it( 'should return true when Document has RootElement with given name', () => {
|
|
|
- doc.createRoot();
|
|
|
-
|
|
|
- expect( doc.hasRoot( 'main' ) ).to.be.true;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should return false when Document does not have RootElement with given name', () => {
|
|
|
- expect( doc.hasRoot( 'noroot' ) ).to.be.false;
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- describe.skip( 'applyOperation()', () => {
|
|
|
+ describe( 'model#applyOperation listener', () => {
|
|
|
it( 'should increase document version, execute operation and fire event with proper data ' +
|
|
|
'when operation is a document operation', () => {
|
|
|
const changeCallback = sinon.spy();
|
|
|
@@ -180,7 +106,9 @@ describe( 'Document', () => {
|
|
|
|
|
|
it( 'should throw an error on the operation base version and the document version is different', () => {
|
|
|
const operation = {
|
|
|
- baseVersion: 1
|
|
|
+ baseVersion: 1,
|
|
|
+ isDocumentOperation: true,
|
|
|
+ _execute: () => {}
|
|
|
};
|
|
|
|
|
|
expect(
|
|
|
@@ -191,6 +119,80 @@ describe( 'Document', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'getRootNames()', () => {
|
|
|
+ it( 'should return empty iterator if no roots exist', () => {
|
|
|
+ expect( count( doc.getRootNames() ) ).to.equal( 0 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return an iterator of all roots without the graveyard', () => {
|
|
|
+ doc.createRoot( '$root', 'a' );
|
|
|
+ doc.createRoot( '$root', 'b' );
|
|
|
+
|
|
|
+ expect( Array.from( doc.getRootNames() ) ).to.deep.equal( [ 'a', 'b' ] );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'createRoot()', () => {
|
|
|
+ it( 'should create a new RootElement with default element and root names, add it to roots map and return it', () => {
|
|
|
+ const root = doc.createRoot();
|
|
|
+
|
|
|
+ expect( doc.roots.size ).to.equal( 2 );
|
|
|
+ expect( root ).to.be.instanceof( RootElement );
|
|
|
+ expect( root.maxOffset ).to.equal( 0 );
|
|
|
+ expect( root ).to.have.property( 'name', '$root' );
|
|
|
+ expect( root ).to.have.property( 'rootName', 'main' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create a new RootElement with custom element and root names, add it to roots map and return it', () => {
|
|
|
+ const root = doc.createRoot( 'customElementName', 'customRootName' );
|
|
|
+
|
|
|
+ expect( doc.roots.size ).to.equal( 2 );
|
|
|
+ expect( root ).to.be.instanceof( RootElement );
|
|
|
+ expect( root.maxOffset ).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', () => {
|
|
|
+ doc.createRoot( '$root', 'rootName' );
|
|
|
+
|
|
|
+ expect(
|
|
|
+ () => {
|
|
|
+ doc.createRoot( '$root', 'rootName' );
|
|
|
+ }
|
|
|
+ ).to.throw( CKEditorError, /model-document-createRoot-name-exists/ );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'getRoot()', () => {
|
|
|
+ it( 'should return a RootElement previously created with given name', () => {
|
|
|
+ const newRoot = doc.createRoot();
|
|
|
+ const getRoot = doc.getRoot();
|
|
|
+
|
|
|
+ expect( getRoot ).to.equal( newRoot );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should throw an error when trying to get non-existent root', () => {
|
|
|
+ expect(
|
|
|
+ () => {
|
|
|
+ doc.getRoot( 'root' );
|
|
|
+ }
|
|
|
+ ).to.throw( CKEditorError, /model-document-getRoot-root-not-exist/ );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'hasRoot()', () => {
|
|
|
+ it( 'should return true when Document has RootElement with given name', () => {
|
|
|
+ doc.createRoot();
|
|
|
+
|
|
|
+ expect( doc.hasRoot( 'main' ) ).to.be.true;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return false when Document does not have RootElement with given name', () => {
|
|
|
+ expect( doc.hasRoot( 'noroot' ) ).to.be.false;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'selection', () => {
|
|
|
it( 'should get updated attributes whenever attribute operation is applied', () => {
|
|
|
sinon.spy( doc.selection, '_updateAttributes' );
|
|
|
@@ -523,8 +525,10 @@ describe( 'Document', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- // @TODO: What for is this test?
|
|
|
- it.skip( 'should be correctly converted to json', () => {
|
|
|
- expect( jsonParseStringify( doc ).selection ).to.equal( '[engine.model.DocumentSelection]' );
|
|
|
+ it( 'should be correctly converted to json', () => {
|
|
|
+ const serialized = jsonParseStringify( doc );
|
|
|
+
|
|
|
+ expect( serialized.selection ).to.equal( '[engine.model.DocumentSelection]' );
|
|
|
+ expect( serialized.model ).to.equal( '[engine.model.Model]' );
|
|
|
} );
|
|
|
} );
|