Преглед изворни кода

Merge pull request #427 from ckeditor/t/408

Sort attributes in view utilities stringify() method.
Piotr Jasiun пре 9 година
родитељ
комит
e2413b51aa

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

@@ -118,7 +118,7 @@ describe( 'view test utils', () => {
 			expect( stringify( p ) ).to.equal( '<p><b>foobar</b></p>' );
 		} );
 
-		it( 'should write elements with attributes', () => {
+		it( 'should write elements with attributes (attributes in alphabetical order)', () => {
 			const text = new Text( 'foobar' );
 			const b = new Element( 'b', {
 				foo: 'bar'
@@ -129,7 +129,7 @@ describe( 'view test utils', () => {
 				class: 'short wide'
 			}, b );
 
-			expect( stringify( p ) ).to.equal( '<p class="short wide" baz="qux" bar="taz"><b foo="bar">foobar</b></p>' );
+			expect( stringify( p ) ).to.equal( '<p bar="taz" baz="qux" class="short wide"><b foo="bar">foobar</b></p>' );
 		} );
 
 		it( 'should write selection ranges inside elements', () => {

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

@@ -913,8 +913,9 @@ class ViewStringify {
 	 */
 	_stringifyElementAttributes( element ) {
 		const attributes = [];
+		const keys = [ ...element.getAttributeKeys() ].sort();
 
-		for ( let attribute of element.getAttributeKeys() ) {
+		for ( let attribute of keys ) {
 			attributes.push( `${ attribute }="${ element.getAttribute( attribute ) }"` );
 		}
 

+ 2 - 2
packages/ckeditor5-engine/tests/treeview/writer/unwrap.js

@@ -237,9 +237,9 @@ describe( 'Writer', () => {
 
 		it( 'should not unwrap single element when attributes are different', () => {
 			test(
-				'<container:p>[<attribute:b:1 foo="bar" baz="qux">test</attribute:b:1>]</container:p>',
+				'<container:p>[<attribute:b:1 baz="qux" foo="bar">test</attribute:b:1>]</container:p>',
 				'<attribute:b:1 baz="qux" test="true"></attribute:b:1>',
-				'<container:p>[<attribute:b:1 foo="bar" baz="qux">test</attribute:b:1>]</container:p>'
+				'<container:p>[<attribute:b:1 baz="qux" foo="bar">test</attribute:b:1>]</container:p>'
 			);
 		} );
 

+ 2 - 2
packages/ckeditor5-engine/tests/treeview/writer/wrap.js

@@ -173,7 +173,7 @@ describe( 'Writer', () => {
 			test(
 				'<container:p>[<attribute:b:1 foo="bar" one="two"></attribute:b:1>]</container:p>',
 				'<attribute:b:1 baz="qux" one="two"></attribute:b:1>',
-				'<container:p>[<attribute:b:1 foo="bar" one="two" baz="qux"></attribute:b:1>]</container:p>'
+				'<container:p>[<attribute:b:1 baz="qux" foo="bar" one="two"></attribute:b:1>]</container:p>'
 			);
 		} );
 
@@ -234,7 +234,7 @@ describe( 'Writer', () => {
 				'<attribute:b:1 baz="qux"></attribute:b:1>',
 				'<container:p>' +
 				'[' +
-					'<attribute:b:1 foo="bar" baz="qux">' +
+					'<attribute:b:1 baz="qux" foo="bar">' +
 						'foobar' +
 						'<attribute:i:1>baz</attribute:i:1>' +
 					'</attribute:b:1>' +