texttransformation.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  6. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  7. import TextTransformation from '../src/texttransformation';
  8. import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. describe( 'Text transformation feature', () => {
  11. let editorElement, editor, model, doc;
  12. beforeEach( () => {
  13. editorElement = global.document.createElement( 'div' );
  14. global.document.body.appendChild( editorElement );
  15. return ClassicTestEditor
  16. .create( editorElement, {
  17. plugins: [ Paragraph, TextTransformation ]
  18. } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. model = editor.model;
  22. doc = model.document;
  23. } );
  24. } );
  25. afterEach( () => {
  26. editorElement.remove();
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( TextTransformation ) ).to.instanceOf( TextTransformation );
  31. } );
  32. it( 'has proper name', () => {
  33. expect( TextTransformation.pluginName ).to.equal( 'TextTransformation' );
  34. } );
  35. describe( 'transformations', () => {
  36. testTransformation( '(c)', '©' );
  37. testTransformation( '(tm)', '™' );
  38. testTransformation( '1/2', '½' );
  39. testTransformation( '<=', '≤' );
  40. testTransformation( '"Foo bar baz"', '„Foo bar baz”' );
  41. function testTransformation( transformFrom, transformTo ) {
  42. it( `should transform ${ transformFrom } to ${ transformTo }`, () => {
  43. setData( model, '<paragraph>[]</paragraph>' );
  44. model.change( writer => {
  45. writer.insertText( transformFrom, doc.selection.getFirstPosition() );
  46. } );
  47. expect( getData( model ) ).to.equal( '<paragraph>' + transformTo + '[]</paragraph>' );
  48. } );
  49. }
  50. } );
  51. } );