瀏覽代碼

Split test to contain single case in view test utilities.

Szymon Kupś 9 年之前
父節點
當前提交
5fc8ce7f11
共有 1 個文件被更改,包括 31 次插入17 次删除
  1. 31 17
      packages/ckeditor5-engine/tests/_utils-tests/view.js

+ 31 - 17
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -130,26 +130,40 @@ describe( 'view test utils', () => {
 			expect( stringify( fragment, null ) ).to.equal( '<b>foobar</b><b>bazqux</b>' );
 		} );
 
-		it( 'should not write ranges outside elements', () => {
+		it( 'should not write ranges outside elements - end position outside element', () => {
 			const text = new Text( 'foobar' );
 			const b = new Element( 'b', null, text );
 			const p = new Element( 'p', null, b );
-			const range1 = Range.createFromParentsAndOffsets( p, 0, p, 5 );
-			const range2 = Range.createFromParentsAndOffsets( p, -1, p, 1 );
-			const range3 = Range.createFromParentsAndOffsets( text, 0, text, 7 );
-			const range4 = Range.createFromParentsAndOffsets( text, -1, text, 2 );
-			const range5 = Range.createFromParentsAndOffsets( text, 6, text, 8 );
-			const selection = new Selection();
-			selection.addRange( range1 );
-			expect( stringify( p, selection ) ).to.equal( '<p>[<b>foobar</b></p>' );
-			selection.setRanges( [ range2 ] );
-			expect( stringify( p, selection ) ).to.equal( '<p><b>foobar</b>]</p>' );
-			selection.setRanges( [ range3 ] );
-			expect( stringify( p, selection ) ).to.equal( '<p><b>{foobar</b></p>' );
-			selection.setRanges( [ range4 ] );
-			expect( stringify( p, selection ) ).to.equal( '<p><b>fo}obar</b></p>' );
-			selection.setRanges( [ range5 ] );
-			expect( stringify( p, selection ) ).to.equal( '<p><b>foobar{</b></p>' );
+			const range = Range.createFromParentsAndOffsets( p, 0, p, 5 );
+
+			expect( stringify( p, range ) ).to.equal( '<p>[<b>foobar</b></p>' );
+		} );
+
+		it( 'should not write ranges outside elements - start position outside element', () => {
+			const text = new Text( 'foobar' );
+			const b = new Element( 'b', null, text );
+			const p = new Element( 'p', null, b );
+			const range = Range.createFromParentsAndOffsets( p, -1, p, 1 );
+
+			expect( stringify( p, range ) ).to.equal( '<p><b>foobar</b>]</p>' );
+		} );
+
+		it( 'should not write ranges outside elements - end position outside text', () => {
+			const text = new Text( 'foobar' );
+			const b = new Element( 'b', null, text );
+			const p = new Element( 'p', null, b );
+			const range = Range.createFromParentsAndOffsets( text, 0, text, 7 );
+
+			expect( stringify( p, range ) ).to.equal( '<p><b>{foobar</b></p>' );
+		} );
+
+		it( 'should not write ranges outside elements - start position outside text', () => {
+			const text = new Text( 'foobar' );
+			const b = new Element( 'b', null, text );
+			const p = new Element( 'p', null, b );
+			const range = Range.createFromParentsAndOffsets( text, -1, text, 2 );
+
+			expect( stringify( p, range ) ).to.equal( '<p><b>fo}obar</b></p>' );
 		} );
 
 		it( 'should write multiple ranges from selection #1', () => {