whitespace-handling-integration.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  7. import { getData } from '../../../src/dev-utils/model';
  8. describe( 'DomConverter – whitespace handling – integration', () => {
  9. let editor;
  10. // See https://github.com/ckeditor/ckeditor5-engine/issues/822.
  11. describe( 'data loading', () => {
  12. beforeEach( () => {
  13. return VirtualTestEditor
  14. .create( { plugins: [ Paragraph ] } )
  15. .then( newEditor => {
  16. editor = newEditor;
  17. } );
  18. } );
  19. afterEach( () => {
  20. return editor.destroy();
  21. } );
  22. it( 'new line at the end of the content is ignored', () => {
  23. editor.setData( '<p>foo</p>\n' );
  24. expect( getData( editor.model, { withoutSelection: true } ) )
  25. .to.equal( '<paragraph>foo</paragraph>' );
  26. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  27. } );
  28. it( 'whitespaces at the end of the content are ignored', () => {
  29. editor.setData( '<p>foo</p>\n\r\n \t' );
  30. expect( getData( editor.model, { withoutSelection: true } ) )
  31. .to.equal( '<paragraph>foo</paragraph>' );
  32. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  33. } );
  34. // Controversial result. See https://github.com/ckeditor/ckeditor5-engine/issues/987.
  35. it( 'nbsp at the end of the content is not ignored', () => {
  36. editor.setData( '<p>foo</p>' );
  37. expect( getData( editor.model, { withoutSelection: true } ) )
  38. .to.equal( '<paragraph>foo</paragraph>' );
  39. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  40. } );
  41. it( 'new line at the beginning of the content is ignored', () => {
  42. editor.setData( '\n<p>foo</p>' );
  43. expect( getData( editor.model, { withoutSelection: true } ) )
  44. .to.equal( '<paragraph>foo</paragraph>' );
  45. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  46. } );
  47. it( 'whitespaces at the beginning of the content are ignored', () => {
  48. editor.setData( '\n\n \t<p>foo</p>' );
  49. expect( getData( editor.model, { withoutSelection: true } ) )
  50. .to.equal( '<paragraph>foo</paragraph>' );
  51. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  52. } );
  53. // Controversial result. See https://github.com/ckeditor/ckeditor5-engine/issues/987.
  54. it( 'nbsp at the beginning of the content is not ignored', () => {
  55. editor.setData( '<p>foo</p>' );
  56. expect( getData( editor.model, { withoutSelection: true } ) )
  57. .to.equal( '<paragraph>foo</paragraph>' );
  58. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  59. } );
  60. it( 'new line between blocks is ignored', () => {
  61. editor.setData( '<p>foo</p>\n<p>bar</p>' );
  62. expect( getData( editor.model, { withoutSelection: true } ) )
  63. .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  64. expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
  65. } );
  66. it( 'whitespaces between blocks are ignored', () => {
  67. editor.setData( '<p>foo</p>\n\n \t<p>bar</p>' );
  68. expect( getData( editor.model, { withoutSelection: true } ) )
  69. .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  70. expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
  71. } );
  72. // Controversial result. See https://github.com/ckeditor/ckeditor5-engine/issues/987.
  73. it( 'nbsp between blocks is not ignored', () => {
  74. editor.setData( '<p>foo</p>&nbsp;<p>bar</p>' );
  75. expect( getData( editor.model, { withoutSelection: true } ) )
  76. .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  77. expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
  78. } );
  79. it( 'new lines inside blocks are ignored', () => {
  80. editor.setData( '<p>\nfoo\n</p>' );
  81. expect( getData( editor.model, { withoutSelection: true } ) )
  82. .to.equal( '<paragraph>foo</paragraph>' );
  83. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  84. } );
  85. it( 'whitespaces inside blocks are ignored', () => {
  86. editor.setData( '<p>\n\n \tfoo\n\n \t</p>' );
  87. expect( getData( editor.model, { withoutSelection: true } ) )
  88. .to.equal( '<paragraph>foo</paragraph>' );
  89. expect( editor.getData() ).to.equal( '<p>foo</p>' );
  90. } );
  91. it( 'nbsp inside blocks are not ignored', () => {
  92. editor.setData( '<p>&nbsp;foo&nbsp;</p>' );
  93. expect( getData( editor.model, { withoutSelection: true } ) )
  94. .to.equal( '<paragraph> foo </paragraph>' );
  95. expect( editor.getData() ).to.equal( '<p>&nbsp;foo&nbsp;</p>' );
  96. } );
  97. it( 'all whitespaces together are ignored', () => {
  98. editor.setData( '\n<p>foo\n\r\n \t</p>\n<p> bar</p>' );
  99. expect( getData( editor.model, { withoutSelection: true } ) )
  100. .to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  101. expect( editor.getData() ).to.equal( '<p>foo</p><p>bar</p>' );
  102. } );
  103. } );
  104. } );