瀏覽代碼

Added tests to model test utilities to check consistency with view test utilites.

Szymon Kupś 9 年之前
父節點
當前提交
7abcf0c15d
共有 1 個文件被更改,包括 36 次插入0 次删除
  1. 36 0
      packages/ckeditor5-engine/tests/_utils-tests/model.js

+ 36 - 0
packages/ckeditor5-engine/tests/_utils-tests/model.js

@@ -301,6 +301,42 @@ describe( 'model test utils', () => {
 	} );
 
 	describe( 'parse', () => {
+		test( 'creates empty DocumentFragment from empty string', {
+			data: '',
+			check( fragment ) {
+				expect( fragment ).to.be.instanceOf( DocumentFragment );
+			}
+		} );
+
+		test( 'creates empty DocumentFragment with selection', {
+			data: '<selection />',
+			check( fragment, selection ) {
+				expect( fragment ).to.be.instanceOf( DocumentFragment );
+				expect( fragment.getChildCount() ).to.equal( 0 );
+				expect( selection.rangeCount ).to.equal( 1 );
+				expect( selection.getFirstRange().isEqual( Range.createFromParentsAndOffsets( fragment, 0, fragment, 0 ) ) ).to.be.true;
+			}
+		} );
+
+		test( 'returns Element if range is around single element', {
+			data: '<selection><a></a></selection>',
+			check( el, selection ) {
+				const fragment = el.parent;
+				expect( el ).to.be.instanceOf( Element );
+				expect( fragment ).to.be.instanceOf( DocumentFragment );
+				expect( selection.rangeCount ).to.equal( 1 );
+				expect( selection.getFirstRange().isEqual( Range.createFromParentsAndOffsets( fragment, 0, fragment, 1 ) ) ).to.be.true;
+			}
+		} );
+
+		test( 'returns DocumentFragment when multiple elements on root', {
+			data: '<a></a><b></b>',
+			check( fragment ) {
+				expect( fragment ).to.be.instanceOf( DocumentFragment );
+				expect( fragment.getChildCount() ).to.equal( 2 );
+			}
+		} );
+
 		test( 'creates elements', {
 			data: '<a></a><b><c></c></b>'
 		} );