normalizehtml.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import normalizeHtml from '../../tests/_utils/normalizehtml';
  6. describe( 'utils', () => {
  7. describe( 'normalizeHtml', () => {
  8. it( 'should sort attributes', () => {
  9. const actual = '<a style="padding:1px" class="" href="file://"></a>';
  10. const expected = '<a class="" href="file://" style="padding:1px"></a>';
  11. expect( normalizeHtml( actual ) ).to.equal( expected );
  12. } );
  13. it( 'should normalize styles', () => {
  14. const actual = '<a style="padding:1px"></a>';
  15. const expected = '<a style="padding:1px"></a>';
  16. expect( normalizeHtml( actual ) ).to.equal( expected );
  17. } );
  18. it( 'should lowercase attributes', () => {
  19. const actual = '<A CLASS="" HREF="file://" STYLE="padding:1px"></A>';
  20. const expected = '<a class="" href="file://" style="padding:1px"></a>';
  21. expect( normalizeHtml( actual ) ).to.equal( expected );
  22. } );
  23. it( 'should trim whitespace', () => {
  24. const actual = '<a class=" " href="file://" style="padding: 1px"></a>';
  25. const expected = '<a class="" href="file://" style="padding:1px"></a>';
  26. expect( normalizeHtml( actual ) ).to.equal( expected );
  27. } );
  28. it( 'should remove empty style attribute', () => {
  29. const actual = '<a style=""></a>';
  30. const expected = '<a></a>';
  31. expect( normalizeHtml( actual ) ).to.equal( expected );
  32. } );
  33. it( 'should leave empty class attribute', () => {
  34. const actual = '<p class=""></p>';
  35. const expected = '<p class=""></p>';
  36. expect( normalizeHtml( actual ) ).to.equal( expected );
  37. } );
  38. it( 'should sort attribute value', () => {
  39. const actual = '<a class="b c a"></a>';
  40. const expected = '<a class="a b c"></a>';
  41. expect( normalizeHtml( actual ) ).to.equal( expected );
  42. } );
  43. } );
  44. } );