rename.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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( 'rename', () => {
  15. describe( 'by rename', () => {
  16. it( 'elements in different paths #1', () => {
  17. john.setData( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  18. kate.setData( '<paragraph>Foo</paragraph><paragraph>[]Bar</paragraph>' );
  19. john.rename( 'heading1' );
  20. kate.rename( 'heading2' );
  21. syncClients();
  22. expectClients( '<heading1>Foo</heading1><heading2>Bar</heading2>' );
  23. } );
  24. it( 'elements in different paths #2', () => {
  25. john.setData( '<blockQuote>[]<paragraph>Foo Bar</paragraph></blockQuote>' );
  26. kate.setData( '<blockQuote><paragraph>[]Foo Bar</paragraph></blockQuote>' );
  27. john.rename( 'blockQuote2' );
  28. kate.rename( 'heading2' );
  29. syncClients();
  30. expectClients( '<blockQuote2><heading2>Foo Bar</heading2></blockQuote2>' );
  31. } );
  32. it( 'the same element', () => {
  33. john.setData( '<blockQuote><paragraph>[]Foo Bar</paragraph></blockQuote>' );
  34. kate.setData( '<blockQuote><paragraph>[]Foo Bar</paragraph></blockQuote>' );
  35. john.rename( 'heading1' );
  36. kate.rename( 'heading2' );
  37. syncClients();
  38. expectClients( '<blockQuote><heading1>Foo Bar</heading1></blockQuote>' );
  39. } );
  40. } );
  41. describe( 'by split', () => {
  42. it( 'element in different path', () => {
  43. john.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  44. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  45. john.rename( 'heading1' );
  46. kate.split();
  47. syncClients();
  48. expectClients(
  49. '<heading1>Foo</heading1>' +
  50. '<paragraph>B</paragraph>' +
  51. '<paragraph>ar</paragraph>'
  52. );
  53. } );
  54. it( 'element in same path', () => {
  55. john.setData( '<paragraph>[]Foo Bar</paragraph>' );
  56. kate.setData( '<paragraph>Foo []Bar</paragraph>' );
  57. john.rename( 'heading1' );
  58. kate.split();
  59. syncClients();
  60. expectClients( '<heading1>Foo </heading1><heading1>Bar</heading1>' );
  61. } );
  62. it( 'element in same path, then undo', () => {
  63. john.setData( '<paragraph>[]Foo Bar</paragraph>' );
  64. kate.setData( '<paragraph>Foo []Bar</paragraph>' );
  65. john.rename( 'heading1' );
  66. john.undo();
  67. kate.split();
  68. syncClients();
  69. expectClients( '<paragraph>Foo </paragraph><paragraph>Bar</paragraph>' );
  70. } );
  71. it( 'element in other user\'s selection', () => {
  72. john.setData( '<paragraph>[Foo]</paragraph>' );
  73. kate.setData( '<paragraph>F[]oo</paragraph>' );
  74. john.rename( 'heading1' );
  75. kate.split();
  76. syncClients();
  77. expectClients(
  78. '<heading1>F</heading1>' +
  79. '<heading1>oo</heading1>'
  80. );
  81. } );
  82. } );
  83. describe( 'by wrap', () => {
  84. it( 'element in different path', () => {
  85. john.setData( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  86. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  87. john.rename( 'heading1' );
  88. kate.wrap( 'blockQuote' );
  89. syncClients();
  90. expectClients(
  91. '<heading1>Foo</heading1>' +
  92. '<blockQuote>' +
  93. '<paragraph>Bar</paragraph>' +
  94. '</blockQuote>'
  95. );
  96. } );
  97. it( 'element in same path', () => {
  98. john.setData( '<paragraph>[]Foo</paragraph>' );
  99. kate.setData( '[<paragraph>Foo</paragraph>]' );
  100. john.rename( 'heading1' );
  101. kate.wrap( 'blockQuote' );
  102. syncClients();
  103. expectClients( '<blockQuote><heading1>Foo</heading1></blockQuote>' );
  104. } );
  105. } );
  106. describe( 'by unwrap', () => {
  107. it( 'element in different path', () => {
  108. john.setData( '<paragraph>F[]oo</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  109. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  110. john.rename( 'heading1' );
  111. kate.unwrap();
  112. syncClients();
  113. expectClients(
  114. '<heading1>Foo</heading1>' +
  115. '<paragraph>Bar</paragraph>'
  116. );
  117. } );
  118. it( 'text in different path', () => {
  119. john.setData( '<paragraph>F[]oo</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  120. kate.setData( '<paragraph>Foo</paragraph><blockQuote><paragraph>[]Bar</paragraph></blockQuote>' );
  121. john.rename( 'heading1' );
  122. kate.unwrap();
  123. syncClients();
  124. expectClients(
  125. '<heading1>Foo</heading1>' +
  126. '<blockQuote>Bar</blockQuote>'
  127. );
  128. } );
  129. it( 'element in same path', () => {
  130. john.setData( '<blockQuote><paragraph>F[]oo</paragraph></blockQuote>' );
  131. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  132. john.rename( 'heading1' );
  133. kate.unwrap();
  134. syncClients();
  135. expectClients( '<heading1>Foo</heading1>' );
  136. } );
  137. it( 'text in same path', () => {
  138. john.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
  139. kate.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
  140. john.rename( 'heading1' );
  141. kate.unwrap();
  142. syncClients();
  143. expectClients( '<blockQuote>Foo</blockQuote>' );
  144. } );
  145. } );
  146. describe( 'by merge', () => {
  147. it( 'element into paragraph #1', () => {
  148. john.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  149. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  150. john.rename( 'heading1' );
  151. kate.merge();
  152. syncClients();
  153. expectClients( '<heading1>FooBar</heading1>' );
  154. } );
  155. it( 'element into paragraph #2', () => {
  156. john.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  157. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  158. john.rename( 'heading1' );
  159. kate.merge();
  160. syncClients();
  161. expectClients( '<paragraph>FooBar</paragraph>' );
  162. } );
  163. it( 'wrapped element into wrapped paragraph #1', () => {
  164. john.setData( '<blockQuote><paragraph>F[]oo</paragraph><paragraph>Bar</paragraph></blockQuote>' );
  165. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  166. john.rename( 'heading1' );
  167. kate.merge();
  168. syncClients();
  169. expectClients( '<blockQuote><heading1>FooBar</heading1></blockQuote>' );
  170. } );
  171. it( 'wrapped element into wrapped paragraph #2', () => {
  172. john.setData( '<blockQuote><paragraph>Foo</paragraph><paragraph>B[]ar</paragraph></blockQuote>' );
  173. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  174. john.rename( 'heading1' );
  175. kate.merge();
  176. syncClients();
  177. expectClients( '<blockQuote><paragraph>FooBar</paragraph></blockQuote>' );
  178. } );
  179. } );
  180. } );
  181. } );