Browse Source

Improved manual tests.

Maciej Bukowski 6 years ago
parent
commit
6711f9c019

+ 0 - 2
packages/ckeditor5-watchdog/tests/manual/watchdog.html

@@ -1,7 +1,5 @@
 <button id="random-error">Simulate a random `Error`</button>
 
-<button id="restart">Restart both editors</button>
-
 <div id="editor-1">
 	<h2>Heading 1</h2>
 	<p>Paragraph</p>

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

@@ -11,11 +11,6 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 import Watchdog from '../../src/watchdog';
 
-const firstEditorElement = document.getElementById( 'editor-1' );
-const secondEditorElement = document.getElementById( 'editor-2' );
-
-const randomErrorButton = document.getElementById( 'random-error' );
-
 class TypingError {
 	constructor( editor ) {
 		this.editor = editor;
@@ -49,36 +44,33 @@ const editorConfig = {
 	}
 };
 
-// Watchdog 1
-
-const watchdog1 = Watchdog.for( ClassicEditor );
-window.watchdog1 = watchdog1;
+const watchdog1 = createWatchdog( document.getElementById( 'editor-1' ), 'First' );
+const watchdog2 = createWatchdog( document.getElementById( 'editor-2' ), 'Second' );
 
-watchdog1.create( firstEditorElement, editorConfig );
+Object.assign( window, { watchdog1, watchdog2 } );
 
-watchdog1.on( 'error', () => {
-	console.log( 'First editor crashed!' );
+document.getElementById( 'random-error' ).addEventListener( 'click', () => {
+	throw new Error( 'foo' );
 } );
 
-watchdog1.on( 'restart', () => {
-	console.log( 'First editor restarted.' );
-} );
+function createWatchdog( element, which ) {
+	const watchdog = Watchdog.for( ClassicEditor );
 
-// Watchdog 2
+	watchdog.create( element, editorConfig );
 
-const watchdog2 = Watchdog.for( ClassicEditor );
-window.watchdog2 = watchdog2;
+	watchdog.on( 'error', () => {
+		console.log( `${ which } editor crashed!` );
+	} );
 
-watchdog2.create( secondEditorElement, editorConfig );
+	watchdog.on( 'restart', () => {
+		console.log( `${ which } editor restarted.` );
+	} );
 
-watchdog2.on( 'error', () => {
-	console.log( 'Second editor crashed!' );
-} );
+	watchdog.on( 'change:state', ( evt, name, currentValue, prevValue ) => {
+		console.log( `${ which } watchdog changed state from ${ prevValue } to ${ currentValue }` );
 
-watchdog2.on( 'restart', () => {
-	console.log( 'Second editor restarted.' );
-} );
-
-randomErrorButton.addEventListener( 'click', () => {
-	throw new Error( 'foo' );
-} );
+		if ( currentValue === 'crashedPermanently' ) {
+			watchdog.editor.isReadOnly = true;
+		}
+	} );
+}

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

@@ -4,4 +4,6 @@
 
 1. Click `Simulate a random error` No editor should be restarted.
 
-1. Refresh page and type `1` in the first editor 4 times. The last time the editor should not be restarted.
+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.