attribute.js 46 KB

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