basichtmlwriter.js 1.8 KB

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