rename.js 6.7 KB

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