Browse Source

Tests: spellchecking input tests.

Krzysztof Krztoń 8 years ago
parent
commit
aecb2f9c8a
1 changed files with 69 additions and 0 deletions
  1. 69 0
      packages/ckeditor5-typing/tests/input.js

+ 69 - 0
packages/ckeditor5-typing/tests/input.js

@@ -250,6 +250,75 @@ describe( 'Input feature', () => {
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 		} );
 		} );
 
 
+		it( 'should place selection after when correcting to longer word (spellchecker)', () => {
+			// This test case emulates spellchecker correction.
+			editor.setData( '<p>Foo hous a</p>' );
+
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 4, modelRoot.getChild( 0 ), 8 )
+				] );
+			} );
+
+			view.fire( 'mutations',
+				[ {
+					type: 'text',
+					oldText: 'Foo hous a',
+					newText: 'Foo house a',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				} ]
+			);
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>Foo house[] a</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>Foo house{} a</p>' );
+		} );
+
+		it( 'should place selection after when correcting to shorter word (spellchecker)', () => {
+			// This test case emulates spellchecker correction.
+			editor.setData( '<p>Bar athat foo</p>' );
+
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 4, modelRoot.getChild( 0 ), 9 )
+				] );
+			} );
+
+			view.fire( 'mutations',
+				[ {
+					type: 'text',
+					oldText: 'Bar athat foo',
+					newText: 'Bar that foo',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				} ]
+			);
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>Bar that[] foo</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>Bar that{} foo</p>' );
+		} );
+
+		it( 'should place selection after when merging two words (spellchecker)', () => {
+			// This test case emulates spellchecker correction.
+			editor.setData( '<p>Foo hous e</p>' );
+
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 4, modelRoot.getChild( 0 ), 10 )
+				] );
+			} );
+
+			view.fire( 'mutations',
+				[ {
+					type: 'text',
+					oldText: 'Foo hous e',
+					newText: 'Foo house',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				} ]
+			);
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>Foo house[]</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>Foo house{}</p>' );
+		} );
+
 		it( 'should replace last &nbsp; with space', () => {
 		it( 'should replace last &nbsp; with space', () => {
 			model.enqueueChanges( () => {
 			model.enqueueChanges( () => {
 				model.selection.setRanges( [
 				model.selection.setRanges( [