浏览代码

Tests: for element and character constructors.

Piotr Jasiun 10 年之前
父节点
当前提交
031f935a54

+ 27 - 4
packages/ckeditor5-utils/tests/document/character.js

@@ -11,18 +11,41 @@
 
 var modules = bender.amd.require(
 	'document/character',
-	'document/node' );
+	'document/node',
+	'document/element',
+	'document/attribute' );
 
 describe( 'constructor', function() {
-	it( 'should create Character', function() {
+	it( 'should create character without attributes', function() {
+		var Element = modules[ 'document/element' ];
 		var Character = modules[ 'document/character' ];
 		var Node = modules[ 'document/node' ];
 
-		var character = new Character( null, 'f' );
+		var parent = new Element( null, 'parent' );
 
-		expect( character ).to.be.an.instanceof( Node );
+		var character = new Character( parent, 'f' );
 
+		expect( character ).to.be.an.instanceof( Node );
 		expect( character ).to.have.property( 'character' ).that.equals( 'f' );
+		expect( character ).to.have.property( 'parent' ).that.equals( parent );
 		expect( character ).to.have.property( 'attrs' ).that.is.an( 'array' ).and.is.empty;
 	} );
+
+	it( 'should create character with attributes', function() {
+		var Element = modules[ 'document/element' ];
+		var Character = modules[ 'document/character' ];
+		var Node = modules[ 'document/node' ];
+		var Attribute = modules[ 'document/attribute' ];
+
+		var parent = new Element( null, 'parent' );
+		var attr = new Attribute( 'key', 'value' );
+
+		var character = new Character( parent, 'f', [ attr ] );
+
+		expect( character ).to.be.an.instanceof( Node );
+		expect( character ).to.have.property( 'character' ).that.equals( 'f' );
+		expect( character ).to.have.property( 'parent' ).that.equals( parent );
+		expect( character ).to.have.property( 'attrs' ).that.is.an( 'array' ).with.length( 1 );
+		expect( character.attrs[ 0 ] ).that.equals( attr );
+	} );
 } );

+ 48 - 0
packages/ckeditor5-utils/tests/document/element.js

@@ -0,0 +1,48 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* jshint expr: true */
+
+/* bender-tags: document */
+
+'use strict';
+
+var modules = bender.amd.require(
+	'document/node',
+	'document/element',
+	'document/attribute' );
+
+describe( 'constructor', function() {
+	it( 'should create element without attributes', function() {
+		var Element = modules[ 'document/element' ];
+		var Node = modules[ 'document/node' ];
+
+		var parent = new Element( null, 'parent' );
+
+		var element = new Element( parent, 'elem' );
+
+		expect( element ).to.be.an.instanceof( Node );
+		expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
+		expect( element ).to.have.property( 'parent' ).that.equals( parent );
+		expect( element ).to.have.property( 'attrs' ).that.is.an( 'array' ).and.is.empty;
+	} );
+
+	it( 'should create element with attributes', function() {
+		var Element = modules[ 'document/element' ];
+		var Node = modules[ 'document/node' ];
+		var Attribute = modules[ 'document/attribute' ];
+
+		var parent = new Element( null, 'parent' );
+		var attr = new Attribute( 'key', 'value' );
+
+		var element = new Element( parent, 'elem', [ attr ] );
+
+		expect( element ).to.be.an.instanceof( Node );
+		expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
+		expect( element ).to.have.property( 'parent' ).that.equals( parent );
+		expect( element ).to.have.property( 'attrs' ).that.is.an( 'array' ).with.length( 1 );
+		expect( element.attrs[ 0 ] ).that.equals( attr );
+	} );
+} );