From 4f00f79f6330ebfa408a7169ad89935f8e1b5ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Sun, 21 Apr 2019 14:20:43 +0200 Subject: [PATCH] Test: Added test for checking if attribute is not lost when composition replaces text. --- tests/tickets/188.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/tickets/188.js diff --git a/tests/tickets/188.js b/tests/tickets/188.js new file mode 100644 index 0000000..35b46ff --- /dev/null +++ b/tests/tickets/188.js @@ -0,0 +1,63 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; +import Input from '../../src/input'; +import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; +import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting'; + +import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view'; + +describe( 'Bug ckeditor5-typing#188', () => { + let editor; + + beforeEach( () => { + return VirtualTestEditor.create( { + plugins: [ Input, Paragraph, BoldEditing ] + } ).then( newEditor => { + editor = newEditor; + } ); + } ); + + afterEach( () => { + return editor.destroy(); + } ); + + it( 'should not lost attributes while typing - IME', () => { + const view = editor.editing.view; + const p = view.document.getRoot().getChild( 0 ); + + editor.execute( 'bold' ); + + simulateMutation( view, p, 0, 0, '', 'u' ); + + expect( getData( view, { withoutSelection: true } ) ).to.equal( '

u

' ); + + simulateMutation( view, p, 0, 1, 'u', 'ü' ); + + expect( getData( view, { withoutSelection: true } ) ).to.equal( '

ü

' ); + } ); +} ); + +function simulateMutation( view, node, startOffset, endOffset, oldText, newText ) { + const viewSelection = view.createSelection(); + + viewSelection.setTo( view.createRange( + view.createPositionAt( node, startOffset ), + view.createPositionAt( node, endOffset ) + ) ); + + view.document.fire( 'mutations', + [ + { + type: 'text', + oldText, + newText, + node + } + ], + viewSelection + ); +}