attribute.js 38 KB

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