Ver código fonte

Improved manual tests.

Maciej Bukowski 7 anos atrás
pai
commit
b317b2d938
1 arquivos alterados com 28 adições e 7 exclusões
  1. 28 7
      packages/ckeditor5-autosave/tests/manual/autosave.js

+ 28 - 7
packages/ckeditor5-autosave/tests/manual/autosave.js

@@ -29,17 +29,38 @@ ClassicEditor
 			save() {
 				const data = editor.getData();
 
-				return saveEditorContentToDatabase( data );
+				return wait( 1000 )
+					.then( () => console.log( `${ getTime() } Saved content:`, data ) );
 			}
 		};
+
+		autosave.listenTo( autosave, 'change:_state',
+			( evt, propName, newValue, oldValue ) => console.log( `${ getTime() } Changed state: ${ oldValue } -> ${ newValue }` ) );
 	} );
 
-function saveEditorContentToDatabase( data ) {
+function wait( time ) {
 	return new Promise( res => {
-		window.setTimeout( () => {
-			console.log( data );
-
-			res();
-		}, 1000 );
+		window.setTimeout( res, time );
 	} );
 }
+
+function getTime() {
+	const date = new Date();
+
+	return '[' +
+		date.getHours() + ':' +
+		setDigitSize( date.getMinutes(), 2 ) + ':' +
+		setDigitSize( date.getSeconds(), 2 ) + '.' +
+		setDigitSize( date.getMilliseconds(), 2 ) +
+		']';
+}
+
+function setDigitSize( number, size ) {
+	const string = String( number );
+
+	if ( string.length >= size ) {
+		return string.slice( 0, size );
+	}
+
+	return '0'.repeat( size - string.length ) + string;
+}