|
|
@@ -17,11 +17,11 @@ describe( 'DataController', () => {
|
|
|
|
|
|
describe( 'insertContent', () => {
|
|
|
it( 'uses the passed batch', () => {
|
|
|
- doc = new Document();
|
|
|
+ const doc = new Document();
|
|
|
doc.createRoot();
|
|
|
doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
|
- dataController = new DataController( doc );
|
|
|
+ const dataController = new DataController( doc );
|
|
|
|
|
|
const batch = doc.batch();
|
|
|
|
|
|
@@ -32,6 +32,36 @@ describe( 'DataController', () => {
|
|
|
expect( batch.deltas.length ).to.be.above( 0 );
|
|
|
} );
|
|
|
|
|
|
+ it( 'accepts DocumentFragment', () => {
|
|
|
+ const doc = new Document();
|
|
|
+ const dataController = new DataController( doc );
|
|
|
+ const batch = doc.batch();
|
|
|
+
|
|
|
+ doc.createRoot();
|
|
|
+ doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
+
|
|
|
+ setData( doc, 'x[]x' );
|
|
|
+
|
|
|
+ insertContent( dataController, new DocumentFragment( [ new Text( 'a' ) ] ), doc.selection, batch );
|
|
|
+
|
|
|
+ expect( getData( doc ) ).to.equal( 'xa[]x' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'accepts Text', () => {
|
|
|
+ const doc = new Document();
|
|
|
+ const dataController = new DataController( doc );
|
|
|
+ const batch = doc.batch();
|
|
|
+
|
|
|
+ doc.createRoot();
|
|
|
+ doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
+
|
|
|
+ setData( doc, 'x[]x' );
|
|
|
+
|
|
|
+ insertContent( dataController, new Text( 'a' ), doc.selection, batch );
|
|
|
+
|
|
|
+ expect( getData( doc ) ).to.equal( 'xa[]x' );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'in simple scenarios', () => {
|
|
|
beforeEach( () => {
|
|
|
doc = new Document();
|
|
|
@@ -604,6 +634,8 @@ describe( 'DataController', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ // Helper function that parses given content and inserts it at the cursor position.
|
|
|
+ //
|
|
|
// @param {module:engine/model/item~Item|String} content
|
|
|
function insertHelper( content ) {
|
|
|
if ( typeof content == 'string' ) {
|
|
|
@@ -612,10 +644,6 @@ describe( 'DataController', () => {
|
|
|
} );
|
|
|
}
|
|
|
|
|
|
- if ( !( content instanceof DocumentFragment ) ) {
|
|
|
- content = new DocumentFragment( [ content ] );
|
|
|
- }
|
|
|
-
|
|
|
insertContent( dataController, content, doc.selection );
|
|
|
}
|
|
|
} );
|