basichtmlwriter.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import BasicHtmlWriter from '../../src/dataprocessor/basichtmlwriter';
  7. describe( 'BasicHtmlWriter', () => {
  8. const basicHtmlWriter = new BasicHtmlWriter();
  9. it( 'should return empty string when empty DocumentFragment is passed', () => {
  10. const data = basicHtmlWriter.getHtml( document.createDocumentFragment() );
  11. expect( data ).to.equal( '' );
  12. } );
  13. it( 'should create text from single text node', () => {
  14. const text = 'foo bar';
  15. const fragment = document.createDocumentFragment();
  16. const textNode = document.createTextNode( text );
  17. fragment.appendChild( textNode );
  18. const data = basicHtmlWriter.getHtml( fragment );
  19. expect( data ).to.equal( text );
  20. } );
  21. it( 'should return correct HTML from fragment with paragraph', () => {
  22. const fragment = document.createDocumentFragment();
  23. const paragraph = document.createElement( 'p' );
  24. paragraph.textContent = 'foo bar';
  25. fragment.appendChild( paragraph );
  26. const data = basicHtmlWriter.getHtml( fragment );
  27. expect( data ).to.equal( '<p>foo bar</p>' );
  28. } );
  29. it( 'should return correct HTML from fragment with multiple child nodes', () => {
  30. const fragment = document.createDocumentFragment();
  31. const text = document.createTextNode( 'foo bar' );
  32. const paragraph = document.createElement( 'p' );
  33. const div = document.createElement( 'div' );
  34. paragraph.textContent = 'foo';
  35. div.textContent = 'bar';
  36. fragment.appendChild( text );
  37. fragment.appendChild( paragraph );
  38. fragment.appendChild( div );
  39. const data = basicHtmlWriter.getHtml( fragment );
  40. expect( data ).to.equal( 'foo bar<p>foo</p><div>bar</div>' );
  41. } );
  42. } );