|
@@ -47,7 +47,7 @@ describe( 'Document', () => {
|
|
|
baseVersion: 0,
|
|
baseVersion: 0,
|
|
|
isDocumentOperation: true,
|
|
isDocumentOperation: true,
|
|
|
_execute: sinon.stub().returns( data ),
|
|
_execute: sinon.stub().returns( data ),
|
|
|
- _validate: () => {}
|
|
|
|
|
|
|
+ _validate: () => { }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
delta = new Delta();
|
|
delta = new Delta();
|
|
@@ -89,7 +89,7 @@ describe( 'Document', () => {
|
|
|
const operation = {
|
|
const operation = {
|
|
|
baseVersion: 1,
|
|
baseVersion: 1,
|
|
|
isDocumentOperation: true,
|
|
isDocumentOperation: true,
|
|
|
- _execute: () => {}
|
|
|
|
|
|
|
+ _execute: () => { }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
expect(
|
|
@@ -321,8 +321,22 @@ describe( 'Document', () => {
|
|
|
expect( spy.calledOnce ).to.be.true;
|
|
expect( spy.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should be fired if there was a change in a document tree in a change block and have a batch as param', () => {
|
|
|
|
|
- doc.createRoot();
|
|
|
|
|
|
|
+ it( 'should be fired if there was a selection change in an (enqueue)change block', () => {
|
|
|
|
|
+ const root = doc.createRoot();
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
|
|
+
|
|
|
|
|
+ root._appendChild( new Text( 'foo' ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change', spy );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( Range.createFromParentsAndOffsets( root, 2, root, 2 ) );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not be fired if writer was used on non-document tree', () => {
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
|
|
|
|
|
|
doc.on( 'change', ( evt, batch ) => {
|
|
doc.on( 'change', ( evt, batch ) => {
|
|
@@ -330,43 +344,97 @@ describe( 'Document', () => {
|
|
|
expect( batch ).to.be.instanceof( Batch );
|
|
expect( batch ).to.be.instanceof( Batch );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- model.enqueueChange( writer => {
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ const docFrag = writer.createDocumentFragment();
|
|
|
|
|
+ writer.insertText( 'foo', docFrag, 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( spy.calledOnce ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'event change:data', () => {
|
|
|
|
|
+ it( 'should be fired if there was a change in a document tree in a change block and have a batch as a param', () => {
|
|
|
|
|
+ doc.createRoot();
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change:data', ( evt, batch ) => {
|
|
|
|
|
+ spy();
|
|
|
|
|
+ expect( batch ).to.be.instanceof( Batch );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
writer.insertText( 'foo', doc.getRoot(), 0 );
|
|
writer.insertText( 'foo', doc.getRoot(), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( spy.calledOnce ).to.be.true;
|
|
expect( spy.calledOnce ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should be fired if there was a selection change in an (enqueue)change block', () => {
|
|
|
|
|
|
|
+ it( 'should be fired before the change event', () => {
|
|
|
doc.createRoot();
|
|
doc.createRoot();
|
|
|
|
|
+
|
|
|
|
|
+ const callOrder = [];
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change:data', () => {
|
|
|
|
|
+ callOrder.push( 1 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change', () => {
|
|
|
|
|
+ callOrder.push( 2 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.insertText( 'foo', doc.getRoot(), 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( callOrder ).to.deep.equal( [ 1, 2 ] );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not be fired if only selection changes', () => {
|
|
|
|
|
+ const root = doc.createRoot();
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
|
|
|
|
|
|
- const root = doc.getRoot();
|
|
|
|
|
root._appendChild( new Text( 'foo' ) );
|
|
root._appendChild( new Text( 'foo' ) );
|
|
|
|
|
|
|
|
- doc.on( 'change', spy );
|
|
|
|
|
|
|
+ doc.on( 'change:data', spy );
|
|
|
|
|
|
|
|
model.change( writer => {
|
|
model.change( writer => {
|
|
|
writer.setSelection( Range.createFromParentsAndOffsets( root, 2, root, 2 ) );
|
|
writer.setSelection( Range.createFromParentsAndOffsets( root, 2, root, 2 ) );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( spy.calledOnce ).to.be.true;
|
|
|
|
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not be fired if writer was used on non-document tree', () => {
|
|
|
|
|
|
|
+ it( 'should fire if default marker operation is applied', () => {
|
|
|
|
|
+ const root = doc.createRoot();
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
|
|
|
|
|
|
- doc.on( 'change', ( evt, batch ) => {
|
|
|
|
|
- spy();
|
|
|
|
|
- expect( batch ).to.be.instanceof( Batch );
|
|
|
|
|
|
|
+ root._appendChild( new Text( 'foo' ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change:data', spy );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ const range = Range.createFromParentsAndOffsets( root, 2, root, 4 );
|
|
|
|
|
+ writer.addMarker( 'name', { range, usingOperation: true } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not fire if the marker operation is applied and marker does not affect data', () => {
|
|
|
|
|
+ const root = doc.createRoot();
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
|
|
+
|
|
|
|
|
+ root._appendChild( new Text( 'foo' ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.on( 'change:data', spy );
|
|
|
|
|
+
|
|
|
model.change( writer => {
|
|
model.change( writer => {
|
|
|
- const docFrag = writer.createDocumentFragment();
|
|
|
|
|
- writer.insertText( 'foo', docFrag, 0 );
|
|
|
|
|
|
|
+ const range = Range.createFromParentsAndOffsets( root, 2, root, 4 );
|
|
|
|
|
+ writer.addMarker( 'name', { range, usingOperation: true, affectsData: false } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( spy.calledOnce ).to.be.false;
|
|
|
|
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|