merge.js 6.3 KB

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