8
0

attribute.js 46 KB

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