瀏覽代碼

Added more tests.

Piotrek Koszuliński 8 年之前
父節點
當前提交
0f4964874c
共有 2 個文件被更改,包括 31 次插入0 次删除
  1. 4 0
      packages/ckeditor5-engine/src/model/schema.js
  2. 27 0
      packages/ckeditor5-engine/tests/model/schema.js

+ 4 - 0
packages/ckeditor5-engine/src/model/schema.js

@@ -120,6 +120,10 @@ export default class Schema {
 		return this._checkContextMatch( rule, context );
 	}
 
+	/**
+	 * @param {module:engine/model/node~Node} context
+	 * @param {String}
+	 */
 	checkAttribute( context, attributeName ) {
 		const rule = this.getRule( context[ context.length - 1 ] );
 

+ 27 - 0
packages/ckeditor5-engine/tests/model/schema.js

@@ -321,6 +321,33 @@ describe( 'Schema', () => {
 			expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
 			expect( schema.checkChild( root1, new Text( 'foo' ) ) ).to.be.false;
 		} );
+
+		// TODO checks fires event
+		// TODO checks with a custom context array
+	} );
+
+	describe( 'checkAttribute()', () => {
+		beforeEach( () => {
+			schema.register( 'paragraph', {
+				allowAttributes: 'align'
+			} );
+			schema.register( '$text', {
+				allowAttributes: 'bold'
+			} );
+		} );
+
+		it( 'accepts an element as a context', () => {
+			expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
+			expect( schema.checkAttribute( r1p1, 'bold' ) ).to.be.false;
+		} );
+
+		it( 'accepts a text as a context', () => {
+			expect( schema.checkAttribute( new Text( 'foo' ), 'bold' ) ).to.be.true;
+			expect( schema.checkAttribute( new Text( 'foo' ), 'align' ) ).to.be.false;
+		} );
+
+		// TODO checks fires event
+		// TODO checks with a custom context array
 	} );
 
 	describe( 'rules compilation', () => {