Parcourir la source

Changed how priority is stringified in tree view test tools.

Szymon Kupś il y a 9 ans
Parent
commit
a89c0fcaad

+ 2 - 4
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -106,8 +106,8 @@ describe( 'view test utils', () => {
 			const b = new AttributeElement( 'b', null, text );
 			const p = new ContainerElement( 'p', null, b );
 
-			expect( getData( p, null, { showType: true, showPriority: true } ) )
-				.to.equal( '<container:p><attribute:b priority=10>foobar</attribute:b></container:p>' );
+			expect( getData( p, null, { showPriority: true } ) )
+				.to.equal( '<p><b:10>foobar</b:10></p>' );
 		} );
 
 		it( 'should parse DocumentFragment as root', () => {
@@ -149,8 +149,6 @@ describe( 'view test utils', () => {
 			const p = new Element( 'p', null, [ b1, b2 ] );
 			const range1 = Range.createFromParentsAndOffsets( p, 0, p, 1 );
 			const range2 = Range.createFromParentsAndOffsets( p, 1, p, 1 );
-			// const range3 = Range.createFromParentsAndOffsets( text2, 3, text2, 4 );
-			// const range4 = Range.createFromParentsAndOffsets( p, 1, p, 1 );
 			const selection = new Selection();
 			selection.setRanges( [ range2, range1 ] );
 

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

@@ -245,10 +245,11 @@ class ViewStringify {
 	 * @returns {string}
 	 */
 	_stringifyElementOpen( element ) {
-		const name = this._stringifyElementName( element );
 		const priority = this._stringifyElementPriority( element );
+		const type = this._stringifyElementType( element );
+		const name = [ type, element.name, priority ].filter( i=> i !== '' ).join( ':' );
 		const attributes = this._stringifyElementAttributes( element );
-		const parts = [ name, priority, attributes ];
+		const parts = [ name, attributes ];
 
 		return `<${ parts.filter( i => i !== '' ).join( ' ' ) }>`;
 	}
@@ -263,34 +264,35 @@ class ViewStringify {
 	 * @returns {string}
 	 */
 	_stringifyElementClose( element ) {
-		const name = this._stringifyElementName( element );
+		const priority = this._stringifyElementPriority( element );
+		const type = this._stringifyElementType( element );
+		const name = [ type, element.name, priority ].filter( i=> i !== '' ).join( ':' );
 
 		return `</${ name }>`;
 	}
 
 	/**
-	 * Converts passed {@link engine.treeView.Element Element} its name representation.
-	 * Depending on current configuration name can be simple (`a`) or contain type prefix (`container:p` or
-	 * `attribute:a`).
+	 * Converts passed {@link engine.treeView.Element Element's} type to its string representation
+	 * Returns 'attribute' for {@link engine.treeView.AttributeElement AttributeElements} and
+	 * 'container' for {@link engine.treeView.ContainerElement ContainerElements}. Returns empty string when current
+	 * configuration is preventing showing elements' types.
 	 *
 	 * @private
 	 * @param {engine.treeView.Element} element
 	 * @returns {string}
 	 */
-	_stringifyElementName( element ) {
-		let name = element.name;
-
+	_stringifyElementType( element ) {
 		if ( this.showType ) {
 			if ( element instanceof AttributeElement ) {
-				return 'attribute:' + name;
+				return 'attribute';
 			}
 
 			if ( element instanceof ContainerElement ) {
-				return 'container:' + name;
+				return 'container';
 			}
 		}
 
-		return name;
+		return '';
 	}
 
 	/**
@@ -305,7 +307,7 @@ class ViewStringify {
 	 */
 	_stringifyElementPriority( element ) {
 		if ( this.showPriority && element instanceof AttributeElement ) {
-			return `priority=${ element.priority }`;
+			return element.priority;
 		}
 
 		return '';