Selaa lähdekoodia

Merge pull request #217 from ckeditor/t/198

Tests: Added a manual test to check `ContextualToolbar` integration with external document changes. Closes #198.
Aleksander Nowodzinski 8 vuotta sitten
vanhempi
commit
4914747d5d

+ 13 - 0
packages/ckeditor5-ui/tests/manual/tickets/198/1.html

@@ -0,0 +1,13 @@
+<h2>External changes (insert)</h2>
+<p><button id="button-insert">Start external changes</button></p>
+<div id="editor-insert">
+	<p>EXTERNAL CHANGES WILL START HERE -> This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML).</p>
+</div>
+
+<h2>External changes (delete)</h2>
+<p><button id="button-delete">Start external changes</button></p>
+<div id="editor-delete">
+	<p>This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML).</p>
+	<p>THIS PARAGRAPH WILL BE REMOVED This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML).</p>
+	<p>This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML).</p>
+</div>

+ 117 - 0
packages/ckeditor5-ui/tests/manual/tickets/198/1.js

@@ -0,0 +1,117 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console:false, document, setTimeout */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
+import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ContextualToolbar from '../../../../src/toolbar/contextual/contextualtoolbar';
+
+import Element from '@ckeditor/ckeditor5-engine/src/model/element';
+import Text from '@ckeditor/ckeditor5-engine/src/model/text';
+import Position from '@ckeditor/ckeditor5-engine/src/model/position';
+import Range from '@ckeditor/ckeditor5-engine/src/model/range';
+
+// Editor for the external insert.
+ClassicEditor.create( document.querySelector( '#editor-insert' ), {
+	plugins: [ ArticlePresets, ContextualToolbar ],
+	toolbar: [ 'undo', 'redo' ],
+	contextualToolbar: [ 'bold', 'italic' ]
+} )
+.then( editor => {
+	const element = document.querySelector( '#button-insert' );
+
+	element.addEventListener( 'click', () => {
+		element.disabled = true;
+		startExternalInsert( editor );
+	} );
+} )
+.catch( err => console.error( err.stack ) );
+
+// Editor for the external delete.
+ClassicEditor.create( document.querySelector( '#editor-delete' ), {
+	plugins: [ ArticlePresets, ContextualToolbar ],
+	toolbar: [ 'undo', 'redo' ],
+	contextualToolbar: [ 'bold', 'italic' ]
+} )
+.then( editor => {
+	const element = document.querySelector( '#button-delete' );
+
+	element.addEventListener( 'click', () => {
+		element.disabled = true;
+		startExternalDelete( editor );
+	} );
+} )
+.catch( err => console.error( err.stack ) );
+
+function wait( delay ) {
+	return new Promise( ( resolve ) => {
+		setTimeout( () => resolve(), delay );
+	} );
+}
+
+function startExternalInsert( editor ) {
+	const document = editor.document;
+	const bath = document.batch( 'transparent' );
+
+	function type( path, text ) {
+		return new Promise( ( resolve ) => {
+			let position = new Position( document.getRoot(), path );
+			let index = 0;
+
+			function typing() {
+				wait( 40 ).then( () => {
+					document.enqueueChanges( () => {
+						bath.insert( position, new Text( text[ index ] ) );
+						position = position.getShiftedBy( 1 );
+
+						let nextLetter = text[ ++index ];
+
+						if ( nextLetter ) {
+							typing( nextLetter );
+						} else {
+							index = 0;
+							resolve();
+						}
+					} );
+				} );
+			}
+
+			typing();
+		} );
+	}
+
+	function insertNewLine( path ) {
+		return wait( 200 ).then( () => {
+			document.enqueueChanges( () => {
+				bath.insert( new Position( document.getRoot(), path ), new Element( 'paragraph' ) );
+			} );
+
+			return Promise.resolve();
+		} );
+	}
+
+	wait( 3000 )
+		.then( () => type( [ 0, 36 ], `This specification defines the 5th major revision of the core language of the World Wide Web. ` ) )
+		.then( () => insertNewLine( [ 0 ] ) )
+		.then( () => type( [ 0, 0 ], 'a' ) )
+		.then( () => insertNewLine( [ 1 ] ) )
+		.then( () => type( [ 1, 0 ], 'b' ) )
+		.then( () => insertNewLine( [ 2 ] ) )
+		.then( () => type( [ 2, 0 ], 'c' ) )
+		.then( () => insertNewLine( [ 0 ] ) )
+		.then( () => type( [ 0, 0 ], 'DONE :)' ) );
+}
+
+function startExternalDelete( editor ) {
+	const document = editor.document;
+	const bath = document.batch( 'transparent' );
+
+	wait( 3000 ).then( () => {
+		document.enqueueChanges( () => {
+			bath.remove( Range.createFromPositionAndShift( new Position( document.getRoot(), [ 1 ] ), 1 ) );
+		} );
+	} );
+}

+ 13 - 0
packages/ckeditor5-ui/tests/manual/tickets/198/1.md

@@ -0,0 +1,13 @@
+# Issue [#198](https://github.com/ckeditor/ckeditor5-ui/issues/198) manual test.
+
+## Position of the `ContextualToolbar` should be updated on external changes.
+
+### Insert:
+
+1. Click **Start external changes** then quickly select some text following the place where external changes will appear (contextual toolbar should show up).
+2. Observe if the balloon remains attached to the target selection.
+
+### Delete:
+
+1. Click **Start external changes** then quickly select some text from the second paragraph (contextual toolbar should appear).
+2. Check if the balloon hides and there are no errors in the browser console.