|
|
@@ -42,24 +42,29 @@ describe( 'Document', () => {
|
|
|
} );
|
|
|
|
|
|
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();
|
|
|
- const type = 't';
|
|
|
- const data = { data: 'x' };
|
|
|
- const batch = new Batch();
|
|
|
- const delta = new Delta();
|
|
|
- delta.type = 'type';
|
|
|
+ let operation, data, delta, batch;
|
|
|
|
|
|
- const operation = {
|
|
|
- type,
|
|
|
+ beforeEach( () => {
|
|
|
+ data = { data: 'x' };
|
|
|
+
|
|
|
+ operation = {
|
|
|
+ type: 't',
|
|
|
baseVersion: 0,
|
|
|
isDocumentOperation: true,
|
|
|
- _execute: sinon.stub().returns( data )
|
|
|
+ _execute: sinon.stub().returns( data ),
|
|
|
+ _validate: () => {}
|
|
|
};
|
|
|
|
|
|
+ delta = new Delta();
|
|
|
delta.addOperation( operation );
|
|
|
+ delta.type = 'delta';
|
|
|
+
|
|
|
+ batch = new Batch();
|
|
|
batch.addDelta( delta );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'for document operation: should increase document version, execute operation and fire change event with proper data', () => {
|
|
|
+ const changeCallback = sinon.spy();
|
|
|
|
|
|
doc.on( 'change', changeCallback );
|
|
|
model.applyOperation( operation );
|
|
|
@@ -69,30 +74,15 @@ describe( 'Document', () => {
|
|
|
sinon.assert.calledOnce( operation._execute );
|
|
|
|
|
|
sinon.assert.calledOnce( changeCallback );
|
|
|
- expect( changeCallback.args[ 0 ][ 1 ] ).to.equal( type );
|
|
|
+ expect( changeCallback.args[ 0 ][ 1 ] ).to.equal( 't' );
|
|
|
expect( changeCallback.args[ 0 ][ 2 ] ).to.equal( data );
|
|
|
- expect( changeCallback.args[ 0 ][ 3 ] ).to.deep.equal( batch );
|
|
|
+ expect( changeCallback.args[ 0 ][ 3 ] ).to.equal( batch );
|
|
|
expect( changeCallback.args[ 0 ][ 4 ] ).to.equal( delta.type );
|
|
|
} );
|
|
|
|
|
|
- it( 'should execute operation, not fire event and not increase document version ' +
|
|
|
- 'when operation is not a document operation', () => {
|
|
|
+ it( 'for non-document operation: should only execute operation', () => {
|
|
|
const changeCallback = sinon.spy();
|
|
|
- const type = 't';
|
|
|
- const data = { data: 'x' };
|
|
|
- const batch = new Batch();
|
|
|
- const delta = new Delta();
|
|
|
- delta.type = 'type';
|
|
|
-
|
|
|
- const operation = {
|
|
|
- type,
|
|
|
- baseVersion: 0,
|
|
|
- isDocumentOperation: false,
|
|
|
- _execute: sinon.stub().returns( data )
|
|
|
- };
|
|
|
-
|
|
|
- delta.addOperation( operation );
|
|
|
- batch.addDelta( delta );
|
|
|
+ operation.isDocumentOperation = false;
|
|
|
|
|
|
doc.on( 'change', changeCallback );
|
|
|
model.applyOperation( operation );
|
|
|
@@ -104,6 +94,15 @@ describe( 'Document', () => {
|
|
|
sinon.assert.notCalled( changeCallback );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should do nothing if operation event was cancelled', () => {
|
|
|
+ model.on( 'applyOperation', evt => evt.stop(), { priority: 'highest' } );
|
|
|
+
|
|
|
+ model.applyOperation( operation );
|
|
|
+
|
|
|
+ expect( doc.version ).to.equal( 0 );
|
|
|
+ expect( operation._execute.called ).to.be.false;
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should throw an error on the operation base version and the document version is different', () => {
|
|
|
const operation = {
|
|
|
baseVersion: 1,
|