Sfoglia il codice sorgente

Tests: Simplified JS code for setData performance manual test.

Marek Lewandowski 6 anni fa
parent
commit
b252a71056
1 ha cambiato i file con 15 aggiunte e 10 eliminazioni
  1. 15 10
      tests/manual/performance/setdata.js

+ 15 - 10
tests/manual/performance/setdata.js

@@ -37,11 +37,10 @@ ClassicEditor
 		console.error( err.stack );
 	} );
 
-const buttons = document.querySelectorAll( '#test-controls button' );
-const fileNames = Array.from( buttons ).map( button => button.getAttribute( 'data-file-name' ) );
-
-preloadData( fileNames.map( name => `_utils/${ name }.txt` ) )
+preloadData()
 	.then( fixtures => {
+		const buttons = document.querySelectorAll( '#test-controls button' );
+
 		for ( const button of buttons ) {
 			button.addEventListener( 'click', function() {
 				const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
@@ -52,12 +51,18 @@ preloadData( fileNames.map( name => `_utils/${ name }.txt` ) )
 		}
 	} );
 
-function preloadData( urls ) {
-	// @todo: simplify it - inline literals instead of looping over arrays.
-	return Promise.all( urls.map( url => window.fetch( url ).then( resp => resp.text() ) ) )
+function preloadData() {
+	return Promise.all( [ getFileContents( 'small' ), getFileContents( 'medium' ), getFileContents( 'large' ) ] )
 		.then( responses => {
-			return Object.fromEntries(
-				Array.from( responses.keys() ).map( index => [ fileNames[ index ], responses[ index ] ] )
-			);
+			return {
+				small: responses[ 0 ],
+				medium: responses[ 1 ],
+				large: responses[ 2 ]
+			};
 		} );
+
+	function getFileContents( fileName ) {
+		return window.fetch( `_utils/${ fileName }.txt` )
+			.then( resp => resp.text() );
+	}
 }