浏览代码

Merge pull request #60 from ckeditor/t/59

Added manual and automated test.
Piotrek Koszuliński 9 年之前
父节点
当前提交
2227709d36

+ 7 - 0
packages/ckeditor5-typing/tests/tickets/59/1.html

@@ -0,0 +1,7 @@
+<head>
+	<link rel="stylesheet" href="%APPS_DIR%ckeditor/build/modules/amd/theme/ckeditor.css">
+</head>
+
+<div id="editor">
+	<p><strong>This</strong> is an editor <strong>instance</strong>.</p>
+</div>

+ 22 - 0
packages/ckeditor5-typing/tests/tickets/59/1.js

@@ -0,0 +1,22 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console, document, window */
+
+import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
+import Typing from '/ckeditor5/typing/typing.js';
+import Paragraph from '/ckeditor5/paragraph/paragraph.js';
+import Bold from '/ckeditor5/basic-styles/bold.js';
+
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	features: [ Typing, Paragraph, Bold ],
+	toolbar: [ 'bold' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
+} );

+ 8 - 0
packages/ckeditor5-typing/tests/tickets/59/1.md

@@ -0,0 +1,8 @@
+@bender-ui: collapsed
+@bender-tags: ticket, 59, iteration4
+
+### Issue [#59](https://github.com/ckeditor/ckeditor5-typing/issues/59) manual test
+
+1. Put selection at the end of the text.
+2. Start backspacing.
+3. No error should be thrown.

+ 58 - 0
packages/ckeditor5-typing/tests/tickets/59/2.js

@@ -0,0 +1,58 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document */
+
+import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
+import Typing from '/ckeditor5/typing/typing.js';
+import Paragraph from '/ckeditor5/paragraph/paragraph.js';
+import Bold from '/ckeditor5/basic-styles/bold.js';
+import { setData } from '/ckeditor5/engine/dev-utils/model.js';
+
+describe( 'Bug #59', () => {
+	let editor;
+	let container;
+
+	beforeEach( () => {
+		container = document.createElement( 'div' );
+		document.body.appendChild( container );
+
+		return ClassicEditor.create( container, {
+			features: [ Typing, Paragraph, Bold ]
+		} )
+		.then( newEditor => {
+			editor = newEditor;
+		} );
+	} );
+
+	it( 'editor does not blow up when deleting last styled character', () => {
+		editor.document.enqueueChanges( () => {
+			editor.editing.view.getDomRoot().focus();
+			setData( editor.document, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
+		} );
+
+		while ( editor.document.selection.anchor.offset > 0 ) {
+			editor.execute( 'delete' );
+		}
+
+		expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
+	} );
+
+	// This is something that came to my mind after I worked on ckeditor/ckeditor5-engine#659.
+	// Toggling bold at the end creates a lot of weird cases so it's interesting to see if it works... and it didn't back then.
+	it( 'editor does not blow up when deleting last styled character, forcing bold switch', () => {
+		editor.document.enqueueChanges( () => {
+			editor.editing.view.getDomRoot().focus();
+			setData( editor.document, '<paragraph><$text bold="true">foo</$text> x <$text bold="true">bar</$text>.[]</paragraph>' );
+		} );
+
+		while ( editor.document.selection.anchor.offset > 0 ) {
+			editor.execute( 'delete' );
+			editor.execute( 'bold' );
+		}
+
+		expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' );
+	} );
+} );