8
0

merge.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import { Client, syncClients, expectClients, clearBuffer } from './utils.js';
  2. describe( 'transform', () => {
  3. let john, kate;
  4. beforeEach( () => {
  5. return Promise.all( [
  6. Client.get( 'john' ).then( client => ( john = client ) ),
  7. Client.get( 'kate' ).then( client => ( kate = client ) )
  8. ] );
  9. } );
  10. afterEach( () => {
  11. clearBuffer();
  12. return Promise.all( [ john.destroy(), kate.destroy() ] );
  13. } );
  14. describe( 'merge', () => {
  15. describe( 'by merge', () => {
  16. it( 'elements into paragraph', () => {
  17. john.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph><paragraph>Abc</paragraph>' );
  18. kate.setData( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>[]<paragraph>Abc</paragraph>' );
  19. john.merge();
  20. kate.merge();
  21. syncClients();
  22. expectClients( '<paragraph>FooBarAbc</paragraph>' );
  23. } );
  24. it.skip( 'same element with undo', () => {
  25. // Unnecessary SplitOperation.
  26. john.setData( '<paragraph>Foo</paragraph>[]<paragraph></paragraph>' );
  27. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph></paragraph>' );
  28. john.merge();
  29. kate.merge();
  30. kate.undo();
  31. syncClients();
  32. expectClients( '<paragraph>Foo</paragraph>' );
  33. } );
  34. } );
  35. describe( 'by delete', () => {
  36. it( 'text from two elements', () => {
  37. john.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  38. kate.setData( '<paragraph>Fo[o</paragraph><paragraph>Ba]r</paragraph>' );
  39. john.merge();
  40. kate.delete();
  41. syncClients();
  42. expectClients( '<paragraph>For</paragraph>' );
  43. } );
  44. } );
  45. describe( 'by wrap', () => {
  46. it( 'wrap merged element', () => {
  47. john.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  48. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  49. john.merge();
  50. kate.wrap( 'blockQuote' );
  51. syncClients();
  52. expectClients( '<paragraph>FooBar</paragraph>' );
  53. john.undo();
  54. kate.undo();
  55. syncClients();
  56. expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  57. } );
  58. it( 'wrap in merged element', () => {
  59. // This is pretty weird case. Right now it cannot be reproduced with the features that we have.
  60. john.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  61. john.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  62. kate.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  63. kate.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  64. john.setData(
  65. '<listItem>' +
  66. '<paragraph>A</paragraph>' +
  67. '</listItem>' +
  68. '[]' +
  69. '<listItem>' +
  70. '<paragraph>B</paragraph>' +
  71. '<paragraph>C</paragraph>' +
  72. '</listItem>'
  73. );
  74. kate.setData(
  75. '<listItem>' +
  76. '<paragraph>A</paragraph>' +
  77. '</listItem>' +
  78. '<listItem>' +
  79. '[<paragraph>B</paragraph>' +
  80. '<paragraph>C</paragraph>]' +
  81. '</listItem>'
  82. );
  83. john.merge();
  84. kate.wrap( 'blockQuote' );
  85. syncClients();
  86. expectClients(
  87. '<listItem>' +
  88. '<paragraph>A</paragraph>' +
  89. '<blockQuote>' +
  90. '<paragraph>B</paragraph>' +
  91. '<paragraph>C</paragraph>' +
  92. '</blockQuote>' +
  93. '</listItem>'
  94. );
  95. } );
  96. } );
  97. describe( 'by unwrap', () => {
  98. it( 'merge to unwrapped element', () => {
  99. john.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  100. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  101. john.merge();
  102. kate.unwrap();
  103. syncClients();
  104. expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  105. } );
  106. it( 'merge to unwrapped element with undo #1', () => {
  107. john.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  108. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  109. john.merge();
  110. john.undo();
  111. kate.unwrap();
  112. syncClients();
  113. expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  114. } );
  115. it( 'merge to unwrapped element with undo #2', () => {
  116. john.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  117. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  118. john.merge();
  119. kate.unwrap();
  120. kate.undo();
  121. syncClients();
  122. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote><paragraph>Bar</paragraph>' );
  123. } );
  124. it( 'unwrap in merged element', () => {
  125. // This is pretty weird case. Right now it cannot be reproduced with the features that we have.
  126. john.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  127. john.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  128. kate.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  129. kate.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  130. john.setData(
  131. '<listItem>' +
  132. '<paragraph>A</paragraph>' +
  133. '</listItem>' +
  134. '[]' +
  135. '<listItem>' +
  136. '<blockQuote>' +
  137. '<paragraph>B</paragraph>' +
  138. '<paragraph>C</paragraph>' +
  139. '</blockQuote>' +
  140. '</listItem>'
  141. );
  142. kate.setData(
  143. '<listItem>' +
  144. '<paragraph>A</paragraph>' +
  145. '</listItem>' +
  146. '<listItem>' +
  147. '<blockQuote>' +
  148. '[]<paragraph>B</paragraph>' +
  149. '<paragraph>C</paragraph>' +
  150. '</blockQuote>' +
  151. '</listItem>'
  152. );
  153. john.merge();
  154. kate.unwrap();
  155. syncClients();
  156. expectClients(
  157. '<listItem>' +
  158. '<paragraph>A</paragraph>' +
  159. '<paragraph>B</paragraph>' +
  160. '<paragraph>C</paragraph>' +
  161. '</listItem>'
  162. );
  163. } );
  164. } );
  165. } );
  166. } );