8
0

attribute.js 25 KB

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