|
|
@@ -6,6 +6,7 @@
|
|
|
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
|
|
|
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
|
|
|
|
|
|
+import Typing from '../src/typing';
|
|
|
import TextTransformation from '../src/texttransformation';
|
|
|
import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
@@ -52,6 +53,30 @@ describe( 'Text transformation feature', () => {
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foo bar(tm) baz</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should not work for deletion changes', () => {
|
|
|
+ setData( model, '<paragraph>foo bar(tm) []</paragraph>' );
|
|
|
+
|
|
|
+ // Simulate delete command.
|
|
|
+ model.change( writer => {
|
|
|
+ const selection = writer.createSelection( doc.selection );
|
|
|
+ model.modifySelection( selection, { direction: 'backward', unit: 'character' } );
|
|
|
+ model.deleteContent( selection, { doNotResetEntireContent: true } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foo bar(tm)</paragraph>' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not work for merging changes', () => {
|
|
|
+ setData( model, '<paragraph>foo bar(tm)</paragraph><paragraph>[] baz</paragraph>' );
|
|
|
+
|
|
|
+ // Simulate delete command.
|
|
|
+ model.change( writer => {
|
|
|
+ writer.merge( writer.createPositionAfter( doc.getRoot().getChild( 0 ) ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foo bar(tm) baz</paragraph>' );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'symbols', () => {
|
|
|
testTransformation( '(c)', '©' );
|
|
|
testTransformation( '(r)', '®' );
|
|
|
@@ -92,21 +117,21 @@ describe( 'Text transformation feature', () => {
|
|
|
it( 'should replace only the parts of content which changed', () => {
|
|
|
setData( model, '<paragraph>Foo "<$text bold="true">Bar</$text>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '"', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '"' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) )
|
|
|
- .to.equal( '<paragraph>Foo “<$text bold="true">Bar</$text>”</paragraph>' );
|
|
|
+ .to.equal( '<paragraph>Foo “<$text bold="true">Bar”</$text></paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should keep styles of the replaced text #1', () => {
|
|
|
setData( model, '<paragraph>Foo <$text bold="true">"</$text>Bar[]</paragraph>' );
|
|
|
|
|
|
model.change( writer => {
|
|
|
- writer.insertText( '"', { bold: true }, doc.selection.focus );
|
|
|
+ writer.setSelectionAttribute( { bold: true } );
|
|
|
} );
|
|
|
|
|
|
+ simulateTyping( '"' );
|
|
|
+
|
|
|
expect( getData( model, { withoutSelection: true } ) )
|
|
|
.to.equal( '<paragraph>Foo <$text bold="true">“</$text>Bar<$text bold="true">”</$text></paragraph>' );
|
|
|
} );
|
|
|
@@ -114,9 +139,7 @@ describe( 'Text transformation feature', () => {
|
|
|
it( 'should keep styles of the replaced text #2', () => {
|
|
|
setData( model, '<paragraph>F<$text bold="true">oo "B</$text>ar[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '"', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '"' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) )
|
|
|
.to.equal( '<paragraph>F<$text bold="true">oo “B</$text>ar”</paragraph>' );
|
|
|
@@ -126,13 +149,7 @@ describe( 'Text transformation feature', () => {
|
|
|
it( `should transform "${ transformFrom }" to "${ transformTo }"`, () => {
|
|
|
setData( model, `<paragraph>${ textInParagraph }[]</paragraph>` );
|
|
|
|
|
|
- const letters = transformFrom.split( '' );
|
|
|
-
|
|
|
- for ( const letter of letters ) {
|
|
|
- model.enqueueChange( model.createBatch(), writer => {
|
|
|
- writer.insertText( letter, doc.selection.focus );
|
|
|
- } );
|
|
|
- }
|
|
|
+ simulateTyping( transformFrom );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) )
|
|
|
.to.equal( `<paragraph>${ textInParagraph }${ transformTo }</paragraph>` );
|
|
|
@@ -170,9 +187,7 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.enqueueChange( model.createBatch(), writer => {
|
|
|
- writer.insertText( 'CKE', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( 'CKE' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>CKEditor</paragraph>' );
|
|
|
} );
|
|
|
@@ -190,9 +205,7 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.enqueueChange( model.createBatch(), writer => {
|
|
|
- writer.insertText( 'user@example.com', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( 'user@example.com' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>user.at.example.com</paragraph>' );
|
|
|
} );
|
|
|
@@ -210,9 +223,7 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>Foo. []</paragraph>' );
|
|
|
|
|
|
- model.enqueueChange( model.createBatch(), writer => {
|
|
|
- writer.insertText( 'b', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( 'b' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>Foo. B</paragraph>' );
|
|
|
} );
|
|
|
@@ -230,15 +241,11 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( 'CKE', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( 'CKE' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>CKEditor</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(tm)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(tm)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>CKEditor™</paragraph>' );
|
|
|
} );
|
|
|
@@ -256,15 +263,11 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( 'CKE', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( 'CKE' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>CKEditor</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(tm)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(tm)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>CKEditor(tm)</paragraph>' );
|
|
|
} );
|
|
|
@@ -281,15 +284,11 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(tm)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(tm)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>(tm)</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(r)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(r)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>(tm)®</paragraph>' );
|
|
|
} );
|
|
|
@@ -306,15 +305,11 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(tm)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(tm)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>(tm)</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '...', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '...' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>(tm)…</paragraph>' );
|
|
|
} );
|
|
|
@@ -340,9 +335,7 @@ describe( 'Text transformation feature', () => {
|
|
|
} ).then( () => {
|
|
|
setData( model, '<paragraph>[]</paragraph>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '(tm)', doc.selection.focus );
|
|
|
- } );
|
|
|
+ simulateTyping( '(tm)' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>™</paragraph>' );
|
|
|
} );
|
|
|
@@ -352,7 +345,7 @@ describe( 'Text transformation feature', () => {
|
|
|
function createEditorInstance( additionalConfig = {} ) {
|
|
|
return ClassicTestEditor
|
|
|
.create( editorElement, Object.assign( {
|
|
|
- plugins: [ Paragraph, Bold, TextTransformation ]
|
|
|
+ plugins: [ Typing, Paragraph, Bold, TextTransformation ]
|
|
|
}, additionalConfig ) )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
@@ -361,4 +354,12 @@ describe( 'Text transformation feature', () => {
|
|
|
doc = model.document;
|
|
|
} );
|
|
|
}
|
|
|
+
|
|
|
+ function simulateTyping( transformFrom ) {
|
|
|
+ const letters = transformFrom.split( '' );
|
|
|
+
|
|
|
+ for ( const letter of letters ) {
|
|
|
+ editor.execute( 'input', { text: letter } );
|
|
|
+ }
|
|
|
+ }
|
|
|
} );
|