|
|
@@ -6,10 +6,12 @@
|
|
|
/* globals setTimeout, window, console, document */
|
|
|
|
|
|
import Watchdog from '../src/watchdog';
|
|
|
+import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
|
|
|
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
|
|
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
|
|
|
+import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
|
|
|
|
|
|
describe( 'Watchdog', () => {
|
|
|
let element;
|
|
|
@@ -989,6 +991,61 @@ describe( 'Watchdog', () => {
|
|
|
} );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should support multi-root editors', () => {
|
|
|
+ class MultiRootEditor extends Editor {
|
|
|
+ constructor( sourceElements, config ) {
|
|
|
+ super( config );
|
|
|
+
|
|
|
+ this.data.processor = new HtmlDataProcessor();
|
|
|
+
|
|
|
+ // Create root and UIView element for each editable container.
|
|
|
+ for ( const rootName of Object.keys( sourceElements ) ) {
|
|
|
+ this.model.document.createRoot( '$root', rootName );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static async create( sourceElements, config ) {
|
|
|
+ const editor = new this( sourceElements, config );
|
|
|
+
|
|
|
+ await editor.initPlugins();
|
|
|
+
|
|
|
+ await editor.data.init( config.initialData );
|
|
|
+
|
|
|
+ editor.fire( 'ready' );
|
|
|
+
|
|
|
+ return editor;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const watchdog = Watchdog.for( MultiRootEditor );
|
|
|
+
|
|
|
+ // sinon.stub( window, 'onerror' ).value( undefined ); and similar do not work.
|
|
|
+ const originalErrorHandler = window.onerror;
|
|
|
+ window.onerror = undefined;
|
|
|
+
|
|
|
+ return watchdog
|
|
|
+ .create( {
|
|
|
+ header: element
|
|
|
+ }, {
|
|
|
+ initialData: {
|
|
|
+ header: '<p>Foo</p>'
|
|
|
+ },
|
|
|
+ plugins: [ Paragraph ]
|
|
|
+ } )
|
|
|
+ .then( () => {
|
|
|
+ expect( watchdog.editor.data.get( { rootName: 'header' } ) ).to.equal( '<p>Foo</p>' );
|
|
|
+
|
|
|
+ setTimeout( () => throwCKEditorError( 'foo', watchdog.editor ) );
|
|
|
+
|
|
|
+ return new Promise( res => {
|
|
|
+ window.onerror = originalErrorHandler;
|
|
|
+ expect( watchdog.editor.data.get( { rootName: 'header' } ) ).to.equal( '<p>Foo</p>' );
|
|
|
+
|
|
|
+ res();
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
function throwCKEditorError( name, context ) {
|