attribute.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import { Client, syncClients, expectClients, clearBuffer } from './utils.js';
  6. describe( 'transform', () => {
  7. let john, kate;
  8. beforeEach( () => {
  9. return Promise.all( [
  10. Client.get( 'john' ).then( client => ( john = client ) ),
  11. Client.get( 'kate' ).then( client => ( kate = client ) )
  12. ] );
  13. } );
  14. afterEach( () => {
  15. clearBuffer();
  16. return Promise.all( [ john.destroy(), kate.destroy() ] );
  17. } );
  18. describe( 'attribute', () => {
  19. describe( 'by attribute', () => {
  20. it( 'in text at same path', () => {
  21. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  22. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  23. john.setAttribute( 'bold', true );
  24. kate.setAttribute( 'italic', true );
  25. syncClients();
  26. expectClients( '<paragraph><$text bold="true">Foo</$text> <$text italic="true">Bar</$text></paragraph>' );
  27. } );
  28. it( 'in text at same path, then undo', () => {
  29. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  30. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  31. john.setAttribute( 'bold', true );
  32. kate.setAttribute( 'italic', true );
  33. syncClients();
  34. expectClients( '<paragraph><$text bold="true">Foo</$text> <$text italic="true">Bar</$text></paragraph>' );
  35. john.undo();
  36. syncClients();
  37. expectClients( '<paragraph>Foo <$text italic="true">Bar</$text></paragraph>' );
  38. } );
  39. it( 'in text in different path', () => {
  40. john.setData( '<paragraph>F[o]o</paragraph><paragraph>Bar</paragraph>' );
  41. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[a]r</paragraph>' );
  42. john.setAttribute( 'bold', true );
  43. kate.setAttribute( 'italic', true );
  44. syncClients();
  45. expectClients(
  46. '<paragraph>F<$text bold="true">o</$text>o</paragraph>' +
  47. '<paragraph>B<$text italic="true">a</$text>r</paragraph>'
  48. );
  49. } );
  50. it( 'in text with selection inside other client\'s selection #1', () => {
  51. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  52. kate.setData( '<paragraph>Fo[o B]ar</paragraph>' );
  53. john.setAttribute( 'bold', true );
  54. kate.setAttribute( 'italic', true );
  55. syncClients();
  56. expectClients(
  57. '<paragraph>' +
  58. '<$text bold="true">Fo</$text><$text bold="true" italic="true">o B</$text><$text bold="true">ar</$text>' +
  59. '</paragraph>'
  60. );
  61. } );
  62. it( 'in text with selection inside other client\'s selection #2', () => {
  63. john.setData( '<paragraph>F[oo Ba]r</paragraph>' );
  64. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  65. john.setAttribute( 'bold', true );
  66. kate.setAttribute( 'italic', true );
  67. syncClients();
  68. expectClients(
  69. '<paragraph>' +
  70. 'F' +
  71. '<$text bold="true">oo </$text>' +
  72. '<$text bold="true" italic="true">Ba</$text>' +
  73. '<$text italic="true">r</$text>' +
  74. '</paragraph>'
  75. );
  76. } );
  77. it( 'in text with selection inside other client\'s selection #3', () => {
  78. john.setData( '<paragraph><$text bold="true">[Foo Bar]</$text></paragraph>' );
  79. kate.setData( '<paragraph><$text bold="true">Fo[o] Bar</$text></paragraph>' );
  80. john.setAttribute( 'italic', true );
  81. kate.setAttribute( 'underline', true );
  82. syncClients();
  83. expectClients(
  84. '<paragraph>' +
  85. '<$text bold="true" italic="true">Fo</$text>' +
  86. '<$text bold="true" italic="true" underline="true">o</$text>' +
  87. '<$text bold="true" italic="true"> Bar</$text>' +
  88. '</paragraph>'
  89. );
  90. } );
  91. it( 'in text at same position', () => {
  92. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  93. kate.setData( '<paragraph>[Foo Bar]</paragraph>' );
  94. john.setAttribute( 'bold', true );
  95. kate.setAttribute( 'italic', true );
  96. syncClients();
  97. expectClients( '<paragraph><$text bold="true" italic="true">Foo Bar</$text></paragraph>' );
  98. } );
  99. it( 'in element at same position', () => {
  100. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  101. kate.setData( '[<paragraph>Foo Bar</paragraph>]' );
  102. john.setAttribute( 'bold', true );
  103. kate.setAttribute( 'italic', true );
  104. syncClients();
  105. expectClients( '<paragraph bold="true" italic="true">Foo Bar</paragraph>' );
  106. } );
  107. it( 'in collapsed selection', () => {
  108. john.setData( '<paragraph>F[]oo Bar</paragraph>' );
  109. kate.setData( '<paragraph>F[]oo Bar</paragraph>' );
  110. john.setAttribute( 'bold', true );
  111. kate.setAttribute( 'italic', true );
  112. syncClients();
  113. expectClients( '<paragraph>Foo Bar</paragraph>' );
  114. } );
  115. it( 'in same range, then change attribute', () => {
  116. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  117. kate.setData( '<paragraph>[Foo Bar]</paragraph>' );
  118. john.setAttribute( 'attr', 'foo' );
  119. kate.setAttribute( 'attr', 'bar' );
  120. syncClients();
  121. expectClients( '<paragraph><$text attr="foo">Foo Bar</$text></paragraph>' );
  122. kate.setAttribute( 'attr', 'bar' );
  123. syncClients();
  124. expectClients( '<paragraph><$text attr="bar">Foo Bar</$text></paragraph>' );
  125. } );
  126. // https://github.com/ckeditor/ckeditor5/issues/6265
  127. it( 'on elements on different but intersecting "levels"', () => {
  128. john.setData( '[<table><tableRow><tableCell><paragraph>Foo</paragraph></tableCell></tableRow></table>]' );
  129. kate.setData( '<table><tableRow>[<tableCell><paragraph>Foo</paragraph></tableCell>]</tableRow></table>' );
  130. john.setAttribute( 'attr', 'foo' );
  131. kate.setAttribute( 'attr', 'bar' );
  132. syncClients();
  133. expectClients(
  134. '<table attr="foo"><tableRow><tableCell attr="bar"><paragraph>Foo</paragraph></tableCell></tableRow></table>'
  135. );
  136. } );
  137. } );
  138. describe( 'by insert', () => {
  139. it( 'text in different path', () => {
  140. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  141. kate.setData( '<paragraph>Foo</paragraph><paragraph>[]Bar</paragraph>' );
  142. john.setAttribute( 'bold', true );
  143. kate.type( 'Abc' );
  144. syncClients();
  145. expectClients( '<paragraph><$text bold="true">Foo</$text></paragraph><paragraph>AbcBar</paragraph>' );
  146. } );
  147. it( 'text in different path #2', () => {
  148. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  149. kate.setData( '<paragraph>Foo</paragraph><paragraph>[]Bar</paragraph>' );
  150. john.setAttribute( 'bold', true );
  151. kate.type( 'Abc' );
  152. syncClients();
  153. expectClients( '<paragraph bold="true">Foo</paragraph><paragraph>AbcBar</paragraph>' );
  154. } );
  155. it( 'text at same path', () => {
  156. john.setData( '<paragraph>[F]oo</paragraph>' );
  157. kate.setData( '<paragraph>Foo[]</paragraph>' );
  158. john.setAttribute( 'bold', true );
  159. kate.type( 'Abc' );
  160. syncClients();
  161. expectClients( '<paragraph><$text bold="true">F</$text>ooAbc</paragraph>' );
  162. } );
  163. it( 'text inside other client\'s selection', () => {
  164. john.setData( '<paragraph>[Foo]</paragraph>' );
  165. kate.setData( '<paragraph>Fo[]o</paragraph>' );
  166. john.setAttribute( 'bold', true );
  167. kate.type( 'Abc' );
  168. syncClients();
  169. expectClients( '<paragraph><$text bold="true">FoAbco</$text></paragraph>' );
  170. } );
  171. it( 'element between changed elements', () => {
  172. john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]' );
  173. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  174. john.setAttribute( 'bold', true );
  175. kate.insert( '<paragraph>Abc</paragraph>' );
  176. syncClients();
  177. expectClients(
  178. '<paragraph bold="true">Foo</paragraph>' +
  179. '<paragraph>Abc</paragraph>' +
  180. '<paragraph bold="true">Bar</paragraph>'
  181. );
  182. } );
  183. it( 'text between changed nodes', () => {
  184. john.setData( '<paragraph>[Foo</paragraph><paragraph>Bar]</paragraph>' );
  185. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
  186. john.setAttribute( 'bold', true );
  187. kate.type( 'Abc' );
  188. syncClients();
  189. expectClients(
  190. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  191. '<paragraph><$text bold="true">BAbcar</$text></paragraph>'
  192. );
  193. } );
  194. it( 'element in different path', () => {
  195. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  196. kate.setData( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>[]' );
  197. john.setAttribute( 'bold', true );
  198. kate.insert( '<paragraph>Abc</paragraph>' );
  199. syncClients();
  200. expectClients(
  201. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  202. '<paragraph>Bar</paragraph>' +
  203. '<paragraph>Abc</paragraph>'
  204. );
  205. } );
  206. it( 'element in different path #2', () => {
  207. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  208. kate.setData( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>[]' );
  209. john.setAttribute( 'bold', true );
  210. kate.insert( '<paragraph>Abc</paragraph>' );
  211. syncClients();
  212. expectClients(
  213. '<paragraph bold="true">Foo</paragraph>' +
  214. '<paragraph>Bar</paragraph>' +
  215. '<paragraph>Abc</paragraph>'
  216. );
  217. } );
  218. it( 'remove attribute from element in different path', () => {
  219. john.setData( '<paragraph>[]Foo</paragraph><paragraph bold="true">Bar</paragraph>' );
  220. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  221. john.type( 'Abc' );
  222. kate.removeAttribute( 'bold' );
  223. syncClients();
  224. expectClients( '<paragraph>AbcFoo</paragraph><paragraph>Bar</paragraph>' );
  225. } );
  226. it( 'remove attribute from text in different path', () => {
  227. john.setData( '<paragraph>[]Foo</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  228. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  229. john.type( 'Abc' );
  230. kate.removeAttribute( 'bold' );
  231. syncClients();
  232. expectClients( '<paragraph>AbcFoo</paragraph><paragraph>Bar</paragraph>' );
  233. } );
  234. it( 'remove attribute from text while typing in client\'s range', () => {
  235. john.setData( '<paragraph>F<$text bold="true">o[]o</$text></paragraph>' );
  236. kate.setData( '<paragraph>F<$text bold="true">[oo]</$text></paragraph>' );
  237. john.type( 'Bar' );
  238. kate.removeAttribute( 'bold' );
  239. syncClients();
  240. expectClients( '<paragraph>FoBaro</paragraph>' );
  241. } );
  242. it( 'remove attribute from element in same path', () => {
  243. john.setData( '<paragraph bold="true">[]Foo</paragraph>' );
  244. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  245. john.type( 'Bar' );
  246. kate.removeAttribute( 'bold' );
  247. syncClients();
  248. expectClients( '<paragraph>BarFoo</paragraph>' );
  249. } );
  250. it( 'remove attribute from text with 2 attributes while typing in client\'s range', () => {
  251. john.setData( '<paragraph>F<$text bold="true" italic="true">o[]o</$text></paragraph>' );
  252. kate.setData( '<paragraph>F<$text bold="true" italic="true">[oo]</$text></paragraph>' );
  253. john.type( 'Bar', john.document.selection.getAttributes() );
  254. kate.removeAttribute( 'bold' );
  255. syncClients();
  256. expectClients( '<paragraph>F<$text italic="true">oBaro</$text></paragraph>' );
  257. } );
  258. it( 'multiple typing', () => {
  259. john.setData( '<paragraph>[Foo]</paragraph>' );
  260. kate.setData( '<paragraph>Fo[]o</paragraph>' );
  261. john.setAttribute( 'bold', true );
  262. kate.setSelection( [ 0, 2 ] );
  263. kate.type( 'x' );
  264. kate.setSelection( [ 0, 3 ] );
  265. kate.type( 'x' );
  266. kate.setSelection( [ 0, 4 ] );
  267. kate.type( 'x' );
  268. syncClients();
  269. expectClients( '<paragraph><$text bold="true">Foxxxo</$text></paragraph>' );
  270. } );
  271. it( 'type inside element which attribute changes', () => {
  272. john.setData( '[<paragraph></paragraph>]' );
  273. kate.setData( '<paragraph>[]</paragraph>' );
  274. john.setAttribute( 'bold', true );
  275. kate.type( 'x' );
  276. syncClients();
  277. expectClients( '<paragraph bold="true">x</paragraph>' );
  278. } );
  279. } );
  280. describe( 'by move', () => {
  281. it( 'text in different path', () => {
  282. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  283. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  284. john.setAttribute( 'bold', true );
  285. kate.move( [ 1, 0 ] );
  286. syncClients();
  287. expectClients(
  288. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  289. '<paragraph>arB</paragraph>'
  290. );
  291. } );
  292. it( 'text in different path #2', () => {
  293. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  294. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  295. john.setAttribute( 'bold', true );
  296. kate.move( [ 1, 0 ] );
  297. syncClients();
  298. expectClients(
  299. '<paragraph bold="true">Foo</paragraph>' +
  300. '<paragraph>arB</paragraph>'
  301. );
  302. } );
  303. it( 'text in same path', () => {
  304. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  305. kate.setData( '<paragraph>Foo B[ar]</paragraph>' );
  306. john.setAttribute( 'bold', true );
  307. kate.move( [ 0, 4 ] );
  308. syncClients();
  309. expectClients( '<paragraph><$text bold="true">Foo</$text> arB</paragraph>' );
  310. } );
  311. it( 'text to other client\'s selection', () => {
  312. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  313. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  314. john.setAttribute( 'bold', true );
  315. kate.move( [ 0, 1 ] );
  316. syncClients();
  317. expectClients( '<paragraph><$text bold="true">F</$text>Bar<$text bold="true">oo</$text> </paragraph>' );
  318. } );
  319. it( 'text from other client\'s selection', () => {
  320. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  321. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  322. john.setAttribute( 'bold', true );
  323. kate.move( [ 0, 7 ] );
  324. syncClients();
  325. expectClients( '<paragraph><$text bold="true">F</$text> Bar<$text bold="true">oo</$text></paragraph>' );
  326. } );
  327. it( 'text from other client\'s selection #2', () => {
  328. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  329. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  330. john.setAttribute( 'bold', true );
  331. kate.move( [ 0, 7 ] );
  332. syncClients();
  333. expectClients( '<paragraph bold="true">F Baroo</paragraph>' );
  334. } );
  335. it( 'remove attribute from element in different path', () => {
  336. john.setData( '<paragraph>F[oo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  337. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  338. john.move( [ 1, 0 ] );
  339. kate.removeAttribute( 'bold' );
  340. syncClients();
  341. expectClients(
  342. '<paragraph>F</paragraph>' +
  343. '<paragraph>ooBar</paragraph>'
  344. );
  345. } );
  346. it( 'remove attribute from text in different path', () => {
  347. john.setData( '<paragraph>F[oo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  348. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  349. john.move( [ 1, 0 ] );
  350. kate.removeAttribute( 'bold' );
  351. syncClients();
  352. expectClients(
  353. '<paragraph>F</paragraph>' +
  354. '<paragraph>ooBar</paragraph>'
  355. );
  356. } );
  357. it( 'remove attribute from text in same path', () => {
  358. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  359. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  360. john.move( [ 0, 3 ] );
  361. kate.removeAttribute( 'bold' );
  362. syncClients();
  363. expectClients( '<paragraph>oFo</paragraph>' );
  364. } );
  365. it( 'remove attribute from element in same path', () => {
  366. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  367. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  368. john.move( [ 0, 3 ] );
  369. kate.removeAttribute( 'bold' );
  370. syncClients();
  371. expectClients( '<paragraph>oFo</paragraph>' );
  372. } );
  373. it( 'remove attribute from text with 2 attributes in same path', () => {
  374. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  375. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  376. john.move( [ 0, 3 ] );
  377. kate.removeAttribute( 'bold' );
  378. syncClients();
  379. expectClients( '<paragraph><$text italic="true">o</$text>Fo</paragraph>' );
  380. } );
  381. it( 'remove attribute from text in other user\'s selection', () => {
  382. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph><paragraph></paragraph>' );
  383. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph><paragraph></paragraph>' );
  384. john.move( [ 1, 0 ] );
  385. kate.removeAttribute( 'bold' );
  386. syncClients();
  387. expectClients(
  388. '<paragraph></paragraph>' +
  389. '<paragraph>Foo</paragraph>'
  390. );
  391. } );
  392. } );
  393. describe( 'by wrap', () => {
  394. it( 'element into blockQuote in different path', () => {
  395. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  396. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  397. john.setAttribute( 'bold', true );
  398. kate.wrap( 'blockQuote' );
  399. syncClients();
  400. expectClients(
  401. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  402. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  403. );
  404. } );
  405. it( 'element into blockQuote in different path #2', () => {
  406. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  407. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  408. john.setAttribute( 'bold', true );
  409. kate.wrap( 'blockQuote' );
  410. syncClients();
  411. expectClients(
  412. '<paragraph bold="true">Foo</paragraph>' +
  413. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  414. );
  415. } );
  416. it( 'element into blockQuote in same path #1', () => {
  417. john.setData( '<paragraph>[Foo]</paragraph>' );
  418. kate.setData( '[<paragraph>Foo</paragraph>]' );
  419. john.setAttribute( 'bold', true );
  420. kate.wrap( 'blockQuote' );
  421. syncClients();
  422. expectClients(
  423. '<blockQuote>' +
  424. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  425. '</blockQuote>'
  426. );
  427. } );
  428. it( 'element into blockQuote in same path #2', () => {
  429. john.setData( '[<paragraph>Foo</paragraph>]' );
  430. kate.setData( '[<paragraph>Foo</paragraph>]' );
  431. john.setAttribute( 'bold', true );
  432. kate.wrap( 'blockQuote' );
  433. syncClients();
  434. expectClients(
  435. '<blockQuote>' +
  436. '<paragraph bold="true">Foo</paragraph>' +
  437. '</blockQuote>'
  438. );
  439. } );
  440. it( 'remove attribute from element in different path', () => {
  441. john.setData( '[<paragraph>Foo</paragraph>]<paragraph bold="true">Bar</paragraph>' );
  442. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  443. john.wrap( 'blockQuote' );
  444. kate.removeAttribute( 'bold' );
  445. syncClients();
  446. expectClients(
  447. '<blockQuote>' +
  448. '<paragraph>Foo</paragraph>' +
  449. '</blockQuote>' +
  450. '<paragraph>Bar</paragraph>'
  451. );
  452. } );
  453. it( 'remove attribute 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.wrap( 'blockQuote' );
  457. kate.removeAttribute( 'bold' );
  458. syncClients();
  459. expectClients(
  460. '<blockQuote>' +
  461. '<paragraph>Foo</paragraph>' +
  462. '</blockQuote>' +
  463. '<paragraph>Bar</paragraph>'
  464. );
  465. } );
  466. it( 'remove attribute from text in same path', () => {
  467. john.setData( '[<paragraph>Fo<$text bold="true">o</$text></paragraph>]' );
  468. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  469. john.wrap( 'blockQuote' );
  470. kate.removeAttribute( 'bold' );
  471. syncClients();
  472. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  473. } );
  474. it( 'remove attribute from element in same path', () => {
  475. john.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  476. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  477. john.wrap( 'blockQuote' );
  478. kate.removeAttribute( 'bold' );
  479. syncClients();
  480. expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
  481. } );
  482. it( 'remove attribute 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.wrap( 'blockQuote' );
  486. kate.removeAttribute( 'bold' );
  487. syncClients();
  488. expectClients(
  489. '<blockQuote>' +
  490. '<paragraph>Fo<$text italic="true">o</$text></paragraph>' +
  491. '</blockQuote>'
  492. );
  493. } );
  494. } );
  495. describe( 'by unwrap', () => {
  496. it( 'element in different path', () => {
  497. john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  498. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  499. john.setAttribute( 'bold', true );
  500. kate.unwrap();
  501. syncClients();
  502. expectClients(
  503. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  504. '<paragraph>Bar</paragraph>'
  505. );
  506. } );
  507. it( 'element in different path #2', () => {
  508. john.setData( '[<paragraph>Foo</paragraph>]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  509. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  510. john.setAttribute( 'bold', true );
  511. kate.unwrap();
  512. syncClients();
  513. expectClients(
  514. '<paragraph bold="true">Foo</paragraph>' +
  515. '<paragraph>Bar</paragraph>'
  516. );
  517. } );
  518. it( 'text in different path', () => {
  519. john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  520. kate.setData( '<paragraph>Foo</paragraph><blockQuote><paragraph>[]Bar</paragraph></blockQuote>' );
  521. john.setAttribute( 'bold', true );
  522. kate.unwrap();
  523. syncClients();
  524. expectClients(
  525. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  526. '<blockQuote>Bar</blockQuote>'
  527. );
  528. } );
  529. it( 'element in same path #1', () => {
  530. john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
  531. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  532. john.setAttribute( 'bold', true );
  533. kate.unwrap();
  534. syncClients();
  535. expectClients( '<paragraph><$text bold="true">Foo</$text></paragraph>' );
  536. } );
  537. it( 'element in same path #2', () => {
  538. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  539. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  540. john.setAttribute( 'bold', true );
  541. kate.unwrap();
  542. syncClients();
  543. expectClients( '<paragraph bold="true">Foo</paragraph>' );
  544. } );
  545. it( 'text in same path', () => {
  546. john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
  547. kate.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
  548. john.setAttribute( 'bold', true );
  549. kate.unwrap();
  550. syncClients();
  551. expectClients( '<blockQuote><$text bold="true">Foo</$text></blockQuote>' );
  552. } );
  553. it( 'remove attribute from element in different path', () => {
  554. john.setData(
  555. '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' +
  556. '<paragraph bold="true">Bar</paragraph>' );
  557. kate.setData(
  558. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  559. '[<paragraph bold="true">Bar</paragraph>]' );
  560. john.unwrap();
  561. kate.removeAttribute( 'bold' );
  562. syncClients();
  563. expectClients(
  564. '<paragraph>Foo</paragraph>' +
  565. '<paragraph>Bar</paragraph>'
  566. );
  567. } );
  568. it( 'remove attribute from text in different path', () => {
  569. john.setData(
  570. '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' +
  571. '<paragraph><$text bold="true">Bar</$text></paragraph>' );
  572. kate.setData(
  573. '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
  574. '<paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  575. john.unwrap();
  576. kate.removeAttribute( 'bold' );
  577. syncClients();
  578. expectClients(
  579. '<blockQuote>Foo</blockQuote>' +
  580. '<paragraph>Bar</paragraph>'
  581. );
  582. } );
  583. it( 'remove attribute from text in same path', () => {
  584. john.setData( '<blockQuote><paragraph>[]Fo<$text bold="true">o</$text></paragraph></blockQuote>' );
  585. kate.setData( '<blockQuote><paragraph>Fo<$text bold="true">[o]</$text></paragraph></blockQuote>' );
  586. john.unwrap();
  587. kate.removeAttribute( 'bold' );
  588. syncClients();
  589. expectClients( '<blockQuote>Foo</blockQuote>' );
  590. } );
  591. it( 'remove attribute from element in same path', () => {
  592. john.setData( '<blockQuote><paragraph bold="true">[]Foo</paragraph></blockQuote>' );
  593. kate.setData( '<blockQuote>[<paragraph bold="true">Foo</paragraph>]</blockQuote>' );
  594. john.unwrap();
  595. kate.removeAttribute( 'bold' );
  596. syncClients();
  597. expectClients( '<blockQuote>Foo</blockQuote>' );
  598. } );
  599. it( 'remove attribute from text with 2 attributes in same path', () => {
  600. john.setData( '<blockQuote><paragraph>[]Fo<$text bold="true" italic="true">o</$text></paragraph></blockQuote>' );
  601. kate.setData( '<blockQuote><paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph></blockQuote>' );
  602. john.unwrap();
  603. kate.removeAttribute( 'bold' );
  604. syncClients();
  605. expectClients( '<blockQuote>Fo<$text italic="true">o</$text></blockQuote>' );
  606. } );
  607. } );
  608. describe( 'by split', () => {
  609. it( 'text in different path', () => {
  610. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  611. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  612. john.setAttribute( 'bold', true );
  613. kate.split();
  614. syncClients();
  615. expectClients(
  616. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  617. '<paragraph>Ba</paragraph>' +
  618. '<paragraph>r</paragraph>'
  619. );
  620. } );
  621. it( 'text in different path #2', () => {
  622. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  623. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  624. john.setAttribute( 'bold', true );
  625. kate.split();
  626. syncClients();
  627. expectClients(
  628. '<paragraph bold="true">Foo</paragraph>' +
  629. '<paragraph>Ba</paragraph>' +
  630. '<paragraph>r</paragraph>'
  631. );
  632. } );
  633. it( 'text in same path #1', () => {
  634. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  635. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  636. john.setAttribute( 'bold', true );
  637. kate.split();
  638. syncClients();
  639. expectClients(
  640. '<paragraph><$text bold="true">Foo</$text> B</paragraph>' +
  641. '<paragraph>ar</paragraph>'
  642. );
  643. } );
  644. it( 'text in other user\'s selection', () => {
  645. john.setData( '<paragraph>[Foo]</paragraph>' );
  646. kate.setData( '<paragraph>Fo[]o</paragraph>' );
  647. john.setAttribute( 'bold', true );
  648. kate.split();
  649. syncClients();
  650. expect(
  651. '<paragraph><$text bold="true">Fo</$text></paragraph>' +
  652. '<paragraph><$text bold="true">o</$text></paragraph>'
  653. );
  654. } );
  655. it( 'text in other user\'s selection #2', () => {
  656. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  657. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  658. john.setAttribute( 'bold', true );
  659. kate.split();
  660. syncClients();
  661. expectClients(
  662. '<paragraph bold="true">Foo B</paragraph>' +
  663. '<paragraph bold="true">ar</paragraph>'
  664. );
  665. } );
  666. it( 'text while changing attribute', () => {
  667. john.setData( '<paragraph><$text attr="foo">Foo B[ar]</$text></paragraph>' );
  668. kate.setData( '<paragraph><$text attr="foo">Foo B[]ar</$text></paragraph>' );
  669. john.setAttribute( 'attr', 'bar' );
  670. kate.split();
  671. syncClients();
  672. expectClients(
  673. '<paragraph><$text attr="foo">Foo B</$text></paragraph>' +
  674. '<paragraph><$text attr="bar">ar</$text></paragraph>'
  675. );
  676. } );
  677. it( 'remove attribute from element in different path', () => {
  678. john.setData( '<paragraph>F[]oo</paragraph><paragraph bold="true">Bar</paragraph>' );
  679. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  680. john.split();
  681. kate.removeAttribute( 'bold' );
  682. syncClients();
  683. expectClients(
  684. '<paragraph>F</paragraph>' +
  685. '<paragraph>oo</paragraph>' +
  686. '<paragraph>Bar</paragraph>'
  687. );
  688. } );
  689. it( 'remove attribute from text in different path', () => {
  690. john.setData( '<paragraph>F[]oo</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  691. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  692. john.split();
  693. kate.removeAttribute( 'bold' );
  694. syncClients();
  695. expectClients(
  696. '<paragraph>F</paragraph>' +
  697. '<paragraph>oo</paragraph>' +
  698. '<paragraph>Bar</paragraph>'
  699. );
  700. } );
  701. it( 'remove attribute from text in same path #1', () => {
  702. john.setData( '<paragraph>F[]o<$text bold="true">o</$text></paragraph>' );
  703. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  704. john.split();
  705. kate.removeAttribute( 'bold' );
  706. syncClients();
  707. expectClients(
  708. '<paragraph>F</paragraph>' +
  709. '<paragraph>oo</paragraph>' );
  710. } );
  711. it( 'remove attribute from text in same path #2', () => {
  712. john.setData( '<paragraph>F<$text bold="true">o[]o</$text></paragraph>' );
  713. kate.setData( '<paragraph>F<$text bold="true">[oo]</$text></paragraph>' );
  714. john.split();
  715. kate.removeAttribute( 'bold' );
  716. syncClients();
  717. expectClients(
  718. '<paragraph>Fo</paragraph>' +
  719. '<paragraph>o</paragraph>' );
  720. } );
  721. it( 'remove attribute from element in same path', () => {
  722. john.setData( '<paragraph bold="true">F[]oo</paragraph>' );
  723. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  724. john.split();
  725. kate.removeAttribute( 'bold' );
  726. syncClients();
  727. expectClients(
  728. '<paragraph>F</paragraph>' +
  729. '<paragraph>oo</paragraph>' );
  730. } );
  731. it( 'remove attribute from text with 2 attributes in same path', () => {
  732. john.setData( '<paragraph>F<$text bold="true" italic="true">o[]o</$text></paragraph>' );
  733. kate.setData( '<paragraph>F<$text bold="true" italic="true">[oo]</$text></paragraph>' );
  734. john.split();
  735. kate.removeAttribute( 'bold' );
  736. syncClients();
  737. expectClients(
  738. '<paragraph>F<$text italic="true">o</$text></paragraph>' +
  739. '<paragraph><$text italic="true">o</$text></paragraph>'
  740. );
  741. } );
  742. } );
  743. describe( 'by remove', () => {
  744. it( 'text in different path', () => {
  745. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  746. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  747. john.setAttribute( 'bold', true );
  748. kate.remove();
  749. syncClients();
  750. expectClients(
  751. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  752. '<paragraph></paragraph>'
  753. );
  754. } );
  755. it( 'text in same path', () => {
  756. john.setData( '<paragraph>[Fo]o</paragraph>' );
  757. kate.setData( '<paragraph>Fo[o]</paragraph>' );
  758. john.setAttribute( 'bold', true );
  759. kate.remove();
  760. syncClients();
  761. expectClients( '<paragraph><$text bold="true">Fo</$text></paragraph>' );
  762. } );
  763. it( 'text in other user\'s selection', () => {
  764. john.setData( '<paragraph>[Foo]</paragraph>' );
  765. kate.setData( '<paragraph>F[oo]</paragraph>' );
  766. john.setAttribute( 'bold', true );
  767. kate.remove();
  768. syncClients();
  769. expectClients( '<paragraph><$text bold="true">F</$text></paragraph>' );
  770. } );
  771. it( 'remove attribute from element in different path', () => {
  772. john.setData( '<paragraph>F[oo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  773. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  774. john.remove();
  775. kate.removeAttribute( 'bold' );
  776. syncClients();
  777. expectClients(
  778. '<paragraph>F</paragraph>' +
  779. '<paragraph>Bar</paragraph>'
  780. );
  781. } );
  782. it( 'remove attribute from text in different path', () => {
  783. john.setData( '<paragraph>F[oo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  784. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  785. john.remove();
  786. kate.removeAttribute( 'bold' );
  787. syncClients();
  788. expectClients(
  789. '<paragraph>F</paragraph>' +
  790. '<paragraph>Bar</paragraph>'
  791. );
  792. } );
  793. it( 'remove attribute from text in same path #1', () => {
  794. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  795. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  796. john.remove();
  797. kate.removeAttribute( 'bold' );
  798. syncClients();
  799. expectClients( '<paragraph>o</paragraph>' );
  800. } );
  801. it( 'remove attribute from text in same path #2', () => {
  802. john.setData( '<paragraph>F[o<$text bold="true">o]z</$text>Bar</paragraph>' );
  803. kate.setData( '<paragraph>Fo<$text bold="true">[oz]</$text>Bar</paragraph>' );
  804. john.remove();
  805. kate.removeAttribute( 'bold' );
  806. syncClients();
  807. expectClients(
  808. '<paragraph>FzBar</paragraph>'
  809. );
  810. } );
  811. it( 'remove attribute from element in same path', () => {
  812. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  813. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  814. john.remove();
  815. kate.removeAttribute( 'bold' );
  816. syncClients();
  817. expectClients( '<paragraph>o</paragraph>' );
  818. } );
  819. it( 'remove attribute from text with 2 attributes in same path #1', () => {
  820. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  821. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  822. john.remove();
  823. kate.removeAttribute( 'bold' );
  824. syncClients();
  825. expectClients( '<paragraph><$text italic="true">o</$text></paragraph>' );
  826. } );
  827. it( 'remove attribute from text with 2 attributes in same path #2', () => {
  828. john.setData( '<paragraph>F[o<$text bold="true" italic="true">o]z</$text>Bar</paragraph>' );
  829. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[oz]</$text>Bar</paragraph>' );
  830. john.remove();
  831. kate.removeAttribute( 'bold' );
  832. syncClients();
  833. expectClients(
  834. '<paragraph>F<$text italic="true">z</$text>Bar</paragraph>'
  835. );
  836. } );
  837. it( 'remove attribute from text in other user\'s selection', () => {
  838. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  839. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  840. john.remove();
  841. kate.removeAttribute( 'bold' );
  842. syncClients();
  843. expectClients( '<paragraph></paragraph>' );
  844. } );
  845. } );
  846. describe( 'by remove attribute', () => {
  847. it( 'from element in different path', () => {
  848. john.setData( '<paragraph>[Foo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  849. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  850. john.setAttribute( 'bold', true );
  851. kate.removeAttribute( 'bold' );
  852. syncClients();
  853. expectClients(
  854. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  855. '<paragraph>Bar</paragraph>'
  856. );
  857. } );
  858. it( 'from text in different path', () => {
  859. john.setData( '<paragraph>[Foo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  860. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  861. john.setAttribute( 'bold', true );
  862. kate.removeAttribute( 'bold' );
  863. syncClients();
  864. expectClients(
  865. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  866. '<paragraph>Bar</paragraph>'
  867. );
  868. } );
  869. it( 'from text in same path', () => {
  870. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  871. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  872. john.setAttribute( 'bold', true );
  873. kate.removeAttribute( 'bold' );
  874. syncClients();
  875. expectClients( '<paragraph><$text bold="true">Fo</$text>o</paragraph>' );
  876. } );
  877. it( 'from element in same path', () => {
  878. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  879. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  880. john.setAttribute( 'italic', true );
  881. kate.removeAttribute( 'bold' );
  882. syncClients();
  883. expectClients( '<paragraph><$text italic="true">Fo</$text>o</paragraph>' );
  884. } );
  885. it( 'from text with 2 attributes in same path', () => {
  886. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  887. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  888. john.setAttribute( 'bold', true );
  889. kate.removeAttribute( 'bold' );
  890. syncClients();
  891. expectClients( '<paragraph><$text bold="true">Fo</$text><$text italic="true">o</$text></paragraph>' );
  892. } );
  893. it( 'from text in other user\'s selection', () => {
  894. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  895. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  896. john.setAttribute( 'italic', true );
  897. kate.removeAttribute( 'bold' );
  898. syncClients();
  899. expectClients( '<paragraph><$text italic="true">Foo</$text></paragraph>' );
  900. } );
  901. } );
  902. describe( 'by marker', () => {
  903. it( 'in text at same path', () => {
  904. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  905. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  906. john.setAttribute( 'bold', true );
  907. kate.setMarker( 'm1' );
  908. syncClients();
  909. expectClients( '<paragraph><$text bold="true">Foo</$text> <m1:start></m1:start>Bar<m1:end></m1:end></paragraph>' );
  910. } );
  911. it( 'in text at same path #2', () => {
  912. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  913. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  914. john.setAttribute( 'bold', true );
  915. kate.setMarker( 'm1' );
  916. syncClients();
  917. expectClients(
  918. '<paragraph bold="true">' +
  919. 'Foo <m1:start></m1:start>Bar<m1:end></m1:end>' +
  920. '</paragraph>'
  921. );
  922. } );
  923. it( 'in text in different path', () => {
  924. john.setData( '<paragraph>F[o]o</paragraph><paragraph>Bar</paragraph>' );
  925. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[a]r</paragraph>' );
  926. john.setAttribute( 'bold', true );
  927. kate.setMarker( 'm1' );
  928. syncClients();
  929. expectClients(
  930. '<paragraph>F<$text bold="true">o</$text>o</paragraph>' +
  931. '<paragraph>B<m1:start></m1:start>a<m1:end></m1:end>r</paragraph>'
  932. );
  933. } );
  934. it( 'in text with selection inside other client\'s selection #1', () => {
  935. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  936. kate.setData( '<paragraph>Fo[o B]ar</paragraph>' );
  937. john.setAttribute( 'bold', true );
  938. kate.setMarker( 'm1' );
  939. syncClients();
  940. expectClients(
  941. '<paragraph>' +
  942. '<$text bold="true">Fo</$text><m1:start></m1:start>' +
  943. '<$text bold="true">o B</$text><m1:end></m1:end><$text bold="true">ar</$text>' +
  944. '</paragraph>'
  945. );
  946. } );
  947. it( 'in text with selection inside other client\'s selection #2', () => {
  948. john.setData( '<paragraph>F[oo Ba]r</paragraph>' );
  949. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  950. john.setAttribute( 'bold', true );
  951. kate.setMarker( 'm1' );
  952. syncClients();
  953. expectClients(
  954. '<paragraph>' +
  955. 'F<$text bold="true">oo </$text><m1:start></m1:start><$text bold="true">Ba</$text>r<m1:end></m1:end>' +
  956. '</paragraph>'
  957. );
  958. } );
  959. it( 'in text at same position', () => {
  960. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  961. kate.setData( '<paragraph>[Foo Bar]</paragraph>' );
  962. john.setAttribute( 'bold', true );
  963. kate.setMarker( 'm1' );
  964. syncClients();
  965. expectClients( '<paragraph><m1:start></m1:start><$text bold="true">Foo Bar</$text><m1:end></m1:end></paragraph>' );
  966. } );
  967. it( 'remove attribute from element in different path', () => {
  968. john.setData( '<paragraph>[Foo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  969. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  970. john.setMarker( 'm1' );
  971. kate.removeAttribute( 'bold' );
  972. syncClients();
  973. expectClients(
  974. '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' +
  975. '<paragraph>Bar</paragraph>'
  976. );
  977. } );
  978. it( 'remove attribute from text in different path', () => {
  979. john.setData( '<paragraph>[Foo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  980. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  981. john.setMarker( 'm1' );
  982. kate.removeAttribute( 'bold' );
  983. syncClients();
  984. expectClients(
  985. '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' +
  986. '<paragraph>Bar</paragraph>'
  987. );
  988. } );
  989. it( 'remove attribute from text in same path', () => {
  990. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  991. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  992. john.setMarker( 'm1' );
  993. kate.removeAttribute( 'bold' );
  994. syncClients();
  995. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end>o</paragraph>' );
  996. } );
  997. it( 'remove attribute from text in same path, then undo', () => {
  998. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  999. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  1000. john.setMarker( 'm1' );
  1001. kate.removeAttribute( 'bold' );
  1002. syncClients();
  1003. kate.undo();
  1004. syncClients();
  1005. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end><$text bold="true">o</$text></paragraph>' );
  1006. } );
  1007. it( 'remove attribute from text with 2 attributes in same path', () => {
  1008. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  1009. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  1010. john.setMarker( 'm1' );
  1011. kate.removeAttribute( 'bold' );
  1012. syncClients();
  1013. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end><$text italic="true">o</$text></paragraph>' );
  1014. } );
  1015. it( 'remove attribute from text in other user\'s selection', () => {
  1016. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  1017. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  1018. john.setMarker( 'm1' );
  1019. kate.removeAttribute( 'bold' );
  1020. syncClients();
  1021. expectClients( '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' );
  1022. } );
  1023. } );
  1024. describe( 'by merge', () => {
  1025. it( 'element into paragraph #1', () => {
  1026. john.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  1027. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  1028. john.setAttribute( 'bold', 'true' );
  1029. kate.merge();
  1030. syncClients();
  1031. expectClients( '<paragraph>FooB<$text bold="true">ar</$text></paragraph>' );
  1032. } );
  1033. it( 'element into paragraph #2, then undo', () => {
  1034. john.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  1035. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  1036. john.setAttribute( 'bold', 'true' );
  1037. kate.merge();
  1038. syncClients();
  1039. expectClients( '<paragraph>FooBar</paragraph>' );
  1040. kate.undo();
  1041. syncClients();
  1042. expectClients( '<paragraph>Foo</paragraph><paragraph bold="true">Bar</paragraph>' );
  1043. } );
  1044. it( 'element in same path', () => {
  1045. john.setData( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>[<paragraph>Baz</paragraph>]' );
  1046. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph><paragraph>Baz</paragraph>' );
  1047. john.setAttribute( 'bold', 'true' );
  1048. kate.merge();
  1049. syncClients();
  1050. expectClients( '<paragraph>FooBar</paragraph><paragraph bold="true">Baz</paragraph>' );
  1051. kate.undo();
  1052. john.undo();
  1053. syncClients();
  1054. expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Baz</paragraph>' );
  1055. } );
  1056. } );
  1057. } );
  1058. describe( 'by rename', () => {
  1059. it( 'element in different path', () => {
  1060. john.setData( '<paragraph>Foo</paragraph><paragraph>[Ba]r</paragraph>' );
  1061. kate.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  1062. john.setAttribute( 'bold', true );
  1063. kate.rename( 'heading1' );
  1064. syncClients();
  1065. expectClients(
  1066. '<heading1>Foo</heading1>' +
  1067. '<paragraph><$text bold="true">Ba</$text>r</paragraph>'
  1068. );
  1069. } );
  1070. it( 'element in same path', () => {
  1071. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  1072. kate.setData( '<paragraph>[]Foo Bar</paragraph>' );
  1073. john.setAttribute( 'bold', true );
  1074. kate.rename( 'heading1' );
  1075. syncClients();
  1076. expectClients( '<heading1><$text bold="true">Foo Bar</$text></heading1>' );
  1077. } );
  1078. it( 'element in user\'s selection', () => {
  1079. john.setData( '<paragraph>[Foo]</paragraph>' );
  1080. kate.setData( '<paragraph>[Foo]</paragraph>' );
  1081. john.setAttribute( 'bold', true );
  1082. kate.rename( 'heading1' );
  1083. syncClients();
  1084. expectClients( '<heading1><$text bold="true">Foo</$text></heading1>' );
  1085. } );
  1086. it( 'element in user\'s selection, then undo', () => {
  1087. john.setData( '<paragraph>[Foo]</paragraph>' );
  1088. kate.setData( '<paragraph>[Foo]</paragraph>' );
  1089. john.setAttribute( 'bold', true );
  1090. kate.rename( 'heading1' );
  1091. syncClients();
  1092. john.undo();
  1093. kate.undo();
  1094. syncClients();
  1095. expectClients( '<paragraph>Foo</paragraph>' );
  1096. } );
  1097. it( 'remove attribute from element in different path', () => {
  1098. john.setData( '<paragraph>F[]oo</paragraph><paragraph bold="true">Bar</paragraph>' );
  1099. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  1100. john.rename( 'heading1' );
  1101. kate.removeAttribute( 'bold' );
  1102. syncClients();
  1103. expectClients(
  1104. '<heading1>Foo</heading1>' +
  1105. '<paragraph>Bar</paragraph>'
  1106. );
  1107. } );
  1108. it( 'remove attribute from text in different path', () => {
  1109. john.setData( '<paragraph>F[]oo</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  1110. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  1111. john.rename( 'heading1' );
  1112. kate.removeAttribute( 'bold' );
  1113. syncClients();
  1114. expectClients(
  1115. '<heading1>Foo</heading1>' +
  1116. '<paragraph>Bar</paragraph>'
  1117. );
  1118. } );
  1119. it( 'remove attribute from text in same path', () => {
  1120. john.setData( '<paragraph>F[]o<$text bold="true">o</$text></paragraph>' );
  1121. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  1122. john.rename( 'heading1' );
  1123. kate.removeAttribute( 'bold' );
  1124. syncClients();
  1125. expectClients( '<heading1>Foo</heading1>' );
  1126. } );
  1127. it( 'remove attribute from element in same path', () => {
  1128. john.setData( '<paragraph bold="true">F[]oo</paragraph>' );
  1129. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  1130. john.rename( 'heading1' );
  1131. kate.removeAttribute( 'bold' );
  1132. syncClients();
  1133. expectClients( '<heading1>Foo</heading1>' );
  1134. } );
  1135. it( 'remove attribute from text with 2 attributes in same path', () => {
  1136. john.setData( '<paragraph>F[o]<$text bold="true" italic="true">o</$text></paragraph>' );
  1137. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  1138. john.rename( 'heading1' );
  1139. kate.removeAttribute( 'bold' );
  1140. syncClients();
  1141. expectClients( '<heading1>Fo<$text italic="true">o</$text></heading1>' );
  1142. } );
  1143. it( 'remove attribute from text in other user\'s selection', () => {
  1144. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  1145. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  1146. john.rename( 'heading1' );
  1147. kate.removeAttribute( 'bold' );
  1148. syncClients();
  1149. expectClients( '<heading1>Foo</heading1>' );
  1150. } );
  1151. } );
  1152. } );