8
0

viewtoplaintext.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import viewToPlainText from '../../src/utils/viewtoplaintext';
  6. import { parse as parseView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  7. describe( 'viewToPlainText()', () => {
  8. function test( viewString, expectedText ) {
  9. const view = parseView( viewString );
  10. const text = viewToPlainText( view );
  11. expect( text ).to.equal( expectedText );
  12. }
  13. it( 'should output text contents of given view', () => {
  14. test(
  15. '<container:p>Foo<strong>Bar</strong>Xyz</container:p>',
  16. 'FooBarXyz'
  17. );
  18. } );
  19. it( 'should put empty line between container elements', () => {
  20. test(
  21. '<container:h1>Header</container:h1>' +
  22. '<container:p>Foo</container:p>' +
  23. '<container:p>Bar</container:p>' +
  24. 'Abc' +
  25. '<container:div>Xyz</container:div>',
  26. 'Header\n\nFoo\n\nBar\n\nAbc\n\nXyz'
  27. );
  28. } );
  29. it( 'should output alt attribute of image elements', () => {
  30. test(
  31. '<container:p>Foo</container:p>' +
  32. '<img src="foo.jpg" alt="Alt" />',
  33. 'Foo\n\nAlt'
  34. );
  35. } );
  36. it( 'should not put empty line after li (if not needed)', () => {
  37. test(
  38. '<container:p>Foo</container:p>' +
  39. '<container:ul>' +
  40. '<container:li>A</container:li>' +
  41. '<container:li>B</container:li>' +
  42. '<container:li>C</container:li>' +
  43. '</container:ul>' +
  44. '<container:p>Bar</container:p>',
  45. 'Foo\n\nA\nB\nC\n\nBar'
  46. );
  47. } );
  48. it( 'should not put empty line before/after figcaption (if not needed)', () => {
  49. test(
  50. '<container:p>Foo</container:p>' +
  51. '<container:figure>' +
  52. '<img src="foo.jpg" alt="Alt" />' +
  53. '<container:figcaption>Caption</container:figcaption>' +
  54. '</container:figure>' +
  55. '<container:p>Bar</container:p>',
  56. 'Foo\n\nAlt\nCaption\n\nBar'
  57. );
  58. } );
  59. } );