texttransformation-integration.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  10. import TextTransformation from '../src/texttransformation';
  11. import Typing from '../src/typing';
  12. describe( 'Text transformation feature - integration', () => {
  13. let editorElement, editor, model, doc;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. } );
  19. afterEach( () => {
  20. editorElement.remove();
  21. return editor.destroy();
  22. } );
  23. describe( 'with undo', () => {
  24. beforeEach( () => {
  25. return ClassicTestEditor
  26. .create( editorElement, { plugins: [ Typing, Paragraph, TextTransformation, UndoEditing ] } )
  27. .then( newEditor => {
  28. editor = newEditor;
  29. model = editor.model;
  30. doc = model.document;
  31. } );
  32. } );
  33. it( 'should undo text transformation', () => {
  34. editor.setData( '<p>foo</p>' );
  35. model.enqueueChange( model.createBatch(), writer => {
  36. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  37. writer.insertText( '(c', doc.selection.focus );
  38. } );
  39. editor.execute( 'input', { text: ')' } );
  40. expect( editor.getData(), 'inserted text' ).to.equal( '<p>foo©</p>' );
  41. editor.execute( 'undo' );
  42. expect( editor.getData(), 'after undo' ).to.equal( '<p>foo(c)</p>' );
  43. editor.execute( 'redo' );
  44. expect( editor.getData(), 'after redo' ).to.equal( '<p>foo©</p>' );
  45. } );
  46. it( 'should allow to undo-redo steps', () => {
  47. editor.setData( '<p></p>' );
  48. model.enqueueChange( model.createBatch(), writer => {
  49. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  50. writer.insertText( 'foo bar baz(c', doc.selection.focus );
  51. } );
  52. editor.execute( 'input', { text: ')' } );
  53. expect( editor.getData() ).to.equal( '<p>foo bar baz©</p>' );
  54. editor.execute( 'undo' );
  55. expect( editor.getData() ).to.equal( '<p>foo bar baz(c)</p>' );
  56. editor.execute( 'undo' );
  57. expect( editor.getData() ).to.equal( '<p>foo bar baz(c</p>' );
  58. editor.execute( 'redo' );
  59. expect( editor.getData() ).to.equal( '<p>foo bar baz(c)</p>' );
  60. editor.execute( 'redo' );
  61. expect( editor.getData() ).to.equal( '<p>foo bar baz©</p>' );
  62. } );
  63. } );
  64. } );