This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Added test for checking if attribute is not lost when compositi…
…on replaces text.
- Loading branch information
1 parent
9fa46e1
commit 4f00f79
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( '<p><strong>u</strong></p>' ); | ||
|
||
simulateMutation( view, p, 0, 1, 'u', 'ü' ); | ||
|
||
expect( getData( view, { withoutSelection: true } ) ).to.equal( '<p><strong>ü</strong></p>' ); | ||
} ); | ||
} ); | ||
|
||
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 | ||
); | ||
} |