Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Test: Added test for checking if attribute is not lost when compositi…
Browse files Browse the repository at this point in the history
…on replaces text.
  • Loading branch information
oskarwrobel authored and Reinmar committed Jun 5, 2019
1 parent 9fa46e1 commit 4f00f79
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/tickets/188.js
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
);
}

0 comments on commit 4f00f79

Please sign in to comment.