8
0
Maciej Bukowski 6 лет назад
Родитель
Сommit
88b73ef2c4

+ 20 - 6
packages/ckeditor5-watchdog/tests/manual/watchdog.html

@@ -1,11 +1,25 @@
 <button id="random-error">Simulate a random `Error`</button>
 
-<div id="editor-1">
-	<h2>Heading 1</h2>
-	<p>Paragraph</p>
+<div class="editor">
+	<div>First editor state: <span id='editor-1-state'></span></div>
+
+	<div id="editor-1">
+		<h2>Heading 1</h2>
+		<p>Paragraph</p>
+	</div>
 </div>
 
-<div id="editor-2">
-	<h2>Heading 1</h2>
-	<p>Paragraph</p>
+<div class="editor">
+	<div>Second editor state: <span id='editor-2-state'></span></div>
+
+	<div id="editor-2">
+		<h2>Heading 1</h2>
+		<p>Paragraph</p>
+	</div>
 </div>
+
+<style>
+.editor {
+	margin-top: 20px;
+}
+</style>

+ 21 - 8
packages/ckeditor5-watchdog/tests/manual/watchdog.js

@@ -44,8 +44,17 @@ const editorConfig = {
 	}
 };
 
-const watchdog1 = createWatchdog( document.getElementById( 'editor-1' ), 'First' );
-const watchdog2 = createWatchdog( document.getElementById( 'editor-2' ), 'Second' );
+const watchdog1 = createWatchdog(
+	document.getElementById( 'editor-1' ),
+	document.getElementById( 'editor-1-state' ),
+	'First'
+);
+
+const watchdog2 = createWatchdog(
+	document.getElementById( 'editor-2' ),
+	document.getElementById( 'editor-2-state' ),
+	'Second'
+);
 
 Object.assign( window, { watchdog1, watchdog2 } );
 
@@ -53,24 +62,28 @@ document.getElementById( 'random-error' ).addEventListener( 'click', () => {
 	throw new Error( 'foo' );
 } );
 
-function createWatchdog( element, which ) {
+function createWatchdog( editorElement, stateElement, name ) {
 	const watchdog = Watchdog.for( ClassicEditor );
 
-	watchdog.create( element, editorConfig );
+	watchdog.create( editorElement, editorConfig );
 
 	watchdog.on( 'error', () => {
-		console.log( `${ which } editor crashed!` );
+		console.log( `${ name } editor crashed!` );
 	} );
 
 	watchdog.on( 'restart', () => {
-		console.log( `${ which } editor restarted.` );
+		console.log( `${ name } editor restarted.` );
 	} );
 
-	watchdog.on( 'change:state', ( evt, name, currentValue, prevValue ) => {
-		console.log( `${ which } watchdog changed state from ${ prevValue } to ${ currentValue }` );
+	watchdog.on( 'change:state', ( evt, paramName, currentValue, prevValue ) => {
+		console.log( `${ name } watchdog changed state from ${ prevValue } to ${ currentValue }` );
+
+		stateElement.innerText = currentValue;
 
 		if ( currentValue === 'crashedPermanently' ) {
 			watchdog.editor.isReadOnly = true;
 		}
 	} );
+
+	stateElement.innerText = watchdog.state;
 }

+ 1 - 1
packages/ckeditor5-watchdog/tests/manual/watchdog.md

@@ -6,4 +6,4 @@
 
 1. Refresh page and quickly type `1` in the first editor 4 times. After the last error the editor should be crashed and it should not restart.
 
-1. Refresh page and slowly (slower 1 per 5 seconds) type `1` in the first editor 4 times. After the last error the editor should be restarted and it should still work.
+1. Refresh page and slowly (slower than 1 per 5 seconds) type `1` in the first editor 4 times. After the last error the editor should be restarted and it should still work.