8
0
Просмотр исходного кода

Merge pull request #94 from ckeditor/t/52

Tests: Manual/Integration tests covering typing space / spellchecking corrections at the end of the block element. Closes #52. Closes #77.
Piotrek Koszuliński 8 лет назад
Родитель
Сommit
2afb6d114c

+ 192 - 0
packages/ckeditor5-typing/tests/bogusbr-integration.js

@@ -0,0 +1,192 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+
+import MutationObserver from '@ckeditor/ckeditor5-engine/src/view/observer/mutationobserver';
+
+import Typing from '../src/typing';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
+
+import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+describe( 'Bogus BR integration', () => {
+	let editor, domRoot, mutationObserver, editorElement;
+
+	beforeEach( () => {
+		editorElement = document.createElement( 'div' );
+		document.body.appendChild( editorElement );
+
+		return ClassicTestEditor.create( editorElement, {
+			plugins: [ Typing, Paragraph, Bold ]
+		} )
+		.then( newEditor => {
+			editor = newEditor;
+			domRoot = editor.editing.view.getDomRoot();
+			mutationObserver = editor.editing.view.getObserver( MutationObserver );
+		} );
+	} );
+
+	afterEach( () => {
+		editorElement.remove();
+
+		return editor.destroy();
+	} );
+
+	describe( 'insertText', () => {
+		// Tests using 'insertText' generates same mutations as typing. This means they will behave
+		// a little different in every browser (as native mutations may be different in different browsers).
+
+		it( 'space is inserted on the end of the line (paragraph)', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
+				done();
+			}, { priority: 'low' } );
+
+			document.execCommand( 'insertText', false, ' ' );
+		} );
+
+		it( 'space is inserted on the end of the line (empty paragraph)', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph>[]</paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
+				done();
+			}, { priority: 'low' } );
+
+			document.execCommand( 'insertText', false, ' ' );
+		} );
+
+		it( 'space is inserted on the end of the line (bold)', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph><$text bold="true">Foo[]</$text></paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p><strong>Foo&nbsp;</strong></p>' );
+				done();
+			}, { priority: 'low' } );
+
+			document.execCommand( 'insertText', false, ' ' );
+		} );
+	} );
+
+	describe( 'mutations', () => {
+		// This tests use fixed list of mutation mocks to simulate specific browser behaviours.
+
+		it( 'space is inserted on the end of the paragraph', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
+				done();
+			}, { priority: 'low' } );
+
+			const mutationTarget = domRoot.childNodes[ 0 ].childNodes[ 0 ];
+
+			mutationObserver.disable();
+
+			mutationTarget.data = 'Foo ';
+
+			mutationObserver.enable();
+
+			mutationObserver._onMutations( [
+				generateMutationMock( 'characterData', mutationTarget ),
+				generateMutationMock( 'characterData', mutationTarget ),
+				generateMutationMock( 'characterData', mutationTarget )
+			] );
+		} );
+
+		it( 'space is inserted on the end of the line paragraph (with bogus br)', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph>Foo[]</paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p>Foo&nbsp;</p>' );
+				done();
+			}, { priority: 'low' } );
+
+			const paragraph = domRoot.childNodes[ 0 ];
+			const text = paragraph.childNodes [ 0 ];
+			const br = document.createElement( 'br' );
+
+			mutationObserver.disable();
+
+			text.data = 'Foo ';
+
+			mutationObserver.enable();
+
+			mutationObserver._onMutations( [
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'childList', paragraph, text, [ br ] ),
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'characterData', text )
+			] );
+		} );
+
+		it( 'word is properly corrected on the end of the block element (with bogus br)', ( done ) => {
+			editor.document.enqueueChanges( () => {
+				editor.editing.view.getDomRoot().focus();
+				setData( editor.document, '<paragraph>Foo hous[]</paragraph>' );
+			} );
+
+			editor.document.once( 'changesDone', () => {
+				expect( editor.getData() ).to.equal( '<p>Foo house</p>' );
+				done();
+			}, { priority: 'low' } );
+
+			const paragraph = domRoot.childNodes[ 0 ];
+			const text = paragraph.childNodes [ 0 ];
+			const br = document.createElement( 'br' );
+
+			mutationObserver.disable();
+
+			text.data = 'Foo house';
+
+			mutationObserver.enable();
+
+			mutationObserver._onMutations( [
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'childList', paragraph, text, [ br ] ),
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'characterData', text ),
+				generateMutationMock( 'characterData', text ),
+			] );
+		} );
+	} );
+
+	function generateMutationMock( type, target, previousSibling, addedNodes ) {
+		return {
+			addedNodes: addedNodes || [],
+			attributeName: null,
+			attributeNamespace: null,
+			nextSibling: null,
+			oldValue: null,
+			previousSibling: previousSibling || null,
+			removedNodes: [],
+			target: target,
+			type: type
+		};
+	}
+} );

+ 4 - 2
packages/ckeditor5-typing/tests/inputcommand-integration.js

@@ -22,10 +22,10 @@ import { getData as getModelData } from  '@ckeditor/ckeditor5-engine/src/dev-uti
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
 
 describe( 'InputCommand integration', () => {
 describe( 'InputCommand integration', () => {
-	let editor, doc, viewDocument, boldView, italicView;
+	let editor, doc, viewDocument, boldView, italicView, editorElement;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
-		const editorElement = document.createElement( 'div' );
+		editorElement = document.createElement( 'div' );
 		document.body.appendChild( editorElement );
 		document.body.appendChild( editorElement );
 
 
 		return ClassicTestEditor.create( editorElement, {
 		return ClassicTestEditor.create( editorElement, {
@@ -43,6 +43,8 @@ describe( 'InputCommand integration', () => {
 	} );
 	} );
 
 
 	afterEach( () => {
 	afterEach( () => {
+		editorElement.remove();
+
 		return editor.destroy();
 		return editor.destroy();
 	} );
 	} );
 
 

+ 6 - 0
packages/ckeditor5-typing/tests/manual/52/1.html

@@ -0,0 +1,6 @@
+<div id="editor">
+	<h2>Heading 1</h2>
+	<h3><em>Heading 2</em></h3>
+	<p><strong>Bolded text!</strong></p>
+	<p><em>This</em> is an <strong>editor</strong> instance.</p>
+</div>

+ 29 - 0
packages/ckeditor5-typing/tests/manual/52/1.js

@@ -0,0 +1,29 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
+import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
+import EssentialsPreset from '@ckeditor/ckeditor5-presets/src/essentials';
+import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+window.setInterval( function() {
+	console.log( getData( window.editor.document ) );
+}, 3000 );
+
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	plugins: [ EssentialsPreset, Paragraph, Bold, Italic, Heading ],
+	toolbar: [ 'headings', 'bold', 'italic', 'undo', 'redo' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
+} );

+ 3 - 0
packages/ckeditor5-typing/tests/manual/52/1.md

@@ -0,0 +1,3 @@
+## Typing - space on the end of the line ([#52](https://github.com/ckeditor/ckeditor5-typing/issues/52))
+
+For every line of text check if it possible to type spaces on the end of that line.