utils.js 944 B

123456789101112131415161718192021222324
  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 { modelElementToPlainText } from '../src/utils';
  6. import Element from '@ckeditor/ckeditor5-engine/src/model/element';
  7. import Text from '@ckeditor/ckeditor5-engine/src/model/text';
  8. describe( 'modelElementToPlainText()', () => {
  9. it( 'should extract only plain text', () => {
  10. const text1 = new Text( 'Foo' );
  11. const text2 = new Text( 'Bar', { bold: true } );
  12. const text3 = new Text( 'Baz', { bold: true, underline: true } );
  13. const innerElement1 = new Element( 'paragraph', null, [ text1 ] );
  14. const innerElement2 = new Element( 'paragraph', null, [ text2, text3 ] );
  15. const mainElement = new Element( 'container', null, [ innerElement1, innerElement2 ] );
  16. expect( modelElementToPlainText( mainElement ) ).to.equal( 'Foo\nBarBaz' );
  17. } );
  18. } );