8
0

paragraph-intergration.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Paragraph from 'ckeditor5-paragraph/src/paragraph';
  6. import Clipboard from 'ckeditor5-clipboard/src/clipboard';
  7. import HeadingEngine from 'ckeditor5-heading/src/headingengine';
  8. import VirtualTestEditor from 'ckeditor5-core/tests/_utils/virtualtesteditor';
  9. import {
  10. getData as getModelData,
  11. setData as setModelData
  12. } from 'ckeditor5-engine/src/dev-utils/model';
  13. import { parse as parseView } from 'ckeditor5-engine/src/dev-utils/view';
  14. describe( 'Paragraph feature – integration', () => {
  15. describe( 'with clipboard', () => {
  16. it( 'pastes h1+h2+p as p+p+p when heading feature is not present', () => {
  17. return VirtualTestEditor.create( {
  18. plugins: [ Paragraph, Clipboard ]
  19. } )
  20. .then( newEditor => {
  21. const editor = newEditor;
  22. const doc = editor.document;
  23. setModelData( doc, '<paragraph>[]</paragraph>' );
  24. editor.editing.view.fire( 'clipboardInput', {
  25. content: parseView( '<h1>foo</h1><h2>bar</h2><p>bom</p>' )
  26. } );
  27. expect( getModelData( doc ) ).to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph><paragraph>bom[]</paragraph>' );
  28. } );
  29. } );
  30. // Explainer: the heading feature is configured to handle h2-h4 elements, so h1 has no handler.
  31. it( 'pastes h1+h2+p as p+h2+p when heading feature is present', () => {
  32. return VirtualTestEditor.create( {
  33. plugins: [ Paragraph, Clipboard, HeadingEngine ]
  34. } )
  35. .then( newEditor => {
  36. const editor = newEditor;
  37. const doc = editor.document;
  38. setModelData( doc, '<paragraph>[]</paragraph>' );
  39. editor.editing.view.fire( 'clipboardInput', {
  40. content: parseView( '<h1>foo</h1><h2>bar</h2><p>bom</p>' )
  41. } );
  42. expect( getModelData( doc ) ).to.equal( '<paragraph>foo</paragraph><heading1>bar</heading1><paragraph>bom[]</paragraph>' );
  43. } );
  44. } );
  45. it( 'pastes ul>li+li as p+p when list feature is not present', () => {
  46. return VirtualTestEditor.create( {
  47. plugins: [ Paragraph, Clipboard ]
  48. } )
  49. .then( newEditor => {
  50. const editor = newEditor;
  51. const doc = editor.document;
  52. setModelData( doc, '<paragraph>[]</paragraph>' );
  53. editor.editing.view.fire( 'clipboardInput', {
  54. content: parseView( '<ul><li>foo</li><li>bar</li></ul>' )
  55. } );
  56. expect( getModelData( doc ) ).to.equal( '<paragraph>foo</paragraph><paragraph>bar[]</paragraph>' );
  57. } );
  58. } );
  59. // Check whether the paragraph feature doesn't breaking pasting such content by trying to
  60. // handle the li element.
  61. it( 'pastes ul>li>h2+h3+p as h2+h3+p when heading feature is present', () => {
  62. return VirtualTestEditor.create( {
  63. plugins: [ Paragraph, Clipboard, HeadingEngine ]
  64. } )
  65. .then( newEditor => {
  66. const editor = newEditor;
  67. const doc = editor.document;
  68. setModelData( doc, '<paragraph>[]</paragraph>' );
  69. editor.editing.view.fire( 'clipboardInput', {
  70. content: parseView( '<ul><li>x</li><li><h2>foo</h2><h3>bar</h3><p>bom</p></li><li>x</li></ul>' )
  71. } );
  72. expect( getModelData( doc ) ).to.equal(
  73. '<paragraph>x</paragraph>' +
  74. '<heading1>foo</heading1><heading2>bar</heading2><paragraph>bom</paragraph>' +
  75. '<paragraph>x[]</paragraph>'
  76. );
  77. } );
  78. } );
  79. // See 'should convert ul>li>ul>li+li (in clipboard holder)' in clipboard.js.
  80. it( 'pastes ul>li>ul>li+li', () => {
  81. return VirtualTestEditor.create( {
  82. plugins: [ Paragraph, Clipboard ]
  83. } )
  84. .then( newEditor => {
  85. const editor = newEditor;
  86. const doc = editor.document;
  87. setModelData( doc, '<paragraph>[]</paragraph>' );
  88. editor.editing.view.fire( 'clipboardInput', {
  89. content: parseView( '<ul><li>a<ul><li>b</li><li>c</li></ul></li></ul>' )
  90. } );
  91. expect( getModelData( doc ) ).to.equal(
  92. '<paragraph>a</paragraph>' +
  93. '<paragraph>b</paragraph>' +
  94. '<paragraph>c[]</paragraph>'
  95. );
  96. } );
  97. } );
  98. // See 'should convert ul>li>p,text (in clipboard holder)' in clipboard.js.
  99. it( 'pastes ul>li>p,text', () => {
  100. return VirtualTestEditor.create( {
  101. plugins: [ Paragraph, Clipboard ]
  102. } )
  103. .then( newEditor => {
  104. const editor = newEditor;
  105. const doc = editor.document;
  106. setModelData( doc, '<paragraph>[]</paragraph>' );
  107. editor.editing.view.fire( 'clipboardInput', {
  108. content: parseView( '<ul><li><p>a</p>b</li></ul>' )
  109. } );
  110. expect( getModelData( doc ) ).to.equal(
  111. '<paragraph>a</paragraph>' +
  112. '<paragraph>b[]</paragraph>'
  113. );
  114. } );
  115. } );
  116. } );
  117. } );