rename.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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( 'text in different path', () => {
  97. john.setData( '<paragraph>[]Foo</paragraph><paragraph>Bar</paragraph>' );
  98. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  99. john.rename( 'heading1' );
  100. kate.wrap( 'div' );
  101. syncClients();
  102. expectClients(
  103. '<heading1>Foo</heading1>' +
  104. '<paragraph><div>Bar</div></paragraph>'
  105. );
  106. } );
  107. it( 'element in same path', () => {
  108. john.setData( '<paragraph>[]Foo</paragraph>' );
  109. kate.setData( '[<paragraph>Foo</paragraph>]' );
  110. john.rename( 'heading1' );
  111. kate.wrap( 'blockQuote' );
  112. syncClients();
  113. expectClients( '<blockQuote><heading1>Foo</heading1></blockQuote>' );
  114. } );
  115. it( 'text in same path', () => {
  116. john.setData( '<paragraph>[]Foo</paragraph>' );
  117. kate.setData( '<paragraph>[Foo]</paragraph>' );
  118. john.rename( 'heading1' );
  119. kate.wrap( 'div' );
  120. syncClients();
  121. expectClients( '<heading1><div>Foo</div></heading1>' );
  122. } );
  123. } );
  124. describe( 'by unwrap', () => {
  125. it( 'element in different path', () => {
  126. john.setData( '<paragraph>F[]oo</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  127. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  128. john.rename( 'heading1' );
  129. kate.unwrap();
  130. syncClients();
  131. expectClients(
  132. '<heading1>Foo</heading1>' +
  133. '<paragraph>Bar</paragraph>'
  134. );
  135. } );
  136. it( 'text in different path', () => {
  137. john.setData( '<paragraph>F[]oo</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  138. kate.setData( '<paragraph>Foo</paragraph><blockQuote><paragraph>[]Bar</paragraph></blockQuote>' );
  139. john.rename( 'heading1' );
  140. kate.unwrap();
  141. syncClients();
  142. expectClients(
  143. '<heading1>Foo</heading1>' +
  144. '<blockQuote>Bar</blockQuote>'
  145. );
  146. } );
  147. it( 'element in same path', () => {
  148. john.setData( '<blockQuote><paragraph>F[]oo</paragraph></blockQuote>' );
  149. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  150. john.rename( 'heading1' );
  151. kate.unwrap();
  152. syncClients();
  153. expectClients( '<heading1>Foo</heading1>' );
  154. } );
  155. it( 'text in same path', () => {
  156. john.setData( '<blockQuote><paragraph>F[]oo</paragraph></blockQuote>' );
  157. kate.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
  158. john.rename( 'heading1' );
  159. kate.unwrap();
  160. syncClients();
  161. expectClients( '<blockQuote>Foo</blockQuote>' );
  162. } );
  163. } );
  164. describe( 'by merge', () => {
  165. it( 'element into paragraph #1', () => {
  166. john.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  167. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  168. john.rename( 'heading1' );
  169. kate.merge();
  170. syncClients();
  171. expectClients( '<heading1>FooBar</heading1>' );
  172. } );
  173. it( 'element into paragraph #2', () => {
  174. john.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  175. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  176. john.rename( 'heading1' );
  177. kate.merge();
  178. syncClients();
  179. expectClients( '<paragraph>FooBar</paragraph>' );
  180. } );
  181. it( 'wrapped element into wrapped paragraph #1', () => {
  182. john.setData( '<blockQuote><paragraph>F[]oo</paragraph><paragraph>Bar</paragraph></blockQuote>' );
  183. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  184. john.rename( 'heading1' );
  185. kate.merge();
  186. syncClients();
  187. expectClients( '<blockQuote><heading1>FooBar</heading1></blockQuote>' );
  188. } );
  189. it( 'wrapped element into wrapped paragraph #2', () => {
  190. john.setData( '<blockQuote><paragraph>Foo</paragraph><paragraph>B[]ar</paragraph></blockQuote>' );
  191. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  192. john.rename( 'heading1' );
  193. kate.merge();
  194. syncClients();
  195. expectClients( '<blockQuote><paragraph>FooBar</paragraph></blockQuote>' );
  196. } );
  197. } );
  198. } );
  199. } );