attribute.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. } );
  192. describe( 'by move', () => {
  193. it( 'text in different path', () => {
  194. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  195. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  196. john.setAttribute( 'bold', true );
  197. kate.move( [ 1, 0 ] );
  198. syncClients();
  199. expectClients(
  200. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  201. '<paragraph>arB</paragraph>'
  202. );
  203. } );
  204. it( 'text in different path #2', () => {
  205. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  206. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  207. john.setAttribute( 'bold', true );
  208. kate.move( [ 1, 0 ] );
  209. syncClients();
  210. expectClients(
  211. '<paragraph bold="true">Foo</paragraph>' +
  212. '<paragraph>arB</paragraph>'
  213. );
  214. } );
  215. it( 'text in same path', () => {
  216. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  217. kate.setData( '<paragraph>Foo B[ar]</paragraph>' );
  218. john.setAttribute( 'bold', true );
  219. kate.move( [ 0, 4 ] );
  220. syncClients();
  221. expectClients( '<paragraph><$text bold="true">Foo</$text> arB</paragraph>' );
  222. } );
  223. it( 'text to other client\'s selection', () => {
  224. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  225. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  226. john.setAttribute( 'bold', true );
  227. kate.move( [ 0, 1 ] );
  228. syncClients();
  229. expectClients( '<paragraph><$text bold="true">F</$text>Bar<$text bold="true">oo</$text> </paragraph>' );
  230. } );
  231. it( 'text from other client\'s selection', () => {
  232. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  233. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  234. john.setAttribute( 'bold', true );
  235. kate.move( [ 0, 7 ], [ 0, 1 ], [ 0, 3 ] );
  236. syncClients();
  237. expectClients( '<paragraph><$text bold="true">F</$text> Bar<$text bold="true">oo</$text></paragraph>' );
  238. } );
  239. it( 'text from other client\'s selection #2', () => {
  240. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  241. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  242. john.setAttribute( 'bold', true );
  243. kate.move( [ 0, 7 ] );
  244. syncClients();
  245. expectClients( '<paragraph bold="true">F Baroo</paragraph>' );
  246. } );
  247. } );
  248. describe( 'by wrap', () => {
  249. it( 'element into blockQuote in different path', () => {
  250. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  251. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  252. john.setAttribute( 'bold', true );
  253. kate.wrap( 'blockQuote' );
  254. syncClients();
  255. expectClients(
  256. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  257. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  258. );
  259. } );
  260. it( 'element into blockQuote in different path #2', () => {
  261. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  262. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  263. john.setAttribute( 'bold', true );
  264. kate.wrap( 'blockQuote' );
  265. syncClients();
  266. expectClients(
  267. '<paragraph bold="true">Foo</paragraph>' +
  268. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  269. );
  270. } );
  271. it( 'element into blockQuote in same path #1', () => {
  272. john.setData( '<paragraph>[Foo]</paragraph>' );
  273. kate.setData( '[<paragraph>Foo</paragraph>]' );
  274. john.setAttribute( 'bold', true );
  275. kate.wrap( 'blockQuote' );
  276. syncClients();
  277. expectClients(
  278. '<blockQuote>' +
  279. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  280. '</blockQuote>'
  281. );
  282. } );
  283. it( 'element into blockQuote in same path #2', () => {
  284. john.setData( '[<paragraph>Foo</paragraph>]' );
  285. kate.setData( '[<paragraph>Foo</paragraph>]' );
  286. john.setAttribute( 'bold', true );
  287. kate.wrap( 'blockQuote' );
  288. syncClients();
  289. expectClients(
  290. '<blockQuote>' +
  291. '<paragraph bold="true">Foo</paragraph>' +
  292. '</blockQuote>'
  293. );
  294. } );
  295. } );
  296. describe( 'by unwrap', () => {
  297. it( 'element in different path', () => {
  298. john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  299. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  300. john.setAttribute( 'bold', true );
  301. kate.unwrap();
  302. syncClients();
  303. expectClients(
  304. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  305. '<paragraph>Bar</paragraph>'
  306. );
  307. } );
  308. it( 'element in different path #2', () => {
  309. john.setData( '[<paragraph>Foo</paragraph>]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  310. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  311. john.setAttribute( 'bold', true );
  312. kate.unwrap();
  313. syncClients();
  314. expectClients(
  315. '<paragraph bold="true">Foo</paragraph>' +
  316. '<paragraph>Bar</paragraph>'
  317. );
  318. } );
  319. it( 'element in same path #1', () => {
  320. john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
  321. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  322. john.setAttribute( 'bold', true );
  323. kate.unwrap();
  324. syncClients();
  325. expectClients(
  326. '<paragraph><$text bold="true">Foo</$text></paragraph>'
  327. );
  328. } );
  329. it( 'element in same path #2', () => {
  330. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  331. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  332. john.setAttribute( 'bold', true );
  333. kate.unwrap();
  334. syncClients();
  335. expectClients( '<paragraph bold="true">Foo</paragraph>' );
  336. } );
  337. } );
  338. describe( 'by split', () => {
  339. it( 'text in different path', () => {
  340. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  341. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  342. john.setAttribute( 'bold', true );
  343. kate.split();
  344. syncClients();
  345. expectClients(
  346. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  347. '<paragraph>Ba</paragraph>' +
  348. '<paragraph>r</paragraph>'
  349. );
  350. } );
  351. it( 'text in different path #2', () => {
  352. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  353. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  354. john.setAttribute( 'bold', true );
  355. kate.split();
  356. syncClients();
  357. expectClients(
  358. '<paragraph bold="true">Foo</paragraph>' +
  359. '<paragraph>Ba</paragraph>' +
  360. '<paragraph>r</paragraph>'
  361. );
  362. } );
  363. it( 'text in same path #1', () => {
  364. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  365. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  366. john.setAttribute( 'bold', true );
  367. kate.split();
  368. syncClients();
  369. expectClients(
  370. '<paragraph><$text bold="true">Foo</$text> B</paragraph>' +
  371. '<paragraph>ar</paragraph>'
  372. );
  373. } );
  374. it( 'text in other user\'s selection', () => {
  375. john.setData( '<paragraph>[Foo]</paragraph>' );
  376. kate.setData( '<paragraph>Fo[]o</paragraph>' );
  377. john.setAttribute( 'bold', true );
  378. kate.split();
  379. syncClients();
  380. expect(
  381. '<paragraph><$text bold="true">Fo</$text></paragraph>' +
  382. '<paragraph><$text bold="true">o</$text></paragraph>'
  383. );
  384. } );
  385. it( 'text in other user\'s selection #2', () => {
  386. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  387. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  388. john.setAttribute( 'bold', true );
  389. kate.split();
  390. syncClients();
  391. expectClients(
  392. '<paragraph bold="true">Foo B</paragraph>' +
  393. '<paragraph bold="true">ar</paragraph>'
  394. );
  395. } );
  396. it( 'text while changing attribute', () => {
  397. john.setData( '<paragraph><$text attr="foo">Foo B[ar]</$text></paragraph>' );
  398. kate.setData( '<paragraph><$text attr="foo">Foo B[]ar</$text></paragraph>' );
  399. john.setAttribute( 'attr', 'bar' );
  400. kate.split();
  401. syncClients();
  402. expectClients(
  403. '<paragraph><$text attr="foo">Foo B</$text></paragraph>' +
  404. '<paragraph><$text attr="bar">ar</$text></paragraph>'
  405. );
  406. } );
  407. } );
  408. describe( 'by remove', () => {
  409. it( 'text in different path', () => {
  410. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  411. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  412. john.setAttribute( 'bold', true );
  413. kate.remove();
  414. syncClients();
  415. expectClients(
  416. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  417. '<paragraph></paragraph>'
  418. );
  419. } );
  420. it( 'text in same path', () => {
  421. john.setData( '<paragraph>[Fo]o</paragraph>' );
  422. kate.setData( '<paragraph>Fo[o]</paragraph>' );
  423. john.setAttribute( 'bold', true );
  424. kate.remove();
  425. syncClients();
  426. expectClients(
  427. '<paragraph><$text bold="true">Fo</$text></paragraph>'
  428. );
  429. } );
  430. it( 'text in other user\'s selection', () => {
  431. john.setData( '<paragraph>[Foo]</paragraph>' );
  432. kate.setData( '<paragraph>F[oo]</paragraph>' );
  433. john.setAttribute( 'bold', true );
  434. kate.remove();
  435. syncClients();
  436. expectClients(
  437. '<paragraph><$text bold="true">F</$text></paragraph>'
  438. );
  439. } );
  440. } );
  441. describe( 'by remove attribute', () => {
  442. it( 'from element in different path', () => {
  443. john.setData( '<paragraph>[Foo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  444. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  445. john.setAttribute( 'bold', true );
  446. kate.removeAttribute( 'bold' );
  447. syncClients();
  448. expectClients(
  449. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  450. '<paragraph>Bar</paragraph>'
  451. );
  452. } );
  453. it( 'from text in different path', () => {
  454. john.setData( '<paragraph>[Foo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  455. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  456. john.setAttribute( 'bold', true );
  457. kate.removeAttribute( 'bold' );
  458. syncClients();
  459. expectClients(
  460. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  461. '<paragraph>Bar</paragraph>'
  462. );
  463. } );
  464. it( 'from text in same path', () => {
  465. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  466. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  467. john.setAttribute( 'bold', true );
  468. kate.removeAttribute( 'bold' );
  469. syncClients();
  470. expectClients(
  471. '<paragraph><$text bold="true">Fo</$text>o</paragraph>'
  472. );
  473. } );
  474. it( 'from element in same path', () => {
  475. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  476. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  477. john.setAttribute( 'italic', true );
  478. kate.removeAttribute( 'bold' );
  479. syncClients();
  480. expectClients( '<paragraph><$text italic="true">Fo</$text>o</paragraph>' );
  481. } );
  482. it( 'from text with 2 attributes in same path', () => {
  483. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  484. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  485. john.setAttribute( 'bold', true );
  486. kate.removeAttribute( 'bold' );
  487. syncClients();
  488. expectClients(
  489. '<paragraph><$text bold="true">Fo</$text><$text italic="true">o</$text></paragraph>'
  490. );
  491. } );
  492. it( 'from text in other user\'s selection', () => {
  493. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  494. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  495. john.setAttribute( 'italic', true );
  496. kate.removeAttribute( 'bold' );
  497. syncClients();
  498. expectClients(
  499. '<paragraph><$text italic="true">Foo</$text></paragraph>'
  500. );
  501. } );
  502. } );
  503. describe( 'by marker', () => {
  504. it( 'in text at same path', () => {
  505. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  506. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  507. john.setAttribute( 'bold', true );
  508. kate.setMarker( 'm1' );
  509. syncClients();
  510. expectClients( '<paragraph><$text bold="true">Foo</$text> <m1:start></m1:start>Bar<m1:end></m1:end></paragraph>' );
  511. } );
  512. it( 'in text at same path #2', () => {
  513. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  514. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  515. john.setAttribute( 'bold', true );
  516. kate.setMarker( 'm1' );
  517. syncClients();
  518. expectClients(
  519. '<paragraph bold="true">' +
  520. 'Foo <m1:start></m1:start>Bar<m1:end></m1:end>' +
  521. '</paragraph>'
  522. );
  523. } );
  524. it( 'in text in different path', () => {
  525. john.setData( '<paragraph>F[o]o</paragraph><paragraph>Bar</paragraph>' );
  526. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[a]r</paragraph>' );
  527. john.setAttribute( 'bold', true );
  528. kate.setMarker( 'm1' );
  529. syncClients();
  530. expectClients(
  531. '<paragraph>F<$text bold="true">o</$text>o</paragraph>' +
  532. '<paragraph>B<m1:start></m1:start>a<m1:end></m1:end>r</paragraph>'
  533. );
  534. } );
  535. it( 'in text with selection inside other client\'s selection #1', () => {
  536. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  537. kate.setData( '<paragraph>Fo[o B]ar</paragraph>' );
  538. john.setAttribute( 'bold', true );
  539. kate.setMarker( 'm1' );
  540. syncClients();
  541. expectClients(
  542. '<paragraph>' +
  543. '<$text bold="true">Fo</$text><m1:start></m1:start>' +
  544. '<$text bold="true">o B</$text><m1:end></m1:end><$text bold="true">ar</$text>' +
  545. '</paragraph>'
  546. );
  547. } );
  548. it( 'in text with selection inside other client\'s selection #2', () => {
  549. john.setData( '<paragraph>F[oo Ba]r</paragraph>' );
  550. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  551. john.setAttribute( 'bold', true );
  552. kate.setMarker( 'm1' );
  553. syncClients();
  554. expectClients(
  555. '<paragraph>' +
  556. 'F<$text bold="true">oo </$text><m1:start></m1:start><$text bold="true">Ba</$text>r<m1:end></m1:end>' +
  557. '</paragraph>'
  558. );
  559. } );
  560. it( 'in text at same position', () => {
  561. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  562. kate.setData( '<paragraph>[Foo Bar]</paragraph>' );
  563. john.setAttribute( 'bold', true );
  564. kate.setMarker( 'm1' );
  565. syncClients();
  566. expectClients( '<paragraph><m1:start></m1:start><$text bold="true">Foo Bar</$text><m1:end></m1:end></paragraph>' );
  567. } );
  568. } );
  569. describe( 'by merge', () => {
  570. it( 'element into paragraph #1', () => {
  571. john.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  572. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  573. john.setAttribute( 'bold', 'true' );
  574. kate.merge();
  575. syncClients();
  576. expectClients( '<paragraph>FooB<$text bold="true">ar</$text></paragraph>' );
  577. } );
  578. it( 'element into paragraph #2, then undo', () => {
  579. john.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  580. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  581. john.setAttribute( 'bold', 'true' );
  582. kate.merge();
  583. syncClients();
  584. expectClients( '<paragraph>FooBar</paragraph>' );
  585. kate.undo();
  586. syncClients();
  587. expectClients( '<paragraph>Foo</paragraph><paragraph bold="true">Bar</paragraph>' );
  588. } );
  589. } );
  590. } );
  591. describe( 'by rename', () => {
  592. it( 'element in different path', () => {
  593. john.setData( '<paragraph>Foo</paragraph><paragraph>[Ba]r</paragraph>' );
  594. kate.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  595. john.setAttribute( 'bold', true );
  596. kate.rename( 'heading1' );
  597. syncClients();
  598. expectClients(
  599. '<heading1>Foo</heading1>' +
  600. '<paragraph><$text bold="true">Ba</$text>r</paragraph>'
  601. );
  602. } );
  603. it( 'element in same path', () => {
  604. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  605. kate.setData( '<paragraph>[]Foo Bar</paragraph>' );
  606. john.setAttribute( 'bold', true );
  607. kate.rename( 'heading1' );
  608. syncClients();
  609. expectClients(
  610. '<heading1><$text bold="true">Foo Bar</$text></heading1>'
  611. );
  612. } );
  613. it( 'element in user\'s selection', () => {
  614. john.setData( '<paragraph>[Foo]</paragraph>' );
  615. kate.setData( '<paragraph>[Foo]</paragraph>' );
  616. john.setAttribute( 'bold', true );
  617. kate.rename( 'heading1' );
  618. syncClients();
  619. expectClients(
  620. '<heading1><$text bold="true">Foo</$text></heading1>'
  621. );
  622. } );
  623. it( 'element in user\'s selection, then undo', () => {
  624. john.setData( '<paragraph>[Foo]</paragraph>' );
  625. kate.setData( '<paragraph>[Foo]</paragraph>' );
  626. john.setAttribute( 'bold', true );
  627. kate.rename( 'heading1' );
  628. syncClients();
  629. john.undo();
  630. kate.undo();
  631. syncClients();
  632. expectClients(
  633. '<paragraph>Foo</paragraph>'
  634. );
  635. } );
  636. } );
  637. } );