浏览代码

Tests: Tests for `DocumentSelection#event:change:marker`.

Szymon Cofalik 5 年之前
父节点
当前提交
8388d8a83a
共有 1 个文件被更改,包括 44 次插入0 次删除
  1. 44 0
      packages/ckeditor5-engine/tests/model/documentselection.js

+ 44 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -442,6 +442,50 @@ describe( 'DocumentSelection', () => {
 
 			expect( selection.markers.map( marker => marker.name ) ).to.have.members( [ 'marker' ] );
 		} );
+
+		it( 'should fire change:marker event when selection markers change', () => {
+			model.change( writer => {
+				const spy = sinon.spy();
+
+				model.document.selection.on( 'change:marker', spy );
+
+				writer.setSelection( writer.createRange(
+					writer.createPositionFromPath( root, [ 2, 1 ] ),
+					writer.createPositionFromPath( root, [ 2, 2 ] )
+				) );
+
+				expect( spy.called ).to.be.false;
+
+				writer.addMarker( 'marker-1', {
+					range: writer.createRange(
+						writer.createPositionFromPath( root, [ 2, 0 ] ),
+						writer.createPositionFromPath( root, [ 2, 5 ] )
+					),
+					usingOperation: false
+				} );
+
+				expect( spy.calledOnce ).to.be.true;
+
+				writer.addMarker( 'marker-2', {
+					range: writer.createRange(
+						writer.createPositionFromPath( root, [ 2, 0 ] ),
+						writer.createPositionFromPath( root, [ 2, 3 ] )
+					),
+					usingOperation: false
+				} );
+
+				expect( spy.calledTwice ).to.be.true;
+				spy.resetHistory();
+
+				writer.setSelection( writer.createPositionFromPath( root, [ 2, 6 ] ) );
+
+				expect( spy.calledOnce ).to.be.true;
+
+				writer.setSelection( writer.createPositionFromPath( root, [ 2, 2 ] ) );
+
+				expect( spy.calledTwice ).to.be.true;
+			} );
+		} );
 	} );
 
 	describe( 'destroy()', () => {