8
0

texttransformation-integration.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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( '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.change( writer => {
  35. writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
  36. writer.insertText( '(tm)', doc.selection.getFirstPosition() );
  37. } );
  38. expect( editor.getData() ).to.equal( '<p>foo™</p>' );
  39. editor.execute( 'undo' );
  40. expect( editor.getData() ).to.equal( '<p>foo(tm)</p>' );
  41. editor.execute( 'redo' );
  42. expect( editor.getData() ).to.equal( '<p>foo™</p>' );
  43. } );
  44. } );
  45. } );