attribute.js 25 KB

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