8
0

attribute.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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' );
  238. kate.removeAttribute( 'bold' );
  239. syncClients();
  240. expectClients( '<paragraph>F<$text italic="true">oBaro</$text></paragraph>' );
  241. } );
  242. } );
  243. describe( 'by move', () => {
  244. it( 'text in different path', () => {
  245. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  246. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  247. john.setAttribute( 'bold', true );
  248. kate.move( [ 1, 0 ] );
  249. syncClients();
  250. expectClients(
  251. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  252. '<paragraph>arB</paragraph>'
  253. );
  254. } );
  255. it( 'text in different path #2', () => {
  256. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  257. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  258. john.setAttribute( 'bold', true );
  259. kate.move( [ 1, 0 ] );
  260. syncClients();
  261. expectClients(
  262. '<paragraph bold="true">Foo</paragraph>' +
  263. '<paragraph>arB</paragraph>'
  264. );
  265. } );
  266. it( 'text in same path', () => {
  267. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  268. kate.setData( '<paragraph>Foo B[ar]</paragraph>' );
  269. john.setAttribute( 'bold', true );
  270. kate.move( [ 0, 4 ] );
  271. syncClients();
  272. expectClients( '<paragraph><$text bold="true">Foo</$text> arB</paragraph>' );
  273. } );
  274. it( 'text to other client\'s selection', () => {
  275. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  276. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  277. john.setAttribute( 'bold', true );
  278. kate.move( [ 0, 1 ] );
  279. syncClients();
  280. expectClients( '<paragraph><$text bold="true">F</$text>Bar<$text bold="true">oo</$text> </paragraph>' );
  281. } );
  282. it( 'text from other client\'s selection', () => {
  283. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  284. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  285. john.setAttribute( 'bold', true );
  286. kate.move( [ 0, 7 ], [ 0, 1 ], [ 0, 3 ] );
  287. syncClients();
  288. expectClients( '<paragraph><$text bold="true">F</$text> Bar<$text bold="true">oo</$text></paragraph>' );
  289. } );
  290. it( 'text from other client\'s selection #2', () => {
  291. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  292. kate.setData( '<paragraph>F[oo] Bar</paragraph>' );
  293. john.setAttribute( 'bold', true );
  294. kate.move( [ 0, 7 ] );
  295. syncClients();
  296. expectClients( '<paragraph bold="true">F Baroo</paragraph>' );
  297. } );
  298. it( 'remove attribute from element in different path', () => {
  299. john.setData( '<paragraph>F[oo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  300. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  301. john.move( [ 1, 0 ] );
  302. kate.removeAttribute( 'bold' );
  303. syncClients();
  304. expectClients(
  305. '<paragraph>F</paragraph>' +
  306. '<paragraph>ooBar</paragraph>'
  307. );
  308. } );
  309. it( 'remove attribute from text in different path', () => {
  310. john.setData( '<paragraph>F[oo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  311. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  312. john.move( [ 1, 0 ] );
  313. kate.removeAttribute( 'bold' );
  314. syncClients();
  315. expectClients(
  316. '<paragraph>F</paragraph>' +
  317. '<paragraph>ooBar</paragraph>'
  318. );
  319. } );
  320. it( 'remove attribute from text in same path', () => {
  321. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  322. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  323. john.move( [ 0, 3 ] );
  324. kate.removeAttribute( 'bold' );
  325. syncClients();
  326. expectClients( '<paragraph>oFo</paragraph>' );
  327. } );
  328. it( 'remove attribute from element in same path', () => {
  329. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  330. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  331. john.move( [ 0, 3 ] );
  332. kate.removeAttribute( 'bold' );
  333. syncClients();
  334. expectClients( '<paragraph>oFo</paragraph>' );
  335. } );
  336. it( 'remove attribute from text with 2 attributes in same path', () => {
  337. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  338. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  339. john.move( [ 0, 3 ] );
  340. kate.removeAttribute( 'bold' );
  341. syncClients();
  342. expectClients( '<paragraph><$text italic="true">o</$text>Fo</paragraph>' );
  343. } );
  344. it( 'remove attribute from text in other user\'s selection', () => {
  345. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph><paragraph></paragraph>' );
  346. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph><paragraph></paragraph>' );
  347. john.move( [ 1, 0 ] );
  348. kate.removeAttribute( 'bold' );
  349. syncClients();
  350. expectClients(
  351. '<paragraph></paragraph>' +
  352. '<paragraph>Foo</paragraph>'
  353. );
  354. } );
  355. } );
  356. describe( 'by wrap', () => {
  357. it( 'element into blockQuote in different path', () => {
  358. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  359. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  360. john.setAttribute( 'bold', true );
  361. kate.wrap( 'blockQuote' );
  362. syncClients();
  363. expectClients(
  364. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  365. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  366. );
  367. } );
  368. it( 'element into blockQuote in different path #2', () => {
  369. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  370. kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  371. john.setAttribute( 'bold', true );
  372. kate.wrap( 'blockQuote' );
  373. syncClients();
  374. expectClients(
  375. '<paragraph bold="true">Foo</paragraph>' +
  376. '<blockQuote><paragraph>Bar</paragraph></blockQuote>'
  377. );
  378. } );
  379. it( 'text into div in different path', () => {
  380. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  381. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  382. john.setAttribute( 'bold', true );
  383. kate.wrap( 'div' );
  384. syncClients();
  385. expectClients(
  386. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  387. '<paragraph><div>Bar</div></paragraph>'
  388. );
  389. } );
  390. it( 'element into blockQuote in same path #1', () => {
  391. john.setData( '<paragraph>[Foo]</paragraph>' );
  392. kate.setData( '[<paragraph>Foo</paragraph>]' );
  393. john.setAttribute( 'bold', true );
  394. kate.wrap( 'blockQuote' );
  395. syncClients();
  396. expectClients(
  397. '<blockQuote>' +
  398. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  399. '</blockQuote>'
  400. );
  401. } );
  402. it( 'element into blockQuote in same path #2', () => {
  403. john.setData( '[<paragraph>Foo</paragraph>]' );
  404. kate.setData( '[<paragraph>Foo</paragraph>]' );
  405. john.setAttribute( 'bold', true );
  406. kate.wrap( 'blockQuote' );
  407. syncClients();
  408. expectClients(
  409. '<blockQuote>' +
  410. '<paragraph bold="true">Foo</paragraph>' +
  411. '</blockQuote>'
  412. );
  413. } );
  414. it( 'text into div in same path', () => {
  415. john.setData( '<paragraph>[Foo]</paragraph>' );
  416. kate.setData( '<paragraph>[Foo]</paragraph>' );
  417. john.setAttribute( 'bold', true );
  418. kate.wrap( 'div' );
  419. syncClients();
  420. expectClients( '<paragraph><div><$text bold="true">Foo</$text></div></paragraph>' );
  421. } );
  422. } );
  423. describe( 'by unwrap', () => {
  424. it( 'element in different path', () => {
  425. john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  426. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  427. john.setAttribute( 'bold', true );
  428. kate.unwrap();
  429. syncClients();
  430. expectClients(
  431. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  432. '<paragraph>Bar</paragraph>'
  433. );
  434. } );
  435. it( 'element in different path #2', () => {
  436. john.setData( '[<paragraph>Foo</paragraph>]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  437. kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
  438. john.setAttribute( 'bold', true );
  439. kate.unwrap();
  440. syncClients();
  441. expectClients(
  442. '<paragraph bold="true">Foo</paragraph>' +
  443. '<paragraph>Bar</paragraph>'
  444. );
  445. } );
  446. it( 'text in different path', () => {
  447. john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
  448. kate.setData( '<paragraph>Foo</paragraph><blockQuote><paragraph>[]Bar</paragraph></blockQuote>' );
  449. john.setAttribute( 'bold', true );
  450. kate.unwrap();
  451. syncClients();
  452. expectClients(
  453. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  454. '<blockQuote>Bar</blockQuote>'
  455. );
  456. } );
  457. it( 'element in same path #1', () => {
  458. john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
  459. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  460. john.setAttribute( 'bold', true );
  461. kate.unwrap();
  462. syncClients();
  463. expectClients( '<paragraph><$text bold="true">Foo</$text></paragraph>' );
  464. } );
  465. it( 'element in same path #2', () => {
  466. john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  467. kate.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
  468. john.setAttribute( 'bold', true );
  469. kate.unwrap();
  470. syncClients();
  471. expectClients( '<paragraph bold="true">Foo</paragraph>' );
  472. } );
  473. it( 'text in same path', () => {
  474. john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
  475. kate.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
  476. john.setAttribute( 'bold', true );
  477. kate.unwrap();
  478. syncClients();
  479. expectClients( '<blockQuote><$text bold="true">Foo</$text></blockQuote>' );
  480. } );
  481. } );
  482. describe( 'by split', () => {
  483. it( 'text in different path', () => {
  484. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  485. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  486. john.setAttribute( 'bold', true );
  487. kate.split();
  488. syncClients();
  489. expectClients(
  490. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  491. '<paragraph>Ba</paragraph>' +
  492. '<paragraph>r</paragraph>'
  493. );
  494. } );
  495. it( 'text in different path #2', () => {
  496. john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
  497. kate.setData( '<paragraph>Foo</paragraph><paragraph>Ba[]r</paragraph>' );
  498. john.setAttribute( 'bold', true );
  499. kate.split();
  500. syncClients();
  501. expectClients(
  502. '<paragraph bold="true">Foo</paragraph>' +
  503. '<paragraph>Ba</paragraph>' +
  504. '<paragraph>r</paragraph>'
  505. );
  506. } );
  507. it( 'text in same path #1', () => {
  508. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  509. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  510. john.setAttribute( 'bold', true );
  511. kate.split();
  512. syncClients();
  513. expectClients(
  514. '<paragraph><$text bold="true">Foo</$text> B</paragraph>' +
  515. '<paragraph>ar</paragraph>'
  516. );
  517. } );
  518. it( 'text in other user\'s selection', () => {
  519. john.setData( '<paragraph>[Foo]</paragraph>' );
  520. kate.setData( '<paragraph>Fo[]o</paragraph>' );
  521. john.setAttribute( 'bold', true );
  522. kate.split();
  523. syncClients();
  524. expect(
  525. '<paragraph><$text bold="true">Fo</$text></paragraph>' +
  526. '<paragraph><$text bold="true">o</$text></paragraph>'
  527. );
  528. } );
  529. it( 'text in other user\'s selection #2', () => {
  530. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  531. kate.setData( '<paragraph>Foo B[]ar</paragraph>' );
  532. john.setAttribute( 'bold', true );
  533. kate.split();
  534. syncClients();
  535. expectClients(
  536. '<paragraph bold="true">Foo B</paragraph>' +
  537. '<paragraph bold="true">ar</paragraph>'
  538. );
  539. } );
  540. it( 'text while changing attribute', () => {
  541. john.setData( '<paragraph><$text attr="foo">Foo B[ar]</$text></paragraph>' );
  542. kate.setData( '<paragraph><$text attr="foo">Foo B[]ar</$text></paragraph>' );
  543. john.setAttribute( 'attr', 'bar' );
  544. kate.split();
  545. syncClients();
  546. expectClients(
  547. '<paragraph><$text attr="foo">Foo B</$text></paragraph>' +
  548. '<paragraph><$text attr="bar">ar</$text></paragraph>'
  549. );
  550. } );
  551. } );
  552. describe( 'by remove', () => {
  553. it( 'text in different path', () => {
  554. john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
  555. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  556. john.setAttribute( 'bold', true );
  557. kate.remove();
  558. syncClients();
  559. expectClients(
  560. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  561. '<paragraph></paragraph>'
  562. );
  563. } );
  564. it( 'text in same path', () => {
  565. john.setData( '<paragraph>[Fo]o</paragraph>' );
  566. kate.setData( '<paragraph>Fo[o]</paragraph>' );
  567. john.setAttribute( 'bold', true );
  568. kate.remove();
  569. syncClients();
  570. expectClients( '<paragraph><$text bold="true">Fo</$text></paragraph>' );
  571. } );
  572. it( 'text in other user\'s selection', () => {
  573. john.setData( '<paragraph>[Foo]</paragraph>' );
  574. kate.setData( '<paragraph>F[oo]</paragraph>' );
  575. john.setAttribute( 'bold', true );
  576. kate.remove();
  577. syncClients();
  578. expectClients( '<paragraph><$text bold="true">F</$text></paragraph>' );
  579. } );
  580. it( 'remove attribute from element in different path', () => {
  581. john.setData( '<paragraph>F[oo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  582. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  583. john.remove();
  584. kate.removeAttribute( 'bold' );
  585. syncClients();
  586. expectClients(
  587. '<paragraph>F</paragraph>' +
  588. '<paragraph>Bar</paragraph>'
  589. );
  590. } );
  591. it( 'remove attribute from text in different path', () => {
  592. john.setData( '<paragraph>F[oo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  593. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  594. john.remove();
  595. kate.removeAttribute( 'bold' );
  596. syncClients();
  597. expectClients(
  598. '<paragraph>F</paragraph>' +
  599. '<paragraph>Bar</paragraph>'
  600. );
  601. } );
  602. it( 'remove attribute from text in same path #1', () => {
  603. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  604. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  605. john.remove();
  606. kate.removeAttribute( 'bold' );
  607. syncClients();
  608. expectClients( '<paragraph>o</paragraph>' );
  609. } );
  610. it( 'remove attribute from text in same path #2', () => {
  611. john.setData( '<paragraph>F[o<$text bold="true">o]z</$text>Bar</paragraph>' );
  612. kate.setData( '<paragraph>Fo<$text bold="true">[oz]</$text>Bar</paragraph>' );
  613. john.remove();
  614. kate.removeAttribute( 'bold' );
  615. syncClients();
  616. expectClients(
  617. '<paragraph>FzBar</paragraph>'
  618. );
  619. } );
  620. it( 'remove attribute from element in same path', () => {
  621. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  622. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  623. john.remove();
  624. kate.removeAttribute( 'bold' );
  625. syncClients();
  626. expectClients( '<paragraph>o</paragraph>' );
  627. } );
  628. it( 'remove attribute from text with 2 attributes in same path #1', () => {
  629. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  630. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  631. john.remove();
  632. kate.removeAttribute( 'bold' );
  633. syncClients();
  634. expectClients( '<paragraph><$text italic="true">o</$text></paragraph>' );
  635. } );
  636. it( 'remove attribute from text with 2 attributes in same path #2', () => {
  637. john.setData( '<paragraph>F[o<$text bold="true" italic="true">o]z</$text>Bar</paragraph>' );
  638. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[oz]</$text>Bar</paragraph>' );
  639. john.remove();
  640. kate.removeAttribute( 'bold' );
  641. syncClients();
  642. expectClients(
  643. '<paragraph>F<$text italic="true">z</$text>Bar</paragraph>'
  644. );
  645. } );
  646. it( 'remove attribute from text in other user\'s selection', () => {
  647. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  648. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  649. john.remove();
  650. kate.removeAttribute( 'bold' );
  651. syncClients();
  652. expectClients( '<paragraph></paragraph>' );
  653. } );
  654. } );
  655. describe( 'by remove attribute', () => {
  656. it( 'from element in different path', () => {
  657. john.setData( '<paragraph>[Foo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  658. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  659. john.setAttribute( 'bold', true );
  660. kate.removeAttribute( 'bold' );
  661. syncClients();
  662. expectClients(
  663. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  664. '<paragraph>Bar</paragraph>'
  665. );
  666. } );
  667. it( 'from text in different path', () => {
  668. john.setData( '<paragraph>[Foo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  669. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  670. john.setAttribute( 'bold', true );
  671. kate.removeAttribute( 'bold' );
  672. syncClients();
  673. expectClients(
  674. '<paragraph><$text bold="true">Foo</$text></paragraph>' +
  675. '<paragraph>Bar</paragraph>'
  676. );
  677. } );
  678. it( 'from text in same path', () => {
  679. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  680. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  681. john.setAttribute( 'bold', true );
  682. kate.removeAttribute( 'bold' );
  683. syncClients();
  684. expectClients( '<paragraph><$text bold="true">Fo</$text>o</paragraph>' );
  685. } );
  686. it( 'from element in same path', () => {
  687. john.setData( '<paragraph bold="true">[Fo]o</paragraph>' );
  688. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  689. john.setAttribute( 'italic', true );
  690. kate.removeAttribute( 'bold' );
  691. syncClients();
  692. expectClients( '<paragraph><$text italic="true">Fo</$text>o</paragraph>' );
  693. } );
  694. it( 'from text with 2 attributes in same path', () => {
  695. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  696. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  697. john.setAttribute( 'bold', true );
  698. kate.removeAttribute( 'bold' );
  699. syncClients();
  700. expectClients( '<paragraph><$text bold="true">Fo</$text><$text italic="true">o</$text></paragraph>' );
  701. } );
  702. it( 'from text in other user\'s selection', () => {
  703. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  704. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  705. john.setAttribute( 'italic', true );
  706. kate.removeAttribute( 'bold' );
  707. syncClients();
  708. expectClients( '<paragraph><$text italic="true">Foo</$text></paragraph>' );
  709. } );
  710. } );
  711. describe( 'by marker', () => {
  712. it( 'in text at same path', () => {
  713. john.setData( '<paragraph>[Foo] Bar</paragraph>' );
  714. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  715. john.setAttribute( 'bold', true );
  716. kate.setMarker( 'm1' );
  717. syncClients();
  718. expectClients( '<paragraph><$text bold="true">Foo</$text> <m1:start></m1:start>Bar<m1:end></m1:end></paragraph>' );
  719. } );
  720. it( 'in text at same path #2', () => {
  721. john.setData( '[<paragraph>Foo Bar</paragraph>]' );
  722. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  723. john.setAttribute( 'bold', true );
  724. kate.setMarker( 'm1' );
  725. syncClients();
  726. expectClients(
  727. '<paragraph bold="true">' +
  728. 'Foo <m1:start></m1:start>Bar<m1:end></m1:end>' +
  729. '</paragraph>'
  730. );
  731. } );
  732. it( 'in text in different path', () => {
  733. john.setData( '<paragraph>F[o]o</paragraph><paragraph>Bar</paragraph>' );
  734. kate.setData( '<paragraph>Foo</paragraph><paragraph>B[a]r</paragraph>' );
  735. john.setAttribute( 'bold', true );
  736. kate.setMarker( 'm1' );
  737. syncClients();
  738. expectClients(
  739. '<paragraph>F<$text bold="true">o</$text>o</paragraph>' +
  740. '<paragraph>B<m1:start></m1:start>a<m1:end></m1:end>r</paragraph>'
  741. );
  742. } );
  743. it( 'in text with selection inside other client\'s selection #1', () => {
  744. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  745. kate.setData( '<paragraph>Fo[o B]ar</paragraph>' );
  746. john.setAttribute( 'bold', true );
  747. kate.setMarker( 'm1' );
  748. syncClients();
  749. expectClients(
  750. '<paragraph>' +
  751. '<$text bold="true">Fo</$text><m1:start></m1:start>' +
  752. '<$text bold="true">o B</$text><m1:end></m1:end><$text bold="true">ar</$text>' +
  753. '</paragraph>'
  754. );
  755. } );
  756. it( 'in text with selection inside other client\'s selection #2', () => {
  757. john.setData( '<paragraph>F[oo Ba]r</paragraph>' );
  758. kate.setData( '<paragraph>Foo [Bar]</paragraph>' );
  759. john.setAttribute( 'bold', true );
  760. kate.setMarker( 'm1' );
  761. syncClients();
  762. expectClients(
  763. '<paragraph>' +
  764. 'F<$text bold="true">oo </$text><m1:start></m1:start><$text bold="true">Ba</$text>r<m1:end></m1:end>' +
  765. '</paragraph>'
  766. );
  767. } );
  768. it( 'in text at same position', () => {
  769. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  770. kate.setData( '<paragraph>[Foo Bar]</paragraph>' );
  771. john.setAttribute( 'bold', true );
  772. kate.setMarker( 'm1' );
  773. syncClients();
  774. expectClients( '<paragraph><m1:start></m1:start><$text bold="true">Foo Bar</$text><m1:end></m1:end></paragraph>' );
  775. } );
  776. it( 'remove attribute from element in different path', () => {
  777. john.setData( '<paragraph>[Foo]</paragraph><paragraph bold="true">Bar</paragraph>' );
  778. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  779. john.setMarker( 'm1' );
  780. kate.removeAttribute( 'bold' );
  781. syncClients();
  782. expectClients(
  783. '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' +
  784. '<paragraph>Bar</paragraph>'
  785. );
  786. } );
  787. it( 'remove attribute from text in different path', () => {
  788. john.setData( '<paragraph>[Foo]</paragraph><paragraph><$text bold="true">Bar</$text></paragraph>' );
  789. kate.setData( '<paragraph>Foo</paragraph><paragraph><$text bold="true">[Bar]</$text></paragraph>' );
  790. john.setMarker( 'm1' );
  791. kate.removeAttribute( 'bold' );
  792. syncClients();
  793. expectClients(
  794. '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' +
  795. '<paragraph>Bar</paragraph>'
  796. );
  797. } );
  798. it( 'remove attribute from text in same path', () => {
  799. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  800. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  801. john.setMarker( 'm1' );
  802. kate.removeAttribute( 'bold' );
  803. syncClients();
  804. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end>o</paragraph>' );
  805. } );
  806. it( 'remove attribute from text in same path, then undo', () => {
  807. john.setData( '<paragraph>[Fo]<$text bold="true">o</$text></paragraph>' );
  808. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  809. john.setMarker( 'm1' );
  810. kate.removeAttribute( 'bold' );
  811. syncClients();
  812. kate.undo();
  813. syncClients();
  814. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end><$text bold="true">o</$text></paragraph>' );
  815. } );
  816. it( 'remove attribute from text with 2 attributes in same path', () => {
  817. john.setData( '<paragraph>[Fo]<$text bold="true" italic="true">o</$text></paragraph>' );
  818. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  819. john.setMarker( 'm1' );
  820. kate.removeAttribute( 'bold' );
  821. syncClients();
  822. expectClients( '<paragraph><m1:start></m1:start>Fo<m1:end></m1:end><$text italic="true">o</$text></paragraph>' );
  823. } );
  824. it( 'remove attribute from text in other user\'s selection', () => {
  825. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  826. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  827. john.setMarker( 'm1' );
  828. kate.removeAttribute( 'bold' );
  829. syncClients();
  830. expectClients( '<paragraph><m1:start></m1:start>Foo<m1:end></m1:end></paragraph>' );
  831. } );
  832. } );
  833. describe( 'by merge', () => {
  834. it( 'element into paragraph #1', () => {
  835. john.setData( '<paragraph>Foo</paragraph><paragraph>B[ar]</paragraph>' );
  836. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  837. john.setAttribute( 'bold', 'true' );
  838. kate.merge();
  839. syncClients();
  840. expectClients( '<paragraph>FooB<$text bold="true">ar</$text></paragraph>' );
  841. } );
  842. it.skip( 'element into paragraph #2, then undo', () => {
  843. john.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
  844. kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
  845. john.setAttribute( 'bold', 'true' );
  846. kate.merge();
  847. syncClients();
  848. expectClients( '<paragraph>FooBar</paragraph>' );
  849. kate.undo();
  850. syncClients();
  851. expectClients( '<paragraph>Foo</paragraph><paragraph bold="true">Bar</paragraph>' );
  852. } );
  853. } );
  854. } );
  855. describe( 'by rename', () => {
  856. it( 'element in different path', () => {
  857. john.setData( '<paragraph>Foo</paragraph><paragraph>[Ba]r</paragraph>' );
  858. kate.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  859. john.setAttribute( 'bold', true );
  860. kate.rename( 'heading1' );
  861. syncClients();
  862. expectClients(
  863. '<heading1>Foo</heading1>' +
  864. '<paragraph><$text bold="true">Ba</$text>r</paragraph>'
  865. );
  866. } );
  867. it( 'element in same path', () => {
  868. john.setData( '<paragraph>[Foo Bar]</paragraph>' );
  869. kate.setData( '<paragraph>[]Foo Bar</paragraph>' );
  870. john.setAttribute( 'bold', true );
  871. kate.rename( 'heading1' );
  872. syncClients();
  873. expectClients( '<heading1><$text bold="true">Foo Bar</$text></heading1>' );
  874. } );
  875. it( 'element in user\'s selection', () => {
  876. john.setData( '<paragraph>[Foo]</paragraph>' );
  877. kate.setData( '<paragraph>[Foo]</paragraph>' );
  878. john.setAttribute( 'bold', true );
  879. kate.rename( 'heading1' );
  880. syncClients();
  881. expectClients( '<heading1><$text bold="true">Foo</$text></heading1>' );
  882. } );
  883. it( 'element in user\'s selection, then undo', () => {
  884. john.setData( '<paragraph>[Foo]</paragraph>' );
  885. kate.setData( '<paragraph>[Foo]</paragraph>' );
  886. john.setAttribute( 'bold', true );
  887. kate.rename( 'heading1' );
  888. syncClients();
  889. john.undo();
  890. kate.undo();
  891. syncClients();
  892. expectClients( '<paragraph>Foo</paragraph>' );
  893. } );
  894. it( 'remove attribute from element in different path', () => {
  895. john.setData( '<paragraph>F[]oo</paragraph><paragraph bold="true">Bar</paragraph>' );
  896. kate.setData( '<paragraph>Foo</paragraph>[<paragraph bold="true">Bar</paragraph>]' );
  897. john.rename( 'heading1' );
  898. kate.removeAttribute( 'bold' );
  899. syncClients();
  900. expectClients(
  901. '<heading1>Foo</heading1>' +
  902. '<paragraph>Bar</paragraph>'
  903. );
  904. } );
  905. it( 'remove attribute from text in different path', () => {
  906. john.setData( '<paragraph>F[]oo</paragraph><paragraph>Bar</paragraph>' );
  907. kate.setData( '<paragraph>Foo</paragraph><paragraph>[Bar]</paragraph>' );
  908. john.rename( 'heading1' );
  909. kate.removeAttribute( 'bold' );
  910. syncClients();
  911. expectClients(
  912. '<heading1>Foo</heading1>' +
  913. '<paragraph>Bar</paragraph>'
  914. );
  915. } );
  916. it( 'remove attribute from text in same path', () => {
  917. john.setData( '<paragraph>F[]o<$text bold="true">o</$text></paragraph>' );
  918. kate.setData( '<paragraph>Fo<$text bold="true">[o]</$text></paragraph>' );
  919. john.rename( 'heading1' );
  920. kate.removeAttribute( 'bold' );
  921. syncClients();
  922. expectClients( '<heading1>Foo</heading1>' );
  923. } );
  924. it( 'remove attribute from element in same path', () => {
  925. john.setData( '<paragraph bold="true">F[]oo</paragraph>' );
  926. kate.setData( '[<paragraph bold="true">Foo</paragraph>]' );
  927. john.rename( 'heading1' );
  928. kate.removeAttribute( 'bold' );
  929. syncClients();
  930. expectClients( '<heading1>Foo</heading1>' );
  931. } );
  932. it( 'remove attribute from text with 2 attributes in same path', () => {
  933. john.setData( '<paragraph>F[o]<$text bold="true" italic="true">o</$text></paragraph>' );
  934. kate.setData( '<paragraph>Fo<$text bold="true" italic="true">[o]</$text></paragraph>' );
  935. john.rename( 'heading1' );
  936. kate.removeAttribute( 'bold' );
  937. syncClients();
  938. expectClients( '<heading1>Fo<$text italic="true">o</$text></heading1>' );
  939. } );
  940. it( 'remove attribute from text in other user\'s selection', () => {
  941. john.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  942. kate.setData( '<paragraph><$text bold="true">[Foo]</$text></paragraph>' );
  943. john.rename( 'heading1' );
  944. kate.removeAttribute( 'bold' );
  945. syncClients();
  946. expectClients( '<heading1>Foo</heading1>' );
  947. } );
  948. } );
  949. } );