8
0
Просмотр исходного кода

Increased code coverage of view and model utils.

Oskar Wrobel 9 лет назад
Родитель
Сommit
0f17e4267d

+ 16 - 2
packages/ckeditor5-engine/tests/_utils-tests/model.js

@@ -454,8 +454,22 @@ describe( 'model test utils', () => {
 
 		it( 'throws when invalid XML', () => {
 			expect( () => {
-				parse( '<a><b></a></b>' );
-			} ).to.throw( Error );
+				parse( '<a><b></a></b>', document.schema );
+			} ).to.throw( Error, /Parse error/ );
+		} );
+
+		it( 'throws when try to set element not registered in schema', () => {
+			expect( () => {
+				parse( '<xyz></xyz>', document.schema );
+			} ).to.throw( Error, `Element 'xyz' not allowed in context.` );
+		} );
+
+		it( 'throws when try to set text directly to $root without registering it', () => {
+			const doc = new Document();
+
+			expect( () => {
+				parse( 'text', doc.schema );
+			} ).to.throw( Error, `Element '$text' not allowed in context.` );
 		} );
 
 		describe( 'selection', () => {

+ 8 - 13
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -16,6 +16,7 @@ import Text from '/ckeditor5/engine/view/text.js';
 import Selection from '/ckeditor5/engine/view/selection.js';
 import Range from '/ckeditor5/engine/view/range.js';
 import Document from '/ckeditor5/engine/view/document.js';
+import XmlDataProcessor from '/ckeditor5/engine/dataprocessor/xmldataprocessor.js';
 
 describe( 'view test utils', () => {
 	describe( 'getData, setData', () => {
@@ -586,22 +587,16 @@ describe( 'view test utils', () => {
 			} ).to.throw( Error );
 		} );
 
-		it( 'should throw when wrong tag name is provided #1', () => {
-			expect( () => {
-				parse( '<b:bar></b:bar>' );
-			} ).to.throw( Error );
-		} );
+		it( 'should throw when wrong type is provided', () => {
+			sinon.stub( XmlDataProcessor.prototype, 'toView', () => {
+				return new ContainerElement( 'invalidType:b' );
+			} );
 
-		it( 'should throw when wrong tag name is provided #2', () => {
 			expect( () => {
-				parse( '<container:b:bar></container:b:bar>' );
-			} ).to.throw( Error );
-		} );
+				parse( 'sth' );
+			} ).to.throw( Error, `Parse error - cannot parse element's name: invalidType:b.` );
 
-		it( 'should throw when wrong tag name is provided #3', () => {
-			expect( () => {
-				parse( '<container:b:10:test></container:b:10:test>' );
-			} ).to.throw( Error );
+			XmlDataProcessor.prototype.toView.restore();
 		} );
 
 		it( 'should use provided root element #1', () => {

+ 9 - 13
packages/ckeditor5-engine/tests/_utils/view.js

@@ -888,22 +888,18 @@ function _convertElementNameAndPriority( viewElement ) {
 		};
 	}
 
-	if ( parts.length == 2 ) {
-		// Check if type and name: container:div.
-		const type = _convertType( parts[ 0 ] );
+	// Check if type and name: container:div.
+	const type = _convertType( parts[ 0 ] );
 
-		if ( type ) {
-			return {
-				name: parts[ 1 ],
-				type: type,
-				priority: priority
-			};
-		}
-
-		throw new Error( `Parse error - cannot parse element's name: ${ viewElement.name }.` );
+	if ( type ) {
+		return {
+			name: parts[ 1 ],
+			type: type,
+			priority: priority
+		};
 	}
 
-	throw new Error( `Parse error - cannot parse element's tag name: ${ viewElement.name }.` );
+	throw new Error( `Parse error - cannot parse element's name: ${ viewElement.name }.` );
 }
 
 // Checks if element's type is allowed. Returns `attribute`, `container` or `null`.