Przeglądaj źródła

Tests: improved LiveRange tests.

Szymon Cofalik 9 lat temu
rodzic
commit
1e666e7421
1 zmienionych plików z 40 dodań i 2 usunięć
  1. 40 2
      packages/ckeditor5-engine/tests/model/liverange.js

+ 40 - 2
packages/ckeditor5-engine/tests/model/liverange.js

@@ -94,10 +94,13 @@ describe( 'LiveRange', () => {
 	// structure is representing what is _after_ operation is executed. So live LiveRange properties are describing
 	// virtual tree that is not existing anymore and event ranges are operating on the tree generated above.
 	describe( 'should get transformed if', () => {
-		let live;
+		let live, spy;
 
 		beforeEach( () => {
 			live = new LiveRange( new Position( root, [ 0, 1, 4 ] ), new Position( root, [ 0, 2, 2 ] ) );
+
+			spy = sinon.spy();
+			live.on( 'change', spy );
 		} );
 
 		afterEach( () => {
@@ -112,6 +115,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 8 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is in the same parent as range end and before it', () => {
@@ -121,6 +125,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 5 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is at a position before a node from range start path', () => {
@@ -130,6 +135,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 3, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 4, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is at a position before a node from range end path', () => {
@@ -139,6 +145,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 3, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is at the live range start position and live range is collapsed', () => {
@@ -150,6 +157,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 8 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 1, 8 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 		} );
 
@@ -166,6 +174,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 8 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is to the same parent as range end and before it', () => {
@@ -180,6 +189,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 6 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is to a position before a node from range start path', () => {
@@ -194,6 +204,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 3, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 4, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is to a position before a node from range end path', () => {
@@ -208,6 +219,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 3, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is from the same parent as range start and before it', () => {
@@ -222,6 +234,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 1 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is from the same parent as range end and before it', () => {
@@ -236,6 +249,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 0 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is from a position before a node from range start path', () => {
@@ -250,6 +264,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 0, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 1, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'intersects on live range left side', () => {
@@ -264,6 +279,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 2 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'intersects on live range right side', () => {
@@ -278,6 +294,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 2, 1 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'intersects on live range left side and live range new start is touching moved range end', () => {
@@ -292,6 +309,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 5 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 7, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'intersects on live range right side and live range new end is touching moved range start', () => {
@@ -308,6 +326,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 3, 2 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is equal to live range', () => {
@@ -324,6 +343,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 3, 0 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 3, 3 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'contains live range', () => {
@@ -340,6 +360,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 3, 1 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 3, 4 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is inside live range and points to live range', () => {
@@ -356,6 +377,7 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 4 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 1, 12 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 
 			it( 'is intersecting with live range and points to live range', () => {
@@ -372,12 +394,13 @@ describe( 'LiveRange', () => {
 
 				expect( live.start.path ).to.deep.equal( [ 0, 1, 2 ] );
 				expect( live.end.path ).to.deep.equal( [ 0, 1, 12 ] );
+				expect( spy.calledOnce ).to.be.true;
 			} );
 		} );
 	} );
 
 	describe( 'should not get transformed if', () => {
-		let otherRoot;
+		let otherRoot, spy;
 
 		before( () => {
 			otherRoot = doc.createRoot( '$root', 'otherRoot' );
@@ -388,6 +411,9 @@ describe( 'LiveRange', () => {
 		beforeEach( () => {
 			live = new LiveRange( new Position( root, [ 0, 1, 4 ] ), new Position( root, [ 0, 2, 2 ] ) );
 			clone = Range.createFromRange( live );
+
+			spy = sinon.spy();
+			live.on( 'change', spy );
 		} );
 
 		afterEach( () => {
@@ -401,6 +427,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'insert', { range: insertRange }, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is in the same parent as range end and after it', () => {
@@ -409,6 +436,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'insert', { range: insertRange }, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is to a position after a node from range end path', () => {
@@ -417,6 +445,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'insert', { range: insertRange }, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is in different root', () => {
@@ -425,6 +454,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'insert', { range: insertRange }, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 		} );
 
@@ -440,6 +470,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is to the same parent as range end and after it', () => {
@@ -453,6 +484,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is to a position after a node from range end path', () => {
@@ -466,6 +498,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is from the same parent as range start and after it', () => {
@@ -479,6 +512,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is from the same parent as range end and after it', () => {
@@ -492,6 +526,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is from a position after a node from range end path', () => {
@@ -505,6 +540,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is to different root', () => {
@@ -518,6 +554,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 
 			it( 'is from different root', () => {
@@ -531,6 +568,7 @@ describe( 'LiveRange', () => {
 				doc.fire( 'change', 'move', changes, null );
 
 				expect( live.isEqual( clone ) ).to.be.true;
+				expect( spy.called ).to.be.false;
 			} );
 		} );
 	} );