paragraph-intergration.js 4.9 KB

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