unwrap.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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( 'unwrap', () => {
  15. describe( 'by unwrap', () => {
  16. it( 'unwrap two siblings', () => {
  17. john.setData(
  18. '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' +
  19. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  20. );
  21. kate.setData(
  22. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  23. '<blockQuote>[]<paragraph>Bar</paragraph></blockQuote>'
  24. );
  25. john.unwrap();
  26. kate.unwrap();
  27. syncClients();
  28. expectClients(
  29. '<paragraph>Foo</paragraph>' +
  30. '<paragraph>Bar</paragraph>'
  31. );
  32. } );
  33. it( 'unwrap two siblings then undo', () => {
  34. john.setData(
  35. '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' +
  36. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  37. );
  38. kate.setData(
  39. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  40. '<blockQuote>[]<paragraph>Bar</paragraph></blockQuote>'
  41. );
  42. john.unwrap();
  43. kate.unwrap();
  44. syncClients();
  45. john.undo();
  46. kate.undo();
  47. syncClients();
  48. expectClients(
  49. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  50. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  51. );
  52. } );
  53. it( 'text in different path', () => {
  54. john.setData(
  55. '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' +
  56. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  57. );
  58. kate.setData(
  59. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  60. '<blockQuote><paragraph>[]Bar</paragraph></blockQuote>'
  61. );
  62. john.unwrap();
  63. kate.unwrap();
  64. syncClients();
  65. expectClients(
  66. '<blockQuote>Foo</blockQuote>' +
  67. '<blockQuote>Bar</blockQuote>'
  68. );
  69. } );
  70. it( 'the same element', () => {
  71. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  72. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  73. john.unwrap();
  74. kate.unwrap();
  75. syncClients();
  76. expectClients( '<paragraph>Foo</paragraph>' );
  77. } );
  78. it( 'the same element, then undo', () => {
  79. john.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  80. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  81. john.unwrap();
  82. kate.unwrap();
  83. syncClients();
  84. expectClients( '<paragraph>Foo</paragraph>' );
  85. john.undo();
  86. syncClients();
  87. // Below would be the expected effect with correct wrap transformation.
  88. // expectClients( '<paragraph>Foo</paragraph>' );
  89. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  90. kate.undo();
  91. syncClients();
  92. // Below would be the expected effect with correct wrap transformation.
  93. // expectClients( '<paragraph>Foo</paragraph>' );
  94. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  95. } );
  96. } );
  97. describe( 'by delete', () => {
  98. it( 'text from two elements #1', () => {
  99. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote><paragraph>Bar</paragraph>' );
  100. kate.setData( '<blockQuote><paragraph>Fo[o</paragraph></blockQuote><paragraph>Ba]r</paragraph>' );
  101. john.unwrap();
  102. kate.delete();
  103. syncClients();
  104. expectClients( '<paragraph>For</paragraph>' );
  105. } );
  106. it( 'text in same path', () => {
  107. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  108. kate.setData( '<blockQuote><paragraph>F[oo]</paragraph></blockQuote>' );
  109. john.unwrap();
  110. kate.delete();
  111. syncClients();
  112. expectClients( '<paragraph>F</paragraph>' );
  113. } );
  114. } );
  115. describe( 'by merge', () => {
  116. it( 'element into paragraph #1', () => {
  117. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph></blockQuote>' );
  118. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  119. john.unwrap();
  120. kate.merge();
  121. syncClients();
  122. expectClients( '<paragraph>FooBar</paragraph>' );
  123. } );
  124. it( 'element into paragraph #2', () => {
  125. john.setData( '<blockQuote>[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]</blockQuote>' );
  126. kate.setData( '<blockQuote><paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph></blockQuote>' );
  127. john.unwrap();
  128. kate.merge();
  129. syncClients();
  130. expectClients( '<paragraph>FooBar</paragraph>' );
  131. } );
  132. it( 'unwrapped element', () => {
  133. john.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  134. kate.setData( '<paragraph>Foo</paragraph>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  135. john.unwrap();
  136. kate.merge();
  137. syncClients();
  138. expectClients(
  139. '<paragraph>Foo</paragraph>' +
  140. '<paragraph>Bar</paragraph>'
  141. );
  142. } );
  143. it( 'unwrap merge target element', () => {
  144. john.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  145. kate.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote>[]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  146. john.unwrap();
  147. kate.merge();
  148. syncClients();
  149. // Below would be the expected effect with correct wrap transformation.
  150. // expectClients(
  151. // '<paragraph>Foo</paragraph>' +
  152. // '<paragraph>Bar</paragraph>'
  153. // );
  154. expectClients( '<paragraph>Foo</paragraph>' );
  155. } );
  156. } );
  157. describe( 'by split', () => {
  158. it( 'unwrap, then split and undo', () => {
  159. // This is pretty weird case. Right now it cannot be reproduced with the features that we have.
  160. john.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  161. john.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  162. kate.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } );
  163. kate.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } );
  164. john.setData(
  165. '<listItem>' +
  166. '<blockQuote>' +
  167. '[]' +
  168. '<paragraph>A</paragraph>' +
  169. '<paragraph>B</paragraph>' +
  170. '</blockQuote>' +
  171. '</listItem>'
  172. );
  173. kate.setData(
  174. '<listItem>' +
  175. '<blockQuote>' +
  176. '[]' +
  177. '<paragraph>A</paragraph>' +
  178. '<paragraph>B</paragraph>' +
  179. '</blockQuote>' +
  180. '</listItem>'
  181. );
  182. john.unwrap();
  183. syncClients();
  184. expectClients(
  185. '<listItem>' +
  186. '<paragraph>A</paragraph>' +
  187. '<paragraph>B</paragraph>' +
  188. '</listItem>'
  189. );
  190. john.undo();
  191. kate.setSelection( [ 0, 1 ] );
  192. kate.split();
  193. syncClients();
  194. // Below would be the expected effect with correct wrap transformation.
  195. // expectClients(
  196. // '<listItem>' +
  197. // '<paragraph>A</paragraph>' +
  198. // '</listItem>' +
  199. // '<listItem>' +
  200. // '<paragraph>B</paragraph>' +
  201. // '</listItem>'
  202. // );
  203. expectClients(
  204. '<listItem><blockQuote><paragraph>A</paragraph><paragraph>B</paragraph></blockQuote></listItem><listItem></listItem>'
  205. );
  206. kate.undo();
  207. syncClients();
  208. // Below would be the expected effect with correct wrap transformation.
  209. // expectClients(
  210. // '<listItem>' +
  211. // '<paragraph>A</paragraph>' +
  212. // '<paragraph>B</paragraph>' +
  213. // '</listItem>'
  214. // );
  215. expectClients(
  216. '<listItem><blockQuote><paragraph>A</paragraph><paragraph>B</paragraph></blockQuote></listItem>'
  217. );
  218. } );
  219. } );
  220. describe( 'by wrap', () => {
  221. it( 'unwrap, then undo and wrap #1', () => {
  222. john.setData(
  223. '<blockQuote>' +
  224. '[]' +
  225. '<paragraph>A</paragraph>' +
  226. '<paragraph>B</paragraph>' +
  227. '<paragraph>C</paragraph>' +
  228. '</blockQuote>'
  229. );
  230. kate.setData(
  231. '<blockQuote>' +
  232. '[]' +
  233. '<paragraph>A</paragraph>' +
  234. '<paragraph>B</paragraph>' +
  235. '<paragraph>C</paragraph>' +
  236. '</blockQuote>'
  237. );
  238. john.unwrap();
  239. syncClients();
  240. expectClients(
  241. '<paragraph>A</paragraph>' +
  242. '<paragraph>B</paragraph>' +
  243. '<paragraph>C</paragraph>'
  244. );
  245. john.undo();
  246. kate.setSelection( [ 1 ], [ 2 ] );
  247. kate.wrap( 'blockQuote' );
  248. syncClients();
  249. expectClients(
  250. '<blockQuote>' +
  251. '<paragraph>A</paragraph>' +
  252. '<paragraph>B</paragraph>' +
  253. '<paragraph>C</paragraph>' +
  254. '</blockQuote>'
  255. );
  256. } );
  257. it( 'unwrap, then undo and wrap #2', () => {
  258. john.setData(
  259. '<paragraph>A</paragraph>' +
  260. '<blockQuote>' +
  261. '[]' +
  262. '<paragraph>B</paragraph>' +
  263. '</blockQuote>' +
  264. '<paragraph>C</paragraph>'
  265. );
  266. kate.setData(
  267. '<paragraph>A</paragraph>' +
  268. '<blockQuote>' +
  269. '[]' +
  270. '<paragraph>B</paragraph>' +
  271. '</blockQuote>' +
  272. '<paragraph>C</paragraph>'
  273. );
  274. john.unwrap();
  275. syncClients();
  276. expectClients(
  277. '<paragraph>A</paragraph>' +
  278. '<paragraph>B</paragraph>' +
  279. '<paragraph>C</paragraph>'
  280. );
  281. john.undo();
  282. kate.setSelection( [ 1 ], [ 2 ] );
  283. kate.wrap( 'blockQuote' );
  284. syncClients();
  285. expectClients(
  286. '<paragraph>A</paragraph>' +
  287. '<blockQuote>' +
  288. '<paragraph>B</paragraph>' +
  289. '</blockQuote>' +
  290. '<paragraph>C</paragraph>'
  291. );
  292. } );
  293. } );
  294. } );
  295. } );