texttransformation-integration.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2019, 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. describe( 'Text transformation feature - integration', () => {
  12. let editorElement, editor, model, doc;
  13. testUtils.createSinonSandbox();
  14. beforeEach( () => {
  15. editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. } );
  18. afterEach( () => {
  19. editorElement.remove();
  20. return editor.destroy();
  21. } );
  22. describe.skip( 'with undo', () => {
  23. beforeEach( () => {
  24. return ClassicTestEditor
  25. .create( editorElement, { plugins: [ Paragraph, TextTransformation, UndoEditing ] } )
  26. .then( newEditor => {
  27. editor = newEditor;
  28. model = editor.model;
  29. doc = model.document;
  30. } );
  31. } );
  32. it( 'should undo text transformation', () => {
  33. editor.setData( '<p>foo</p>' );
  34. model.enqueueChange( model.createBatch(), writer => {
  35. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  36. writer.insertText( '(c', doc.selection.focus );
  37. } );
  38. model.enqueueChange( model.createBatch(), writer => {
  39. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  40. writer.insertText( ')', doc.selection.focus );
  41. } );
  42. expect( editor.getData(), 'inserted text' ).to.equal( '<p>foo©</p>' );
  43. editor.execute( 'undo' );
  44. expect( editor.getData(), 'after undo' ).to.equal( '<p>foo(c)</p>' );
  45. editor.execute( 'redo' );
  46. expect( editor.getData(), 'after redo' ).to.equal( '<p>foo©</p>' );
  47. } );
  48. it( 'should allow to undo-redo steps', () => {
  49. editor.setData( '<p></p>' );
  50. model.enqueueChange( model.createBatch(), writer => {
  51. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  52. writer.insertText( 'foo bar baz(c', doc.selection.focus );
  53. } );
  54. model.enqueueChange( model.createBatch(), writer => {
  55. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  56. writer.insertText( ')', doc.selection.focus );
  57. } );
  58. expect( editor.getData() ).to.equal( '<p>foo bar baz©</p>' );
  59. editor.execute( 'undo' );
  60. expect( editor.getData() ).to.equal( '<p>foo bar baz(c)</p>' );
  61. editor.execute( 'undo' );
  62. expect( editor.getData() ).to.equal( '<p>foo bar baz(c</p>' );
  63. editor.execute( 'redo' );
  64. expect( editor.getData() ).to.equal( '<p>foo bar baz(c)</p>' );
  65. editor.execute( 'redo' );
  66. expect( editor.getData() ).to.equal( '<p>foo bar baz©</p>' );
  67. } );
  68. } );
  69. } );