insert.js 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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( 'insert', () => {
  14. describe( 'by insert', () => {
  15. it( 'elements at same position #1', () => {
  16. john.setData( '[]<paragraph>Foo</paragraph>' );
  17. kate.setData( '[]<paragraph>Foo</paragraph>' );
  18. john.insert( '<paragraph>Abc</paragraph>' );
  19. kate.insert( '<paragraph>Xyz</paragraph>' );
  20. syncClients();
  21. expectClients(
  22. '<paragraph>Abc</paragraph>' +
  23. '<paragraph>Xyz</paragraph>' +
  24. '<paragraph>Foo</paragraph>'
  25. );
  26. } );
  27. it( 'elements at same position #2', () => {
  28. john.setData( '[]<paragraph>Foo</paragraph>' );
  29. kate.setData( '[]<paragraph>Foo</paragraph>' );
  30. kate.insert( '<paragraph>Xyz</paragraph>' );
  31. john.insert( '<paragraph>Abc</paragraph>' );
  32. syncClients();
  33. expectClients(
  34. '<paragraph>Abc</paragraph>' +
  35. '<paragraph>Xyz</paragraph>' +
  36. '<paragraph>Foo</paragraph>'
  37. );
  38. } );
  39. it( 'elements in same parent', () => {
  40. john.setData( '[]<paragraph>Foo</paragraph>' );
  41. kate.setData( '<paragraph>Foo</paragraph>[]' );
  42. john.insert( '<paragraph>Abc</paragraph>' );
  43. kate.insert( '<paragraph>Xyz</paragraph>' );
  44. syncClients();
  45. expectClients(
  46. '<paragraph>Abc</paragraph>' +
  47. '<paragraph>Foo</paragraph>' +
  48. '<paragraph>Xyz</paragraph>'
  49. );
  50. } );
  51. it( 'elements in same path', () => {
  52. john.setData( '[]<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  53. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  54. john.insert( '<paragraph>Abc</paragraph>' );
  55. kate.insert( '<paragraph>Xyz</paragraph>' );
  56. syncClients();
  57. expectClients(
  58. '<paragraph>Abc</paragraph>' +
  59. '<blockQuote>' +
  60. '<paragraph>Xyz</paragraph>' +
  61. '<paragraph>Foo</paragraph>' +
  62. '</blockQuote>'
  63. );
  64. } );
  65. it( 'text at different paths', () => {
  66. john.setData( '<paragraph>Abc[]</paragraph><paragraph>Xyz</paragraph>' );
  67. kate.setData( '<paragraph>Abc</paragraph><paragraph>[]Xyz</paragraph>' );
  68. john.type( 'Foo' );
  69. kate.type( 'Bar' );
  70. syncClients();
  71. expectClients(
  72. '<paragraph>AbcFoo</paragraph>' +
  73. '<paragraph>BarXyz</paragraph>'
  74. );
  75. } );
  76. it( 'text, then wrap and undo', () => {
  77. john.setData( '<paragraph>Foo[]</paragraph>' );
  78. kate.setData( '<paragraph>Foo[]</paragraph>' );
  79. john.type( 'Bar' );
  80. kate.type( 'Abc' );
  81. syncClients();
  82. john.setSelection( [ 0 ], [ 1 ] );
  83. john.wrap( 'blockQuote' );
  84. kate.undo();
  85. syncClients();
  86. expectClients(
  87. '<blockQuote>' +
  88. '<paragraph>FooBar</paragraph>' +
  89. '</blockQuote>'
  90. );
  91. } );
  92. it( 'text, then insert element and merge', () => {
  93. john.setData( '<paragraph>[]</paragraph><paragraph>Abc</paragraph>' );
  94. kate.setData( '<paragraph>[]</paragraph><paragraph>Abc</paragraph>' );
  95. john.type( 'Foo' );
  96. kate.type( ' Bar' );
  97. syncClients();
  98. expectClients(
  99. '<paragraph>Foo Bar</paragraph>' +
  100. '<paragraph>Abc</paragraph>'
  101. );
  102. john.setSelection( [ 1 ] );
  103. kate.setSelection( [ 1 ] );
  104. john.insert( '<paragraph>Xyz</paragraph>' );
  105. kate.merge();
  106. syncClients();
  107. expectClients(
  108. '<paragraph>Foo BarAbc</paragraph>' +
  109. '<paragraph>Xyz</paragraph>'
  110. );
  111. } );
  112. it( 'text, then split and undo', () => {
  113. john.setData( '<paragraph>[]</paragraph>' );
  114. kate.setData( '<paragraph>[]</paragraph>' );
  115. john.type( 'Foo' );
  116. kate.type( ' Bar' );
  117. syncClients();
  118. john.setSelection( [ 0, 1 ] );
  119. kate.setSelection( [ 0, 4 ] );
  120. john.split();
  121. kate.split();
  122. syncClients();
  123. john.undo();
  124. kate.undo();
  125. syncClients();
  126. john.undo();
  127. kate.undo();
  128. syncClients();
  129. expectClients(
  130. '<paragraph></paragraph>'
  131. );
  132. } );
  133. } );
  134. describe( 'by move', () => {
  135. it( 'element at different paths #1', () => {
  136. john.setData( '[]<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  137. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  138. john.insert( '<paragraph>Abc</paragraph>' );
  139. kate.move( [ 1, 0 ] );
  140. syncClients();
  141. expectClients(
  142. '<paragraph>Abc</paragraph>' +
  143. '<paragraph>Foo</paragraph>' +
  144. '<paragraph>arB</paragraph>'
  145. );
  146. } );
  147. it( 'element at different paths #2', () => {
  148. john.setData( '<blockQuote><paragraph>Foo</paragraph>[]</blockQuote><paragraph>Bar</paragraph>' );
  149. kate.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote><paragraph>B[ar]</paragraph>' );
  150. john.insert( '<paragraph>Abc</paragraph>' );
  151. kate.move( [ 0, 0, 0 ] );
  152. syncClients();
  153. expectClients(
  154. '<blockQuote>' +
  155. '<paragraph>arFoo</paragraph>' +
  156. '<paragraph>Abc</paragraph>' +
  157. '</blockQuote>' +
  158. '<paragraph>B</paragraph>'
  159. );
  160. } );
  161. it( 'text at same path', () => {
  162. john.setData( '<paragraph>F[]oo Bar</paragraph>' );
  163. kate.setData( '<paragraph>Foo B[ar]</paragraph>' );
  164. john.type( 'Abc' );
  165. kate.move( [ 0, 0 ] );
  166. syncClients();
  167. expectClients( '<paragraph>arFAbcoo B</paragraph>' );
  168. } );
  169. it( 'text at same position #1', () => {
  170. john.setData( '<paragraph>Foo[] Bar</paragraph>' );
  171. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  172. john.type( 'Abc' );
  173. kate.move( [ 0, 3 ] );
  174. syncClients();
  175. expectClients( '<paragraph>FooBarAbc </paragraph>' );
  176. } );
  177. it( 'text at same position #2', () => {
  178. john.setData( '<paragraph>Foo []Bar</paragraph>' );
  179. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  180. john.type( 'Abc' );
  181. kate.move( [ 0, 0 ] );
  182. syncClients();
  183. expectClients( '<paragraph>BarFoo Abc</paragraph>' );
  184. } );
  185. } );
  186. describe( 'by wrap', () => {
  187. it( 'element in same path', () => {
  188. john.setData( '<paragraph>Foo Bar</paragraph>[]' );
  189. kate.setData( '[<paragraph>Foo Bar</paragraph>]' );
  190. john.insert( '<paragraph>Abc</paragraph>' );
  191. kate.wrap( 'blockQuote' );
  192. syncClients();
  193. expectClients(
  194. '<blockQuote>' +
  195. '<paragraph>Foo Bar</paragraph>' +
  196. '</blockQuote>' +
  197. '<paragraph>Abc</paragraph>'
  198. );
  199. } );
  200. it( 'element in same path', () => {
  201. john.setData( '<paragraph>Foo[]</paragraph>' );
  202. kate.setData( '[<paragraph>Foo</paragraph>]' );
  203. john.type( ' Bar' );
  204. kate.wrap( 'blockQuote' );
  205. syncClients();
  206. expectClients(
  207. '<blockQuote>' +
  208. '<paragraph>Foo Bar</paragraph>' +
  209. '</blockQuote>'
  210. );
  211. } );
  212. it( 'element in different paths', () => {
  213. john.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  214. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  215. john.insert( '<paragraph>Abc</paragraph>' );
  216. kate.wrap( 'blockQuote' );
  217. syncClients();
  218. expectClients(
  219. '<paragraph>Foo</paragraph>' +
  220. '<paragraph>Abc</paragraph>' +
  221. '<blockQuote>' +
  222. '<paragraph>Bar</paragraph>' +
  223. '</blockQuote>'
  224. );
  225. } );
  226. it( 'element in different paths', () => {
  227. john.setData( '<paragraph>Foo</paragraph><paragraph>Bar[]</paragraph>' );
  228. kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  229. john.type( 'Abc' );
  230. kate.wrap( 'blockQuote' );
  231. syncClients();
  232. expectClients(
  233. '<blockQuote>' +
  234. '<paragraph>Foo</paragraph>' +
  235. '</blockQuote>' +
  236. '<paragraph>BarAbc</paragraph>'
  237. );
  238. } );
  239. it( 'element, then unwrap and split', () => {
  240. john.setData( '<paragraph>Foo[]</paragraph>' );
  241. kate.setData( '[<paragraph>Foo</paragraph>]' );
  242. john.type( ' Bar' );
  243. kate.wrap( 'blockQuote' );
  244. syncClients();
  245. expectClients( '<blockQuote><paragraph>Foo Bar</paragraph></blockQuote>' );
  246. john.setSelection( [ 0, 0 ] );
  247. kate.setSelection( [ 0, 0, 2 ] );
  248. john.unwrap();
  249. kate.split();
  250. syncClients();
  251. expectClients(
  252. '<paragraph>Fo</paragraph>' +
  253. '<paragraph>o Bar</paragraph>'
  254. );
  255. } );
  256. it( 'element, then add marker and split', () => {
  257. john.setData( '<paragraph>Foo[]</paragraph>' );
  258. kate.setData( '[<paragraph>Foo</paragraph>]' );
  259. john.type( ' Bar' );
  260. kate.wrap( 'blockQuote' );
  261. syncClients();
  262. john.setSelection( [ 0, 0, 0 ], [ 0, 0, 3 ] );
  263. kate.setSelection( [ 0, 0, 2 ] );
  264. john.setMarker( 'm1' );
  265. kate.split();
  266. syncClients();
  267. expectClients(
  268. '<blockQuote>' +
  269. '<paragraph><m1:start></m1:start>Fo</paragraph>' +
  270. '<paragraph>o<m1:end></m1:end> Bar</paragraph>' +
  271. '</blockQuote>'
  272. );
  273. } );
  274. it( 'element, then insert element and unwrap', () => {
  275. john.setData( '<paragraph>Foo[]</paragraph>' );
  276. kate.setData( '[<paragraph>Foo</paragraph>]' );
  277. john.type( ' Bar' );
  278. kate.wrap( 'blockQuote' );
  279. syncClients();
  280. john.setSelection( [ 0, 0 ] );
  281. kate.setSelection( [ 0, 0 ] );
  282. john.insert( '<paragraph>Abc</paragraph>' );
  283. kate.unwrap();
  284. syncClients();
  285. expectClients(
  286. '<paragraph>Abc</paragraph>' +
  287. '<paragraph>Foo Bar</paragraph>'
  288. );
  289. } );
  290. it( 'element, then split at the same position and undo', () => {
  291. john.setData( '<paragraph>Foo[]</paragraph>' );
  292. kate.setData( '[<paragraph>Foo</paragraph>]' );
  293. john.type( ' Bar' );
  294. kate.wrap( 'blockQuote' );
  295. syncClients();
  296. expectClients( '<blockQuote><paragraph>Foo Bar</paragraph></blockQuote>' );
  297. john.setSelection( [ 0, 0, 3 ] );
  298. kate.setSelection( [ 0, 0, 3 ] );
  299. john.split();
  300. kate.split();
  301. syncClients();
  302. expectClients(
  303. '<blockQuote>' +
  304. '<paragraph>Foo</paragraph>' +
  305. '<paragraph> Bar</paragraph>' +
  306. '</blockQuote>'
  307. );
  308. kate.undo();
  309. syncClients();
  310. // Below is not the best result ever but it is acceptable.
  311. expectClients(
  312. '<blockQuote>' +
  313. '<paragraph>Foo Bar</paragraph>' +
  314. '</blockQuote>'
  315. );
  316. } );
  317. } );
  318. describe( 'by unwrap', () => {
  319. it( 'element in different path', () => {
  320. john.setData( '<paragraph>Foo[]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  321. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  322. john.type( 'Abc' );
  323. kate.unwrap();
  324. syncClients();
  325. expectClients(
  326. '<paragraph>FooAbc</paragraph><paragraph>Bar</paragraph>'
  327. );
  328. } );
  329. it( 'element in same path #1', () => {
  330. john.setData( '<blockQuote><paragraph>Foo[]</paragraph></blockQuote>' );
  331. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  332. john.type( ' Bar' );
  333. kate.unwrap();
  334. syncClients();
  335. expectClients(
  336. '<paragraph>Foo Bar</paragraph>'
  337. );
  338. } );
  339. it( 'element in same path #2', () => {
  340. john.setData( '<blockQuote><paragraph>Foo</paragraph>[]</blockQuote>' );
  341. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  342. john.insert( '<paragraph>Bar</paragraph>' );
  343. kate.unwrap();
  344. syncClients();
  345. expectClients(
  346. '<paragraph>Foo</paragraph>' +
  347. '<paragraph>Bar</paragraph>'
  348. );
  349. } );
  350. it( 'element, then insert text and move', () => {
  351. john.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  352. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  353. john.insert( '<paragraph>Bar</paragraph>' );
  354. kate.unwrap();
  355. syncClients();
  356. expectClients( '<paragraph>Bar</paragraph><paragraph>Foo</paragraph>' );
  357. john.setSelection( [ 0, 0 ] );
  358. kate.setSelection( [ 0, 2 ], [ 0, 3 ] );
  359. john.type( 'Abc' );
  360. kate.move( [ 0, 0 ] );
  361. syncClients();
  362. expectClients(
  363. '<paragraph>rAbcBa</paragraph>' +
  364. '<paragraph>Foo</paragraph>'
  365. );
  366. } );
  367. it( 'element, then insert text and remove', () => {
  368. john.setData( '<blockQuote><paragraph>Foo</paragraph>[]</blockQuote>' );
  369. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  370. john.insert( '<paragraph>Bar</paragraph>' );
  371. kate.unwrap();
  372. syncClients();
  373. john.setSelection( [ 0, 0 ] );
  374. kate.setSelection( [ 0, 0 ], [ 0, 3 ] );
  375. john.type( 'Abc' );
  376. kate.remove();
  377. syncClients();
  378. expectClients(
  379. '<paragraph>Abc</paragraph>' +
  380. '<paragraph>Bar</paragraph>'
  381. );
  382. } );
  383. it( 'element, then wrap and undo on both clients', () => {
  384. john.setData( '<blockQuote><paragraph>Foo</paragraph>[]</blockQuote>' );
  385. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  386. john.insert( '<paragraph>Bar</paragraph>' );
  387. kate.unwrap();
  388. syncClients();
  389. kate.setSelection( [ 0 ], [ 1 ] );
  390. kate.wrap( 'blockQuote' );
  391. john.undo();
  392. syncClients();
  393. expectClients(
  394. '<blockQuote>' +
  395. '<paragraph>Foo</paragraph>' +
  396. '</blockQuote>'
  397. );
  398. } );
  399. it( 'element, then wrap, unwrap and undo', () => {
  400. john.setData( '<blockQuote><paragraph>Foo[]</paragraph></blockQuote>' );
  401. kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
  402. john.type( ' Bar' );
  403. kate.unwrap();
  404. syncClients();
  405. expectClients( '<paragraph>Foo Bar</paragraph>' );
  406. john.setSelection( [ 0 ], [ 1 ] );
  407. john.wrap( 'blockQuote' );
  408. syncClients();
  409. expectClients( '<blockQuote><paragraph>Foo Bar</paragraph></blockQuote>' );
  410. john.undo();
  411. kate.setSelection( [ 0, 0 ], [ 0, 1 ] );
  412. kate.unwrap();
  413. syncClients();
  414. expectClients( '<paragraph>Foo Bar</paragraph>' );
  415. } );
  416. } );
  417. describe( 'by split', () => {
  418. it( 'text in same path #1', () => {
  419. john.setData( '<paragraph>Foo</paragraph>[]' );
  420. kate.setData( '<paragraph>F[]oo</paragraph>' );
  421. john.insert( '<paragraph>Bar</paragraph>' );
  422. kate.split();
  423. syncClients();
  424. expectClients(
  425. '<paragraph>F</paragraph>' +
  426. '<paragraph>oo</paragraph>' +
  427. '<paragraph>Bar</paragraph>'
  428. );
  429. } );
  430. it( 'text in same path #2', () => {
  431. john.setData( '<paragraph>Fo[]o</paragraph>' );
  432. kate.setData( '<paragraph>F[]oo</paragraph>' );
  433. john.type( 'Bar' );
  434. kate.split();
  435. syncClients();
  436. expectClients( '<paragraph>F</paragraph><paragraph>oBaro</paragraph>' );
  437. } );
  438. it( 'text in different paths #1', () => {
  439. john.setData( '[]<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  440. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  441. john.insert( '<paragraph>Abc</paragraph>' );
  442. kate.split();
  443. syncClients();
  444. expectClients(
  445. '<paragraph>Abc</paragraph>' +
  446. '<paragraph>Foo</paragraph>' +
  447. '<paragraph>B</paragraph>' +
  448. '<paragraph>ar</paragraph>'
  449. );
  450. } );
  451. it( 'text in different paths #2', () => {
  452. john.setData( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  453. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  454. john.type( 'Abc' );
  455. kate.split();
  456. syncClients();
  457. expectClients(
  458. '<paragraph>FooAbc</paragraph>' +
  459. '<paragraph>B</paragraph>' +
  460. '<paragraph>ar</paragraph>'
  461. );
  462. } );
  463. it( 'text at same position', () => {
  464. john.setData( '<paragraph>F[]oo</paragraph>' );
  465. kate.setData( '<paragraph>F[]oo</paragraph>' );
  466. john.type( 'Bar' );
  467. kate.split();
  468. syncClients();
  469. expectClients( '<paragraph>FBar</paragraph><paragraph>oo</paragraph>' );
  470. } );
  471. it( 'text at same position #2', () => {
  472. john.setData( '<paragraph>Foo[]</paragraph>' );
  473. kate.setData( '<paragraph>Foo[]</paragraph>' );
  474. john.type( 'Bar' );
  475. kate.split();
  476. syncClients();
  477. expectClients( '<paragraph>FooBar</paragraph><paragraph></paragraph>' );
  478. } );
  479. it( 'text, then insert element and split', () => {
  480. john.setData( '<paragraph>[]Foo</paragraph>' );
  481. kate.setData( '<paragraph>F[]oo</paragraph>' );
  482. john.type( 'Bar' );
  483. kate.split();
  484. syncClients();
  485. john.setSelection( [ 1 ] );
  486. kate.setSelection( [ 1, 1 ] );
  487. john.insert( '<paragraph>Abc</paragraph>' );
  488. kate.split();
  489. syncClients();
  490. expectClients(
  491. '<paragraph>BarF</paragraph>' +
  492. '<paragraph>Abc</paragraph>' +
  493. '<paragraph>o</paragraph>' +
  494. '<paragraph>o</paragraph>'
  495. );
  496. } );
  497. } );
  498. describe( 'by remove', () => {
  499. it( 'text in different path', () => {
  500. john.setData( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  501. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  502. john.type( 'Abc' );
  503. kate.remove();
  504. syncClients();
  505. expectClients(
  506. '<paragraph>FooAbc</paragraph><paragraph></paragraph>'
  507. );
  508. } );
  509. it( 'text in same path', () => {
  510. john.setData( '<paragraph>Foo[]</paragraph>' );
  511. kate.setData( '<paragraph>[Foo]</paragraph>' );
  512. john.type( 'Bar' );
  513. kate.remove();
  514. syncClients();
  515. expectClients(
  516. '<paragraph>Bar</paragraph>'
  517. );
  518. } );
  519. it( 'element in different path', () => {
  520. john.setData( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  521. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  522. john.type( 'Abc' );
  523. kate.remove();
  524. syncClients();
  525. expectClients( '<paragraph>FooAbc</paragraph>' );
  526. } );
  527. it( 'element in same path', () => {
  528. john.setData( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  529. kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  530. john.type( 'Abc' );
  531. kate.remove();
  532. syncClients();
  533. expectClients( '<paragraph>Bar</paragraph>' );
  534. } );
  535. it( 'text, then rename, split and undo', () => {
  536. john.setData( '<paragraph>Foo Bar[]</paragraph>' );
  537. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  538. john.type( 'Bar' );
  539. kate.remove();
  540. syncClients();
  541. expectClients( '<paragraph>Foo Bar</paragraph>' );
  542. john.setSelection( [ 0, 0 ] );
  543. kate.setSelection( [ 0, 4 ] );
  544. john.rename( 'heading1' );
  545. kate.split();
  546. syncClients();
  547. expectClients( '<heading1>Foo </heading1><heading1>Bar</heading1>' );
  548. kate.undo();
  549. syncClients();
  550. expectClients( '<heading1>Foo Bar</heading1>' );
  551. } );
  552. it( 'element, then add marker, split and undo with type #1', () => {
  553. john.setData( '<paragraph>Foo</paragraph>[]' );
  554. kate.setData( '[<paragraph>Foo</paragraph>]' );
  555. john.insert( '<paragraph>Bar</paragraph>' );
  556. kate.remove();
  557. syncClients();
  558. expectClients( '<paragraph>Bar</paragraph><paragraph></paragraph>' ); // Autoparagraphing.
  559. john.setSelection( [ 0, 0 ], [ 0, 3 ] );
  560. kate.setSelection( [ 0, 2 ] );
  561. john.setMarker( 'm1' );
  562. kate.split();
  563. syncClients();
  564. expectClients(
  565. '<paragraph><m1:start></m1:start>Ba</paragraph>' +
  566. '<paragraph>r<m1:end></m1:end></paragraph>' +
  567. '<paragraph></paragraph>'
  568. );
  569. john.undo();
  570. john.setSelection( [ 1, 1 ] );
  571. john.type( 'Abc' );
  572. kate.undo();
  573. syncClients();
  574. expectClients( '<paragraph>BarAbc</paragraph><paragraph></paragraph>' );
  575. kate.undo();
  576. syncClients();
  577. expectClients( '<paragraph>Foo</paragraph><paragraph>BarAbc</paragraph>' );
  578. } );
  579. it( 'element, then add marker, split and undo with type #2', () => {
  580. john.setData( '<paragraph>Foo</paragraph>[]' );
  581. kate.setData( '[<paragraph>Foo</paragraph>]' );
  582. john.insert( '<paragraph>Bar</paragraph>' );
  583. kate.remove();
  584. syncClients();
  585. expectClients( '<paragraph>Bar</paragraph><paragraph></paragraph>' ); // Autoparagraphing.
  586. john.setSelection( [ 0, 0 ], [ 0, 3 ] );
  587. kate.setSelection( [ 0, 2 ] );
  588. john.setMarker( 'm1' );
  589. kate.split();
  590. syncClients();
  591. expectClients(
  592. '<paragraph><m1:start></m1:start>Ba</paragraph>' +
  593. '<paragraph>r<m1:end></m1:end></paragraph>' +
  594. '<paragraph></paragraph>'
  595. );
  596. john.undo();
  597. john.setSelection( [ 1, 1 ] );
  598. john.type( 'Abc' );
  599. kate.undo();
  600. kate.undo();
  601. syncClients();
  602. expectClients( '<paragraph>Foo</paragraph><paragraph>BarAbc</paragraph>' );
  603. } );
  604. } );
  605. describe( 'by merge', () => {
  606. it( 'element into paragraph', () => {
  607. john.setData( '<paragraph>Foo</paragraph><paragraph>[]</paragraph>' );
  608. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph></paragraph>' );
  609. john.type( ' Bar' );
  610. kate.merge();
  611. syncClients();
  612. expectClients(
  613. '<paragraph>Foo Bar</paragraph>'
  614. );
  615. } );
  616. } );
  617. describe( 'by marker', () => {
  618. it( 'in different path #1', () => {
  619. john.setData( '[]<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
  620. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  621. john.insert( '<paragraph>Abc</paragraph>' );
  622. kate.setMarker( 'm1' );
  623. syncClients();
  624. expectClients(
  625. '<paragraph>Abc</paragraph>' +
  626. '<paragraph>Foo</paragraph>' +
  627. '<paragraph><m1:start></m1:start>Bar<m1:end></m1:end></paragraph>'
  628. );
  629. } );
  630. it( 'in different path #2', () => {
  631. john.setData( '<paragraph>Foo[]</paragraph><paragraph>Bar</paragraph>' );
  632. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  633. john.type( 'Abc' );
  634. kate.setMarker( 'm1' );
  635. syncClients();
  636. expectClients(
  637. '<paragraph>FooAbc</paragraph>' +
  638. '<paragraph><m1:start></m1:start>Bar<m1:end></m1:end></paragraph>'
  639. );
  640. } );
  641. it( 'in same path', () => {
  642. john.setData( '<paragraph>[]Foo</paragraph>' );
  643. kate.setData( '<paragraph>Fo[o]</paragraph>' );
  644. john.type( 'Bar' );
  645. kate.setMarker( 'm1' );
  646. syncClients();
  647. expectClients(
  648. '<paragraph>BarFo<m1:start></m1:start>o<m1:end></m1:end></paragraph>'
  649. );
  650. } );
  651. } );
  652. // This should be moved to attribute.js.
  653. describe( 'by remove attribute', () => {
  654. it( 'from element in different path', () => {
  655. john.setData( '<paragraph>[]Foo</paragraph><paragraph bold="true">Bar</paragraph>' );
  656. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  657. john.type( 'Abc' );
  658. kate.removeAttribute( 'bold' );
  659. syncClients();
  660. expectClients( '<paragraph>AbcFoo</paragraph><paragraph>Bar</paragraph>' );
  661. } );
  662. it( 'from text in different path', () => {
  663. john.setData( '<paragraph>[]Foo</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  664. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  665. john.type( 'Abc' );
  666. kate.removeAttribute( 'bold' );
  667. syncClients();
  668. expectClients( '<paragraph>AbcFoo</paragraph><paragraph>Bar</paragraph>' );
  669. } );
  670. it( 'from text in same path', () => {
  671. john.setData( '<paragraph>[]Fo<$text bold="true">o</$text></paragraph>' );
  672. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  673. john.type( 'Bar' );
  674. kate.removeAttribute( 'bold' );
  675. syncClients();
  676. expectClients( '<paragraph>BarFoo</paragraph>' );
  677. } );
  678. it( 'from element in same path', () => {
  679. john.setData( '<paragraph bold="true">[]Foo</paragraph>' );
  680. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  681. john.type( 'Bar' );
  682. kate.removeAttribute( 'bold' );
  683. syncClients();
  684. expectClients( '<paragraph>BarFoo</paragraph>' );
  685. } );
  686. it( 'from text with 2 attributes in same path', () => {
  687. john.setData( '<paragraph>[]Fo<$text bold="true" italic="true">o</$text></paragraph>' );
  688. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  689. john.type( 'Bar' );
  690. kate.removeAttribute( 'bold' );
  691. syncClients();
  692. expectClients(
  693. '<paragraph>BarFo<$text italic="true">o</$text></paragraph>'
  694. );
  695. } );
  696. } );
  697. describe( 'by rename', () => {
  698. it( 'element in different path', () => {
  699. john.setData( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>[]' );
  700. kate.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  701. john.insert( '<paragraph>Abc</paragraph>' );
  702. kate.rename( 'heading1' );
  703. syncClients();
  704. expectClients(
  705. '<heading1>Foo</heading1>' +
  706. '<paragraph>Bar</paragraph>' +
  707. '<paragraph>Abc</paragraph>'
  708. );
  709. } );
  710. it( 'element in same path', () => {
  711. john.setData( '<paragraph>Foo</paragraph>[]' );
  712. kate.setData( '<paragraph>F[]oo</paragraph>' );
  713. john.insert( '<paragraph>Bar</paragraph>' );
  714. kate.rename( 'heading1' );
  715. syncClients();
  716. expectClients(
  717. '<heading1>Foo</heading1>' +
  718. '<paragraph>Bar</paragraph>'
  719. );
  720. } );
  721. it( 'text in same path', () => {
  722. john.setData( '<paragraph>Foo[] Bar</paragraph>' );
  723. kate.setData( '<paragraph>F[]oo Bar</paragraph>' );
  724. john.type( 'Abc' );
  725. kate.rename( 'heading1' );
  726. syncClients();
  727. expectClients( '<heading1>FooAbc Bar</heading1>' );
  728. } );
  729. it( 'text in different paths', () => {
  730. john.setData( '<blockQuote><paragraph>Foo</paragraph></blockQuote><paragraph>B[]ar</paragraph>' );
  731. kate.setData( '<blockQuote><paragraph>F[]oo</paragraph></blockQuote><paragraph>Bar</paragraph>' );
  732. john.type( 'Abc' );
  733. kate.rename( 'heading1' );
  734. syncClients();
  735. expectClients(
  736. '<blockQuote>' +
  737. '<heading1>Foo</heading1>' +
  738. '</blockQuote>' +
  739. '<paragraph>BAbcar</paragraph>'
  740. );
  741. } );
  742. } );
  743. } );
  744. } );