8
0

transform.js 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import transform from '../../../src/model/operation/transform';
  6. import Document from '../../../src/model/document';
  7. import RootElement from '../../../src/model/rootelement';
  8. import Node from '../../../src/model/node';
  9. import Position from '../../../src/model/position';
  10. import Range from '../../../src/model/range';
  11. import InsertOperation from '../../../src/model/operation/insertoperation';
  12. import AttributeOperation from '../../../src/model/operation/attributeoperation';
  13. import RootAttributeOperation from '../../../src/model/operation/rootattributeoperation';
  14. import MarkerOperation from '../../../src/model/operation/markeroperation';
  15. import MoveOperation from '../../../src/model/operation/moveoperation';
  16. import RemoveOperation from '../../../src/model/operation/removeoperation';
  17. import RenameOperation from '../../../src/model/operation/renameoperation';
  18. import NoOperation from '../../../src/model/operation/nooperation';
  19. describe( 'transform', () => {
  20. let doc, root, op, nodeA, nodeB, expected, baseVersion;
  21. beforeEach( () => {
  22. doc = new Document();
  23. root = doc.createRoot();
  24. nodeA = new Node();
  25. nodeB = new Node();
  26. baseVersion = 0;
  27. } );
  28. function expectOperation( op, params ) {
  29. for ( const i in params ) {
  30. if ( params.hasOwnProperty( i ) ) {
  31. if ( i == 'type' ) {
  32. expect( op ).to.be.instanceof( params[ i ] );
  33. }
  34. else if ( params[ i ] instanceof Array ) {
  35. expect( op[ i ].length ).to.equal( params[ i ].length );
  36. for ( let j = 0; j < params[ i ].length; j++ ) {
  37. expect( op[ i ][ j ] ).to.equal( params[ i ][ j ] );
  38. }
  39. } else if ( params[ i ] instanceof Position || params[ i ] instanceof Range ) {
  40. expect( op[ i ].isEqual( params[ i ] ) ).to.be.true;
  41. } else {
  42. expect( op[ i ] ).to.equal( params[ i ] );
  43. }
  44. }
  45. }
  46. }
  47. describe( 'InsertOperation', () => {
  48. let nodeC, nodeD, position;
  49. beforeEach( () => {
  50. nodeC = new Node();
  51. nodeD = new Node();
  52. position = new Position( root, [ 0, 2, 2 ] );
  53. op = new InsertOperation( position, [ nodeA, nodeB ], baseVersion );
  54. expected = {
  55. type: InsertOperation,
  56. position: Position.createFromPosition( position ),
  57. baseVersion: baseVersion + 1
  58. };
  59. } );
  60. describe( 'by InsertOperation', () => {
  61. it( 'target at different position: no position update', () => {
  62. const transformBy = new InsertOperation(
  63. new Position( root, [ 1, 3, 2 ] ),
  64. [ nodeC, nodeD ],
  65. baseVersion
  66. );
  67. const transOp = transform( op, transformBy );
  68. expect( transOp.length ).to.equal( 1 );
  69. expectOperation( transOp[ 0 ], expected );
  70. } );
  71. it( 'target at offset before: increment offset', () => {
  72. const transformBy = new InsertOperation(
  73. new Position( root, [ 0, 2, 0 ] ),
  74. [ nodeC, nodeD ],
  75. baseVersion
  76. );
  77. const transOp = transform( op, transformBy );
  78. expected.position.offset += 2;
  79. expect( transOp.length ).to.equal( 1 );
  80. expectOperation( transOp[ 0 ], expected );
  81. } );
  82. it( 'target at same offset and is important: increment offset', () => {
  83. const transformBy = new InsertOperation(
  84. new Position( root, [ 0, 2, 2 ] ),
  85. [ nodeC, nodeD ],
  86. baseVersion
  87. );
  88. const transOp = transform( op, transformBy );
  89. expected.position.offset += 2;
  90. expect( transOp.length ).to.equal( 1 );
  91. expectOperation( transOp[ 0 ], expected );
  92. } );
  93. it( 'target at same offset and is less important: no position update', () => {
  94. const transformBy = new InsertOperation(
  95. new Position( root, [ 0, 2, 2 ] ),
  96. [ nodeC, nodeD ],
  97. baseVersion
  98. );
  99. const transOp = transform( transformBy, { isStrong: true } );
  100. expect( transOp.length ).to.equal( 1 );
  101. expectOperation( transOp[ 0 ], expected );
  102. } );
  103. it( 'target at same offset and context.insertBefore = true: no position update', () => {
  104. const transformBy = new InsertOperation(
  105. new Position( root, [ 0, 2, 2 ] ),
  106. [ nodeC, nodeD ],
  107. baseVersion
  108. );
  109. const transOp = transform( transformBy, { isStrong: false, insertBefore: false } );
  110. expect( transOp.length ).to.equal( 1 );
  111. expectOperation( transOp[ 0 ], expected );
  112. } );
  113. it( 'target at same offset and context.insertBefore = false: increment offset', () => {
  114. const transformBy = new InsertOperation(
  115. new Position( root, [ 0, 2, 2 ] ),
  116. [ nodeC, nodeD ],
  117. baseVersion
  118. );
  119. const transOp = transform( op, transformBy );
  120. expected.position.offset += 2;
  121. expect( transOp.length ).to.equal( 1 );
  122. expectOperation( transOp[ 0 ], expected );
  123. } );
  124. it( 'target at offset after: no position update', () => {
  125. const transformBy = new InsertOperation(
  126. new Position( root, [ 0, 2, 3 ] ),
  127. [ nodeC, nodeD ],
  128. baseVersion
  129. );
  130. const transOp = transform( op, transformBy );
  131. expect( transOp.length ).to.equal( 1 );
  132. expectOperation( transOp[ 0 ], expected );
  133. } );
  134. it( 'target before node from path: increment index on path', () => {
  135. const transformBy = new InsertOperation(
  136. new Position( root, [ 0, 1 ] ),
  137. [ nodeC, nodeD ],
  138. baseVersion
  139. );
  140. const transOp = transform( op, transformBy );
  141. expected.position.path[ 1 ] += 2;
  142. expect( transOp.length ).to.equal( 1 );
  143. expectOperation( transOp[ 0 ], expected );
  144. } );
  145. it( 'target after node from path: no position update', () => {
  146. const transformBy = new InsertOperation(
  147. new Position( root, [ 0, 6 ] ),
  148. [ nodeC, nodeD ],
  149. baseVersion
  150. );
  151. const transOp = transform( op, transformBy );
  152. expect( transOp.length ).to.equal( 1 );
  153. expectOperation( transOp[ 0 ], expected );
  154. } );
  155. } );
  156. describe( 'by AttributeOperation', () => {
  157. it( 'no position update', () => {
  158. const transformBy = new AttributeOperation(
  159. Range.createFromPositionAndShift( position, 2 ),
  160. 'foo',
  161. null,
  162. 'bar',
  163. baseVersion
  164. );
  165. const transOp = transform( op, transformBy );
  166. expect( transOp.length ).to.equal( 1 );
  167. expectOperation( transOp[ 0 ], expected );
  168. } );
  169. } );
  170. describe( 'by RootAttributeOperation', () => {
  171. it( 'no position update', () => {
  172. const transformBy = new RootAttributeOperation(
  173. root,
  174. 'foo',
  175. null,
  176. 'bar',
  177. baseVersion
  178. );
  179. const transOp = transform( op, transformBy );
  180. expect( transOp.length ).to.equal( 1 );
  181. expectOperation( transOp[ 0 ], expected );
  182. } );
  183. } );
  184. describe( 'by MoveOperation', () => {
  185. it( 'range and target are different than insert position: no position update', () => {
  186. const transformBy = new MoveOperation(
  187. new Position( root, [ 1, 3, 2 ] ),
  188. 2,
  189. new Position( root, [ 2, 1 ] ),
  190. baseVersion
  191. );
  192. const transOp = transform( op, transformBy );
  193. expect( transOp.length ).to.equal( 1 );
  194. expectOperation( transOp[ 0 ], expected );
  195. } );
  196. it( 'range is before insert position offset: decrement offset', () => {
  197. const transformBy = new MoveOperation(
  198. new Position( root, [ 0, 2, 0 ] ),
  199. 1,
  200. new Position( root, [ 1, 1 ] ),
  201. baseVersion
  202. );
  203. const transOp = transform( op, transformBy );
  204. expected.position.offset--;
  205. expect( transOp.length ).to.equal( 1 );
  206. expectOperation( transOp[ 0 ], expected );
  207. } );
  208. it( 'range offset is after insert position offset: no position update', () => {
  209. const transformBy = new MoveOperation(
  210. new Position( root, [ 0, 2, 5 ] ),
  211. 1,
  212. new Position( root, [ 1, 1 ] ),
  213. baseVersion
  214. );
  215. const transOp = transform( op, transformBy );
  216. expect( transOp.length ).to.equal( 1 );
  217. expectOperation( transOp[ 0 ], expected );
  218. } );
  219. it( 'target offset before insert position offset: increment offset', () => {
  220. const transformBy = new MoveOperation(
  221. new Position( root, [ 1, 1 ] ),
  222. 2,
  223. new Position( root, [ 0, 2, 0 ] ),
  224. baseVersion
  225. );
  226. const transOp = transform( op, transformBy );
  227. expected.position.offset += 2;
  228. expect( transOp.length ).to.equal( 1 );
  229. expectOperation( transOp[ 0 ], expected );
  230. } );
  231. it( 'target offset after insert position offset: no position update', () => {
  232. const transformBy = new MoveOperation(
  233. new Position( root, [ 1, 1 ] ),
  234. 2,
  235. new Position( root, [ 0, 2, 5 ] ),
  236. baseVersion
  237. );
  238. const transOp = transform( op, transformBy );
  239. expect( transOp.length ).to.equal( 1 );
  240. expectOperation( transOp[ 0 ], expected );
  241. } );
  242. it( 'target offset same as insert position offset and is important: increment offset', () => {
  243. const transformBy = new MoveOperation(
  244. new Position( root, [ 1, 1 ] ),
  245. 2,
  246. new Position( root, [ 0, 2, 2 ] ),
  247. baseVersion
  248. );
  249. const transOp = transform( op, transformBy );
  250. expected.position.offset += 2;
  251. expect( transOp.length ).to.equal( 1 );
  252. expectOperation( transOp[ 0 ], expected );
  253. } );
  254. it( 'target offset same as insert position offset and is less important: no position update', () => {
  255. const transformBy = new MoveOperation(
  256. new Position( root, [ 1, 1 ] ),
  257. 2,
  258. new Position( root, [ 0, 2, 2 ] ),
  259. baseVersion
  260. );
  261. const transOp = transform( op, transformBy, { isStrong: true } );
  262. expect( transOp.length ).to.equal( 1 );
  263. expectOperation( transOp[ 0 ], expected );
  264. } );
  265. it( 'target offset same as insert position offset and context.insertBefore = true: increment offset', () => {
  266. const transformBy = new MoveOperation(
  267. new Position( root, [ 1, 1 ] ),
  268. 2,
  269. new Position( root, [ 0, 2, 2 ] ),
  270. baseVersion
  271. );
  272. const transOp = transform( op, transformBy, { isStrong: true, insertBefore: true } );
  273. expected.position.offset += 2;
  274. expect( transOp.length ).to.equal( 1 );
  275. expectOperation( transOp[ 0 ], expected );
  276. } );
  277. it( 'target offset same as insert position offset and context.insertBefore = false: no position update', () => {
  278. const transformBy = new MoveOperation(
  279. new Position( root, [ 1, 1 ] ),
  280. 2,
  281. new Position( root, [ 0, 2, 2 ] ),
  282. baseVersion
  283. );
  284. const transOp = transform( op, transformBy, { isStrong: false, insertBefore: false } );
  285. expect( transOp.length ).to.equal( 1 );
  286. expectOperation( transOp[ 0 ], expected );
  287. } );
  288. it( 'range is before node from insert position path: decrement index on path', () => {
  289. const transformBy = new MoveOperation(
  290. new Position( root, [ 0, 0 ] ),
  291. 1,
  292. new Position( root, [ 1, 0 ] ),
  293. baseVersion
  294. );
  295. const transOp = transform( op, transformBy );
  296. expected.position.path[ 1 ] -= 1;
  297. expect( transOp.length ).to.equal( 1 );
  298. expectOperation( transOp[ 0 ], expected );
  299. } );
  300. it( 'range is after node from insert position path: no position update', () => {
  301. const transformBy = new MoveOperation(
  302. new Position( root, [ 0, 4 ] ),
  303. 2,
  304. new Position( root, [ 1, 0 ] ),
  305. baseVersion
  306. );
  307. const transOp = transform( op, transformBy );
  308. expect( transOp.length ).to.equal( 1 );
  309. expectOperation( transOp[ 0 ], expected );
  310. } );
  311. it( 'target before node from insert position path: increment index on path', () => {
  312. const transformBy = new MoveOperation(
  313. new Position( root, [ 1, 0 ] ),
  314. 2,
  315. new Position( root, [ 0, 0 ] ),
  316. baseVersion
  317. );
  318. const transOp = transform( op, transformBy );
  319. expected.position.path[ 1 ] += 2;
  320. expect( transOp.length ).to.equal( 1 );
  321. expectOperation( transOp[ 0 ], expected );
  322. } );
  323. it( 'target after node from insert position path: no position update', () => {
  324. const transformBy = new MoveOperation(
  325. new Position( root, [ 1, 0 ] ),
  326. 2,
  327. new Position( root, [ 0, 4 ] ),
  328. baseVersion
  329. );
  330. const transOp = transform( op, transformBy );
  331. expect( transOp.length ).to.equal( 1 );
  332. expectOperation( transOp[ 0 ], expected );
  333. } );
  334. it( 'range has node that contains insert position: update position', () => {
  335. const transformBy = new MoveOperation(
  336. new Position( root, [ 0, 1 ] ),
  337. 2,
  338. new Position( root, [ 1, 1 ] ),
  339. baseVersion
  340. );
  341. const transOp = transform( op, transformBy );
  342. expected.position.path = [ 1, 2, 2 ];
  343. expect( transOp.length ).to.equal( 1 );
  344. expectOperation( transOp[ 0 ], expected );
  345. } );
  346. it( 'range contains insert position (on same level): update position', () => {
  347. const transformBy = new MoveOperation(
  348. new Position( root, [ 0, 2, 0 ] ),
  349. 4,
  350. new Position( root, [ 1, 0 ] ),
  351. baseVersion
  352. );
  353. const transOp = transform( op, transformBy );
  354. expected.position.path = [ 1, 2 ];
  355. expect( transOp.length ).to.equal( 1 );
  356. expectOperation( transOp[ 0 ], expected );
  357. } );
  358. } );
  359. describe( 'by NoOperation', () => {
  360. it( 'no operation update', () => {
  361. const transformBy = new NoOperation( baseVersion );
  362. const transOp = transform( op, transformBy );
  363. expect( transOp.length ).to.equal( 1 );
  364. expectOperation( transOp[ 0 ], expected );
  365. } );
  366. } );
  367. describe( 'by RenameOperation', () => {
  368. it( 'no position update', () => {
  369. const transformBy = new RenameOperation( new Position( root, [ 0, 2, 0 ] ), 'oldName', 'newName', baseVersion );
  370. const transOp = transform( op, transformBy );
  371. expect( transOp.length ).to.equal( 1 );
  372. expectOperation( transOp[ 0 ], expected );
  373. } );
  374. } );
  375. describe( 'by MarkerOperation', () => {
  376. it( 'no position update', () => {
  377. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 4 ] ) );
  378. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  379. const transOp = transform( op, transformBy );
  380. expect( transOp.length ).to.equal( 1 );
  381. expectOperation( transOp[ 0 ], expected );
  382. } );
  383. } );
  384. } );
  385. describe( 'AttributeOperation', () => {
  386. let start, end, range;
  387. beforeEach( () => {
  388. expected = {
  389. type: AttributeOperation,
  390. key: 'foo',
  391. oldValue: 'abc',
  392. newValue: 'bar',
  393. baseVersion: baseVersion + 1
  394. };
  395. } );
  396. describe( 'with multi-level range', () => {
  397. beforeEach( () => {
  398. start = new Position( root, [ 1, 2 ] );
  399. end = new Position( root, [ 2, 2, 4 ] );
  400. range = new Range( start, end );
  401. op = new AttributeOperation( range, 'foo', 'abc', 'bar', baseVersion );
  402. expected.range = new Range( start, end );
  403. } );
  404. describe( 'by InsertOperation', () => {
  405. it( 'target at different position: no operation update', () => {
  406. const transformBy = new InsertOperation(
  407. new Position( root, [ 3, 3, 2 ] ),
  408. [ nodeA, nodeB ],
  409. baseVersion
  410. );
  411. const transOp = transform( op, transformBy );
  412. expect( transOp.length ).to.equal( 1 );
  413. expectOperation( transOp[ 0 ], expected );
  414. } );
  415. it( 'target at offset before: increment offset', () => {
  416. const transformBy = new InsertOperation(
  417. new Position( root, [ 1, 1 ] ),
  418. [ nodeA, nodeB ],
  419. baseVersion
  420. );
  421. const transOp = transform( op, transformBy );
  422. expected.range.start.offset += 2;
  423. expect( transOp.length ).to.equal( 1 );
  424. expectOperation( transOp[ 0 ], expected );
  425. } );
  426. it( 'target at same offset: increment offset', () => {
  427. const transformBy = new InsertOperation(
  428. new Position( root, [ 1, 2 ] ),
  429. [ nodeA, nodeB ],
  430. baseVersion
  431. );
  432. const transOp = transform( op, transformBy );
  433. expected.range.start.offset += 2;
  434. expect( transOp.length ).to.equal( 1 );
  435. expectOperation( transOp[ 0 ], expected );
  436. } );
  437. it( 'target at offset after: no operation update', () => {
  438. const transformBy = new InsertOperation(
  439. new Position( root, [ 3, 2 ] ),
  440. [ nodeA, nodeB ],
  441. baseVersion
  442. );
  443. const transOp = transform( op, transformBy );
  444. expect( transOp.length ).to.equal( 1 );
  445. expectOperation( transOp[ 0 ], expected );
  446. } );
  447. it( 'target before node from path: increment index on path', () => {
  448. const transformBy = new InsertOperation(
  449. new Position( root, [ 0 ] ),
  450. [ nodeA, nodeB ],
  451. baseVersion
  452. );
  453. const transOp = transform( op, transformBy );
  454. expected.range.start.path[ 0 ] += 2;
  455. expected.range.end.path[ 0 ] += 2;
  456. expect( transOp.length ).to.equal( 1 );
  457. expectOperation( transOp[ 0 ], expected );
  458. } );
  459. it( 'target after node from path: no position change', () => {
  460. const transformBy = new InsertOperation(
  461. new Position( root, [ 2, 6 ] ),
  462. [ nodeA, nodeB ],
  463. baseVersion
  464. );
  465. const transOp = transform( op, transformBy );
  466. expect( transOp.length ).to.equal( 1 );
  467. expectOperation( transOp[ 0 ], expected );
  468. } );
  469. it( 'target inside change range: split into two operations', () => {
  470. const transformBy = new InsertOperation(
  471. new Position( root, [ 1, 3, 1 ] ),
  472. [ nodeA, nodeB ],
  473. baseVersion
  474. );
  475. const transOp = transform( op, transformBy );
  476. expect( transOp.length ).to.equal( 2 );
  477. expected.range.start.path = [ 1, 3, 3 ];
  478. expectOperation( transOp[ 0 ], expected );
  479. expected.range.start = op.range.start;
  480. expected.range.end.path = [ 1, 3, 1 ];
  481. expected.baseVersion++;
  482. expectOperation( transOp[ 1 ], expected );
  483. } );
  484. } );
  485. describe( 'by AttributeOperation', () => {
  486. it( 'attributes have different key: no operation update', () => {
  487. const transformBy = new AttributeOperation(
  488. Range.createFromRange( range ),
  489. 'differentKey',
  490. true,
  491. false,
  492. baseVersion
  493. );
  494. const transOp = transform( op, transformBy );
  495. expect( transOp.length ).to.equal( 1 );
  496. expectOperation( transOp[ 0 ], expected );
  497. } );
  498. it( 'same key and value: convert to NoOperation', () => {
  499. const transformBy = new AttributeOperation(
  500. Range.createFromRange( range ),
  501. 'foo',
  502. 'abc',
  503. 'bar',
  504. baseVersion
  505. );
  506. const transOp = transform( op, transformBy );
  507. expect( transOp.length ).to.equal( 1 );
  508. expectOperation( transOp[ 0 ], {
  509. type: NoOperation,
  510. baseVersion: baseVersion + 1
  511. } );
  512. } );
  513. describe( 'that is less important and', () => {
  514. it( 'both operations removes same attribute: change old value to null', () => {
  515. op.newValue = null;
  516. expected.newValue = null;
  517. const transformBy = new AttributeOperation(
  518. new Range( new Position( root, [ 1, 1, 4 ] ), new Position( root, [ 3 ] ) ),
  519. 'foo',
  520. 'another',
  521. null,
  522. baseVersion
  523. );
  524. const transOp = transform( op, transformBy, { isStrong: true } );
  525. expected.oldValue = null;
  526. expect( transOp.length ).to.equal( 1 );
  527. } );
  528. it( 'range does not intersect original range: no operation update', () => {
  529. const transformBy = new AttributeOperation(
  530. new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 4 ] ) ),
  531. 'foo',
  532. 'abc',
  533. null,
  534. baseVersion
  535. );
  536. const transOp = transform( op, transformBy, { isStrong: true } );
  537. expect( transOp.length ).to.equal( 1 );
  538. expectOperation( transOp[ 0 ], expected );
  539. } );
  540. it( 'range contains original range: update oldValue', () => {
  541. const transformBy = new AttributeOperation(
  542. new Range( new Position( root, [ 1, 1, 4 ] ), new Position( root, [ 3 ] ) ),
  543. 'foo',
  544. 'abc',
  545. null,
  546. baseVersion
  547. );
  548. const transOp = transform( op, transformBy, { isStrong: true } );
  549. expected.oldValue = null;
  550. expect( transOp.length ).to.equal( 1 );
  551. expectOperation( transOp[ 0 ], expected );
  552. } );
  553. // [ original range < ] range transformed by >
  554. it( 'range intersects on left: split into two operations, update oldValue', () => {
  555. // Get more test cases and better code coverage
  556. op.newValue = null;
  557. expected.newValue = null;
  558. const transformBy = new AttributeOperation(
  559. new Range( new Position( root, [ 1, 4, 2 ] ), new Position( root, [ 3 ] ) ),
  560. 'foo',
  561. null,
  562. // Get more test cases and better code coverage
  563. 'another',
  564. baseVersion
  565. );
  566. const transOp = transform( op, transformBy, { isStrong: true } );
  567. expect( transOp.length ).to.equal( 2 );
  568. expected.range.end.path = [ 1, 4, 2 ];
  569. expectOperation( transOp[ 0 ], expected );
  570. expected.range.start.path = [ 1, 4, 2 ];
  571. expected.range.end = op.range.end;
  572. expected.oldValue = 'another';
  573. expected.baseVersion++;
  574. expectOperation( transOp[ 1 ], expected );
  575. } );
  576. // [ range transformed by < ] original range >
  577. it( 'range intersects on right: split into two operations, update oldValue', () => {
  578. const transformBy = new AttributeOperation(
  579. new Range( new Position( root, [ 1 ] ), new Position( root, [ 2, 1 ] ) ),
  580. 'foo',
  581. 'abc',
  582. null,
  583. baseVersion
  584. );
  585. const transOp = transform( op, transformBy, { isStrong: true } );
  586. expect( transOp.length ).to.equal( 2 );
  587. expected.range.start.path = [ 2, 1 ];
  588. expectOperation( transOp[ 0 ], expected );
  589. expected.range.start = op.range.start;
  590. expected.range.end.path = [ 2, 1 ];
  591. expected.oldValue = null;
  592. expected.baseVersion++;
  593. expectOperation( transOp[ 1 ], expected );
  594. } );
  595. it( 'range is inside original range: split into three operations, update oldValue', () => {
  596. const transformBy = new AttributeOperation(
  597. new Range( new Position( root, [ 1, 4, 1 ] ), new Position( root, [ 2, 1 ] ) ),
  598. 'foo',
  599. 'abc',
  600. null,
  601. baseVersion
  602. );
  603. const transOp = transform( op, transformBy, { isStrong: true } );
  604. expect( transOp.length ).to.equal( 3 );
  605. expected.range.end.path = [ 1, 4, 1 ];
  606. expectOperation( transOp[ 0 ], expected );
  607. expected.range.start.path = [ 2, 1 ];
  608. expected.range.end = op.range.end;
  609. expected.baseVersion++;
  610. expectOperation( transOp[ 1 ], expected );
  611. expected.range.start.path = [ 1, 4, 1 ];
  612. expected.range.end.path = [ 2, 1 ];
  613. expected.oldValue = null;
  614. expected.baseVersion++;
  615. expectOperation( transOp[ 2 ], expected );
  616. } );
  617. } );
  618. describe( 'that is more important and', () => {
  619. it( 'both operations removes same attribute: convert to NoOperation', () => {
  620. op.newValue = null;
  621. expected.newValue = null;
  622. const transformBy = new AttributeOperation(
  623. new Range( new Position( root, [ 1, 1, 4 ] ), new Position( root, [ 3 ] ) ),
  624. 'foo',
  625. 'another',
  626. null,
  627. baseVersion
  628. );
  629. const transOp = transform( op, transformBy );
  630. expect( transOp.length ).to.equal( 1 );
  631. expectOperation( transOp[ 0 ], {
  632. type: NoOperation,
  633. baseVersion: baseVersion + 1
  634. } );
  635. } );
  636. it( 'range does not intersect original range: no operation update', () => {
  637. const transformBy = new AttributeOperation(
  638. new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 4 ] ) ),
  639. 'foo',
  640. 'abc',
  641. null,
  642. baseVersion
  643. );
  644. const transOp = transform( op, transformBy );
  645. expect( transOp.length ).to.equal( 1 );
  646. expectOperation( transOp[ 0 ], expected );
  647. } );
  648. it( 'range contains original range: convert to NoOperation', () => {
  649. const transformBy = new AttributeOperation(
  650. new Range( new Position( root, [ 1, 1, 4 ] ), new Position( root, [ 3 ] ) ),
  651. 'foo',
  652. 'abc',
  653. null,
  654. baseVersion
  655. );
  656. const transOp = transform( op, transformBy );
  657. expect( transOp.length ).to.equal( 1 );
  658. expectOperation( transOp[ 0 ], {
  659. type: NoOperation,
  660. baseVersion: baseVersion + 1
  661. } );
  662. } );
  663. // [ original range < ] range transformed by >
  664. it( 'range intersects on left: shrink original range', () => {
  665. const transformBy = new AttributeOperation(
  666. new Range( new Position( root, [ 1, 4, 2 ] ), new Position( root, [ 3 ] ) ),
  667. 'foo',
  668. 'abc',
  669. null,
  670. baseVersion
  671. );
  672. const transOp = transform( op, transformBy );
  673. expected.range.end.path = [ 1, 4, 2 ];
  674. expect( transOp.length ).to.equal( 1 );
  675. expectOperation( transOp[ 0 ], expected );
  676. } );
  677. // [ range transformed by < ] original range >
  678. it( 'range intersects on right: shrink original range', () => {
  679. const transformBy = new AttributeOperation(
  680. new Range( new Position( root, [ 1 ] ), new Position( root, [ 2, 1 ] ) ),
  681. 'foo',
  682. 'abc',
  683. null,
  684. baseVersion
  685. );
  686. const transOp = transform( op, transformBy );
  687. expected.range.start.path = [ 2, 1 ];
  688. expect( transOp.length ).to.equal( 1 );
  689. expectOperation( transOp[ 0 ], expected );
  690. } );
  691. it( 'range is inside original range: split into two operations', () => {
  692. const transformBy = new AttributeOperation(
  693. new Range( new Position( root, [ 1, 4, 1 ] ), new Position( root, [ 2, 1 ] ) ),
  694. 'foo',
  695. 'abc',
  696. null,
  697. baseVersion
  698. );
  699. const transOp = transform( op, transformBy );
  700. expect( transOp.length ).to.equal( 2 );
  701. expected.range.end.path = [ 1, 4, 1 ];
  702. expectOperation( transOp[ 0 ], expected );
  703. expected.range.start.path = [ 2, 1 ];
  704. expected.range.end = op.range.end;
  705. expected.baseVersion++;
  706. expectOperation( transOp[ 1 ], expected );
  707. } );
  708. } );
  709. } );
  710. describe( 'by RootAttributeOperation', () => {
  711. it( 'no operation update', () => {
  712. const transformBy = new RootAttributeOperation(
  713. root,
  714. 'foo',
  715. null,
  716. 'bar',
  717. baseVersion
  718. );
  719. const transOp = transform( op, transformBy );
  720. expect( transOp.length ).to.equal( 1 );
  721. expectOperation( transOp[ 0 ], expected );
  722. } );
  723. } );
  724. describe( 'by MoveOperation', () => {
  725. it( 'range and target are different than change range: no operation update', () => {
  726. const transformBy = new MoveOperation(
  727. new Position( root, [ 1, 1, 2 ] ),
  728. 2,
  729. new Position( root, [ 3, 4 ] ),
  730. baseVersion
  731. );
  732. const transOp = transform( op, transformBy );
  733. expect( transOp.length ).to.equal( 1 );
  734. expectOperation( transOp[ 0 ], expected );
  735. } );
  736. it( 'range offset is before change range start offset: decrement offset', () => {
  737. const transformBy = new MoveOperation(
  738. new Position( root, [ 1, 0 ] ),
  739. 2,
  740. new Position( root, [ 3, 4, 1 ] ),
  741. baseVersion
  742. );
  743. const transOp = transform( op, transformBy );
  744. expected.range.start.offset -= 2;
  745. expect( transOp.length ).to.equal( 1 );
  746. expectOperation( transOp[ 0 ], expected );
  747. } );
  748. it( 'target offset is before change range start offset: increment offset', () => {
  749. const transformBy = new MoveOperation(
  750. new Position( root, [ 3, 4, 1 ] ),
  751. 2,
  752. new Position( root, [ 1, 0 ] ),
  753. baseVersion
  754. );
  755. const transOp = transform( op, transformBy );
  756. expected.range.start.offset += 2;
  757. expect( transOp.length ).to.equal( 1 );
  758. expectOperation( transOp[ 0 ], expected );
  759. } );
  760. it( 'range is before node from path to change range: decrement index on path', () => {
  761. const transformBy = new MoveOperation(
  762. new Position( root, [ 0 ] ),
  763. 1,
  764. new Position( root, [ 2, 4, 1 ] ),
  765. baseVersion
  766. );
  767. const transOp = transform( op, transformBy );
  768. expected.range.start.path[ 0 ]--;
  769. expected.range.end.path[ 0 ]--;
  770. expect( transOp.length ).to.equal( 1 );
  771. expectOperation( transOp[ 0 ], expected );
  772. } );
  773. it( 'range is after node from path to change range: no position change', () => {
  774. const transformBy = new MoveOperation(
  775. new Position( root, [ 3 ] ),
  776. 2,
  777. new Position( root, [ 0, 1 ] ),
  778. baseVersion
  779. );
  780. const transOp = transform( op, transformBy );
  781. expect( transOp.length ).to.equal( 1 );
  782. expectOperation( transOp[ 0 ], expected );
  783. } );
  784. it( 'target before node from path to change range: increment index on path', () => {
  785. const transformBy = new MoveOperation(
  786. new Position( root, [ 3, 4, 1 ] ),
  787. 2,
  788. new Position( root, [ 1, 0 ] ),
  789. baseVersion
  790. );
  791. const transOp = transform( op, transformBy );
  792. expected.range.start.path[ 1 ] += 2;
  793. expect( transOp.length ).to.equal( 1 );
  794. expectOperation( transOp[ 0 ], expected );
  795. } );
  796. it( 'target after node from path to change range: no position change', () => {
  797. const transformBy = new MoveOperation(
  798. new Position( root, [ 3, 4, 1 ] ),
  799. 2,
  800. new Position( root, [ 3 ] ),
  801. baseVersion
  802. );
  803. const transOp = transform( op, transformBy );
  804. expect( transOp.length ).to.equal( 1 );
  805. expectOperation( transOp[ 0 ], expected );
  806. } );
  807. it( 'range intersects on left with change range: split into two operations', () => {
  808. const transformBy = new MoveOperation(
  809. new Position( root, [ 2, 1 ] ),
  810. 3,
  811. new Position( root, [ 4 ] ),
  812. baseVersion
  813. );
  814. const transOp = transform( op, transformBy );
  815. expect( transOp.length ).to.equal( 2 );
  816. expected.range.end.path = [ 2, 1 ];
  817. expectOperation( transOp[ 0 ], expected );
  818. expected.range.start.path = [ 4 ];
  819. expected.range.end.path = [ 5, 4 ];
  820. expected.baseVersion++;
  821. expectOperation( transOp[ 1 ], expected );
  822. } );
  823. it( 'range intersects on right with change range: split into two operation', () => {
  824. const transformBy = new MoveOperation(
  825. new Position( root, [ 1, 1 ] ),
  826. 3,
  827. new Position( root, [ 0, 0 ] ),
  828. baseVersion
  829. );
  830. const transOp = transform( op, transformBy );
  831. expect( transOp.length ).to.equal( 2 );
  832. expected.range.start.path = [ 1, 1 ];
  833. expectOperation( transOp[ 0 ], expected );
  834. expected.range.start.path = [ 0, 1 ];
  835. expected.range.end.path = [ 0, 3 ];
  836. expected.baseVersion++;
  837. expectOperation( transOp[ 1 ], expected );
  838. } );
  839. it( 'range contains change range: update change range', () => {
  840. const transformBy = new MoveOperation(
  841. new Position( root, [ 1 ] ),
  842. 2,
  843. new Position( root, [ 3, 4, 1 ] ),
  844. baseVersion
  845. );
  846. const transOp = transform( op, transformBy );
  847. expected.range.start.path = [ 1, 4, 1, 2 ];
  848. expected.range.end.path = [ 1, 4, 2, 2, 4 ];
  849. expect( transOp.length ).to.equal( 1 );
  850. expectOperation( transOp[ 0 ], expected );
  851. } );
  852. it( 'range is inside change range: split into two operations', () => {
  853. const transformBy = new MoveOperation(
  854. new Position( root, [ 1, 4 ] ),
  855. 2,
  856. new Position( root, [ 3, 2 ] ),
  857. baseVersion
  858. );
  859. const transOp = transform( op, transformBy );
  860. expect( transOp.length ).to.equal( 2 );
  861. expectOperation( transOp[ 0 ], expected );
  862. expected.range.start.path = [ 3, 2 ];
  863. expected.range.end.path = [ 3, 4 ];
  864. expected.baseVersion++;
  865. expectOperation( transOp[ 1 ], expected );
  866. } );
  867. it( 'target inside change range: split into two operations', () => {
  868. const transformBy = new MoveOperation(
  869. new Position( root, [ 3, 4, 1 ] ),
  870. 2,
  871. new Position( root, [ 1, 4 ] ),
  872. baseVersion
  873. );
  874. const transOp = transform( op, transformBy );
  875. expect( transOp.length ).to.equal( 2 );
  876. expected.range.start.path = [ 1, 6 ];
  877. expectOperation( transOp[ 0 ], expected );
  878. expected.range.start = op.range.start;
  879. expected.range.end.path = [ 1, 4 ];
  880. expected.baseVersion++;
  881. expectOperation( transOp[ 1 ], expected );
  882. } );
  883. it( 'range intersects change range and target inside change range: split into three operations', () => {
  884. const transformBy = new MoveOperation(
  885. new Position( root, [ 1, 1 ] ),
  886. 3,
  887. new Position( root, [ 2 ] ),
  888. baseVersion
  889. );
  890. const transOp = transform( op, transformBy );
  891. expect( transOp.length ).to.equal( 3 );
  892. expected.range.start.path = [ 5 ];
  893. expected.range.end.path = [ 5, 2, 4 ];
  894. expectOperation( transOp[ 0 ], expected );
  895. expected.range.start.path = [ 1, 1 ];
  896. expected.range.end.path = [ 2 ];
  897. expected.baseVersion++;
  898. expectOperation( transOp[ 1 ], expected );
  899. expected.range.start.path = [ 3 ];
  900. expected.range.end.path = [ 5 ];
  901. expected.baseVersion++;
  902. expectOperation( transOp[ 2 ], expected );
  903. } );
  904. } );
  905. describe( 'by NoOperation', () => {
  906. it( 'no operation update', () => {
  907. const transformBy = new NoOperation( baseVersion );
  908. const transOp = transform( op, transformBy );
  909. expect( transOp.length ).to.equal( 1 );
  910. expectOperation( transOp[ 0 ], expected );
  911. } );
  912. } );
  913. describe( 'by RenameOperation', () => {
  914. it( 'no position update', () => {
  915. const transformBy = new RenameOperation( new Position( root, [ 1, 0 ] ), 'oldName', 'newName', baseVersion );
  916. const transOp = transform( op, transformBy );
  917. expect( transOp.length ).to.equal( 1 );
  918. expectOperation( transOp[ 0 ], expected );
  919. } );
  920. } );
  921. describe( 'by MarkerOperation', () => {
  922. it( 'no operation update', () => {
  923. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  924. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  925. const transOp = transform( op, transformBy );
  926. expect( transOp.length ).to.equal( 1 );
  927. expectOperation( transOp[ 0 ], expected );
  928. } );
  929. } );
  930. } );
  931. // Some extra cases for a AttributeOperation that operates on single tree level range.
  932. // This means that the change range start and end differs only on offset value.
  933. // This test suite also have some modifications to the original operation
  934. // to get more test cases covered and better code coverage.
  935. describe( 'with single-level range', () => {
  936. beforeEach( () => {
  937. start = new Position( root, [ 0, 2, 1 ] );
  938. end = new Position( root, [ 0, 2, 4 ] );
  939. range = new Range( start, end );
  940. op = new AttributeOperation( range, 'foo', 'abc', 'bar', baseVersion );
  941. expected.range = new Range( start, end );
  942. } );
  943. describe( 'by InsertOperation', () => {
  944. it( 'target at offset before: increment offset', () => {
  945. const transformBy = new InsertOperation(
  946. new Position( root, [ 0, 2, 0 ] ),
  947. [ nodeA, nodeB ],
  948. baseVersion
  949. );
  950. const transOp = transform( op, transformBy );
  951. expected.range.start.offset += 2;
  952. expected.range.end.offset += 2;
  953. expect( transOp.length ).to.equal( 1 );
  954. expectOperation( transOp[ 0 ], expected );
  955. } );
  956. it( 'target at same offset: increment offset', () => {
  957. const transformBy = new InsertOperation(
  958. new Position( root, [ 0, 2, 1 ] ),
  959. [ nodeA, nodeB ],
  960. baseVersion
  961. );
  962. const transOp = transform( op, transformBy );
  963. expected.range.start.offset += 2;
  964. expected.range.end.offset += 2;
  965. expect( transOp.length ).to.equal( 1 );
  966. expectOperation( transOp[ 0 ], expected );
  967. } );
  968. } );
  969. describe( 'by MoveOperation', () => {
  970. it( 'range offset is before change range start offset: decrement offset', () => {
  971. const transformBy = new MoveOperation(
  972. new Position( root, [ 0, 2, 0 ] ),
  973. 1,
  974. new Position( root, [ 2, 4, 1 ] ),
  975. baseVersion
  976. );
  977. const transOp = transform( op, transformBy );
  978. expected.range.start.offset--;
  979. expected.range.end.offset--;
  980. expect( transOp.length ).to.equal( 1 );
  981. expectOperation( transOp[ 0 ], expected );
  982. } );
  983. it( 'target offset is before change range start offset: increment offset', () => {
  984. const transformBy = new MoveOperation(
  985. new Position( root, [ 2, 4, 1 ] ),
  986. 2,
  987. new Position( root, [ 0, 2, 0 ] ),
  988. baseVersion
  989. );
  990. const transOp = transform( op, transformBy );
  991. expected.range.start.offset += 2;
  992. expected.range.end.offset += 2;
  993. expect( transOp.length ).to.equal( 1 );
  994. expectOperation( transOp[ 0 ], expected );
  995. } );
  996. it( 'range intersects on left with change range: split into two operations', () => {
  997. const transformBy = new MoveOperation(
  998. new Position( root, [ 0, 2, 2 ] ),
  999. 4,
  1000. new Position( root, [ 2, 4, 1 ] ),
  1001. baseVersion
  1002. );
  1003. const transOp = transform( op, transformBy );
  1004. expect( transOp.length ).to.equal( 2 );
  1005. expected.range.end.offset -= 2;
  1006. expectOperation( transOp[ 0 ], expected );
  1007. expected.range.start.path = [ 2, 4, 1 ];
  1008. expected.range.end.path = [ 2, 4, 3 ];
  1009. expected.baseVersion++;
  1010. expectOperation( transOp[ 1 ], expected );
  1011. } );
  1012. it( 'range intersects on right with change range: split into two operation', () => {
  1013. const transformBy = new MoveOperation(
  1014. new Position( root, [ 0, 2, 0 ] ),
  1015. 2,
  1016. new Position( root, [ 2, 4, 1 ] ),
  1017. baseVersion
  1018. );
  1019. const transOp = transform( op, transformBy );
  1020. expect( transOp.length ).to.equal( 2 );
  1021. expected.range.start.offset -= 1;
  1022. expected.range.end.offset -= 2;
  1023. expectOperation( transOp[ 0 ], expected );
  1024. expected.range.start.path = [ 2, 4, 2 ];
  1025. expected.range.end.path = [ 2, 4, 3 ];
  1026. expected.baseVersion++;
  1027. expectOperation( transOp[ 1 ], expected );
  1028. } );
  1029. it( 'range contains change range: update change range', () => {
  1030. const transformBy = new MoveOperation(
  1031. new Position( root, [ 0, 1 ] ),
  1032. 3,
  1033. new Position( root, [ 2, 4, 1 ] ),
  1034. baseVersion
  1035. );
  1036. const transOp = transform( op, transformBy );
  1037. expected.range.start.path = [ 2, 4, 2, 1 ];
  1038. expected.range.end.path = [ 2, 4, 2, 4 ];
  1039. expect( transOp.length ).to.equal( 1 );
  1040. expectOperation( transOp[ 0 ], expected );
  1041. } );
  1042. it( 'range is inside change range: split into two operations', () => {
  1043. const transformBy = new MoveOperation(
  1044. new Position( root, [ 0, 2, 2 ] ),
  1045. 1,
  1046. new Position( root, [ 2, 4, 1 ] ),
  1047. baseVersion
  1048. );
  1049. const transOp = transform( op, transformBy );
  1050. expect( transOp.length ).to.equal( 2 );
  1051. expected.range.end.offset--;
  1052. expectOperation( transOp[ 0 ], expected );
  1053. expected.range.start.path = [ 2, 4, 1 ];
  1054. expected.range.end.path = [ 2, 4, 2 ];
  1055. expected.baseVersion++;
  1056. expectOperation( transOp[ 1 ], expected );
  1057. } );
  1058. it( 'range is same as change range: update change range', () => {
  1059. const transformBy = new MoveOperation(
  1060. new Position( root, [ 0, 2, 1 ] ),
  1061. 3,
  1062. new Position( root, [ 2, 4, 1 ] ),
  1063. baseVersion
  1064. );
  1065. const transOp = transform( op, transformBy );
  1066. expected.range.start.path = [ 2, 4, 1 ];
  1067. expected.range.end.path = [ 2, 4, 4 ];
  1068. expect( transOp.length ).to.equal( 1 );
  1069. expectOperation( transOp[ 0 ], expected );
  1070. } );
  1071. it( 'target inside change range: split into two operations', () => {
  1072. const transformBy = new MoveOperation(
  1073. new Position( root, [ 2, 4, 1 ] ),
  1074. 2,
  1075. new Position( root, [ 0, 2, 2 ] ),
  1076. baseVersion
  1077. );
  1078. const transOp = transform( op, transformBy );
  1079. expect( transOp.length ).to.equal( 2 );
  1080. expected.range.start.offset = 4;
  1081. expected.range.end.offset = 6;
  1082. expectOperation( transOp[ 0 ], expected );
  1083. expected.range.start.offset = op.range.start.offset;
  1084. expected.range.end.offset = 2;
  1085. expected.baseVersion++;
  1086. expectOperation( transOp[ 1 ], expected );
  1087. } );
  1088. it( 'range intersects change range and target inside change range: split into three operations', () => {
  1089. const transformBy = new MoveOperation(
  1090. new Position( root, [ 0, 2, 0 ] ),
  1091. 2,
  1092. new Position( root, [ 0, 2, 3 ] ),
  1093. baseVersion
  1094. );
  1095. const transOp = transform( op, transformBy );
  1096. expect( transOp.length ).to.equal( 3 );
  1097. expected.range.start.offset = 3;
  1098. expected.range.end.offset = 4;
  1099. expectOperation( transOp[ 0 ], expected );
  1100. expected.range.start.offset = 0;
  1101. expected.range.end.offset = 1;
  1102. expected.baseVersion++;
  1103. expectOperation( transOp[ 1 ], expected );
  1104. expected.range.start.offset = 2;
  1105. expected.range.end.offset = 3;
  1106. expected.baseVersion++;
  1107. expectOperation( transOp[ 2 ], expected );
  1108. } );
  1109. } );
  1110. } );
  1111. describe( 'by RemoveOperation', () => {
  1112. beforeEach( () => {
  1113. start = new Position( doc.graveyard, [ 2, 0 ] );
  1114. end = new Position( doc.graveyard, [ 2, 4 ] );
  1115. range = new Range( start, end );
  1116. op = new AttributeOperation( range, 'foo', 'abc', 'bar', baseVersion );
  1117. expected.range = new Range( start, end );
  1118. } );
  1119. it( 'remove operation inserted elements before attribute operation range: increment path', () => {
  1120. const transformBy = new RemoveOperation(
  1121. new Position( root, [ 0 ] ),
  1122. 2,
  1123. new Position( doc.graveyard, [ 0 ] ),
  1124. baseVersion
  1125. );
  1126. transformBy.targetPosition.path = [ 0 ];
  1127. const transOp = transform( op, transformBy );
  1128. expect( transOp.length ).to.equal( 1 );
  1129. expected.range.start.path = [ 4, 0 ];
  1130. expected.range.end.path = [ 4, 4 ];
  1131. expectOperation( transOp[ 0 ], expected );
  1132. } );
  1133. it( 'remove operation inserted elements after attribute operation range: do nothing', () => {
  1134. const transformBy = new RemoveOperation(
  1135. new Position( root, [ 0 ] ),
  1136. 2,
  1137. new Position( doc.graveyard, [ 0 ] ),
  1138. baseVersion
  1139. );
  1140. transformBy.targetPosition.path = [ 4 ];
  1141. const transOp = transform( op, transformBy );
  1142. expect( transOp.length ).to.equal( 1 );
  1143. expectOperation( transOp[ 0 ], expected );
  1144. } );
  1145. } );
  1146. } );
  1147. describe( 'RootAttributeOperation', () => {
  1148. const diffRoot = new RootElement( null );
  1149. beforeEach( () => {
  1150. expected = {
  1151. type: RootAttributeOperation,
  1152. key: 'foo',
  1153. oldValue: 'abc',
  1154. newValue: 'bar',
  1155. baseVersion: baseVersion + 1
  1156. };
  1157. op = new RootAttributeOperation( root, 'foo', 'abc', 'bar', baseVersion );
  1158. } );
  1159. describe( 'by InsertOperation', () => {
  1160. it( 'no operation update', () => {
  1161. const transformBy = new InsertOperation(
  1162. new Position( root, [ 0 ] ),
  1163. 'a',
  1164. baseVersion
  1165. );
  1166. const transOp = transform( op, transformBy );
  1167. expect( transOp.length ).to.equal( 1 );
  1168. expectOperation( transOp[ 0 ], expected );
  1169. } );
  1170. } );
  1171. describe( 'by AttributeOperation', () => {
  1172. it( 'no operation update', () => {
  1173. const transformBy = new AttributeOperation(
  1174. new Range(
  1175. new Position( root, [ 0 ] ),
  1176. new Position( root, [ 1 ] )
  1177. ),
  1178. 'foo',
  1179. 'bar',
  1180. 'xyz',
  1181. baseVersion
  1182. );
  1183. const transOp = transform( op, transformBy );
  1184. expect( transOp.length ).to.equal( 1 );
  1185. expectOperation( transOp[ 0 ], expected );
  1186. } );
  1187. } );
  1188. describe( 'by RootAttributeOperation', () => {
  1189. it( 'changes different root: no operation update', () => {
  1190. const transformBy = new RootAttributeOperation(
  1191. diffRoot,
  1192. 'foo',
  1193. 'abc',
  1194. 'xyz',
  1195. baseVersion
  1196. );
  1197. const transOp = transform( op, transformBy );
  1198. expect( transOp.length ).to.equal( 1 );
  1199. expectOperation( transOp[ 0 ], expected );
  1200. } );
  1201. it( 'changes different key: no operation update', () => {
  1202. const transformBy = new RootAttributeOperation(
  1203. root,
  1204. 'abc',
  1205. 'abc',
  1206. 'xyz',
  1207. baseVersion
  1208. );
  1209. const transOp = transform( op, transformBy );
  1210. expect( transOp.length ).to.equal( 1 );
  1211. expectOperation( transOp[ 0 ], expected );
  1212. } );
  1213. it( 'sets same value for same key: convert to NoOperation', () => {
  1214. const transformBy = new RootAttributeOperation(
  1215. root,
  1216. 'foo',
  1217. 'abc',
  1218. 'bar',
  1219. baseVersion
  1220. );
  1221. const transOp = transform( op, transformBy );
  1222. expect( transOp.length ).to.equal( 1 );
  1223. expectOperation( transOp[ 0 ], {
  1224. type: NoOperation,
  1225. baseVersion: baseVersion + 1
  1226. } );
  1227. } );
  1228. it( 'sets different value for same key on same root and is important: no operation update', () => {
  1229. const transformBy = new RootAttributeOperation(
  1230. root,
  1231. 'foo',
  1232. 'abc',
  1233. 'xyz',
  1234. baseVersion
  1235. );
  1236. const transOp = transform( op, transformBy );
  1237. expect( transOp.length ).to.equal( 1 );
  1238. expectOperation( transOp[ 0 ], {
  1239. type: NoOperation,
  1240. baseVersion: baseVersion + 1
  1241. } );
  1242. } );
  1243. it( 'sets different value for same key on same root and is less important: convert to NoOperation', () => {
  1244. const transformBy = new RootAttributeOperation(
  1245. root,
  1246. 'foo',
  1247. 'abc',
  1248. 'xyz',
  1249. baseVersion
  1250. );
  1251. const transOp = transform( op, transformBy, { isStrong: true } );
  1252. expect( transOp.length ).to.equal( 1 );
  1253. expectOperation( transOp[ 0 ], expected );
  1254. } );
  1255. } );
  1256. describe( 'by MoveOperation', () => {
  1257. it( 'no operation update', () => {
  1258. const transformBy = new MoveOperation(
  1259. new Position( root, [ 0 ] ),
  1260. 2,
  1261. new Position( root, [ 1 ] ),
  1262. baseVersion
  1263. );
  1264. const transOp = transform( op, transformBy );
  1265. expect( transOp.length ).to.equal( 1 );
  1266. expectOperation( transOp[ 0 ], expected );
  1267. } );
  1268. } );
  1269. describe( 'by NoOperation', () => {
  1270. it( 'no operation update', () => {
  1271. const transformBy = new NoOperation( baseVersion );
  1272. const transOp = transform( op, transformBy );
  1273. expect( transOp.length ).to.equal( 1 );
  1274. expectOperation( transOp[ 0 ], expected );
  1275. } );
  1276. } );
  1277. describe( 'by RenameOperation', () => {
  1278. it( 'no position update', () => {
  1279. const transformBy = new RenameOperation( new Position( root, [ 0 ] ), 'oldName', 'newName', baseVersion );
  1280. const transOp = transform( op, transformBy );
  1281. expect( transOp.length ).to.equal( 1 );
  1282. expectOperation( transOp[ 0 ], expected );
  1283. } );
  1284. } );
  1285. describe( 'by MarkerOperation', () => {
  1286. it( 'no position update', () => {
  1287. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  1288. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  1289. const transOp = transform( op, transformBy );
  1290. expect( transOp.length ).to.equal( 1 );
  1291. expectOperation( transOp[ 0 ], expected );
  1292. } );
  1293. } );
  1294. } );
  1295. describe( 'MoveOperation', () => {
  1296. let sourcePosition, targetPosition, rangeEnd, howMany;
  1297. beforeEach( () => {
  1298. sourcePosition = new Position( root, [ 2, 2, 4 ] );
  1299. targetPosition = new Position( root, [ 3, 3, 3 ] );
  1300. howMany = 2;
  1301. rangeEnd = Position.createFromPosition( sourcePosition );
  1302. rangeEnd.offset += howMany;
  1303. op = new MoveOperation( sourcePosition, howMany, targetPosition, baseVersion );
  1304. expected = {
  1305. type: MoveOperation,
  1306. sourcePosition: Position.createFromPosition( sourcePosition ),
  1307. targetPosition: Position.createFromPosition( targetPosition ),
  1308. howMany,
  1309. baseVersion: baseVersion + 1
  1310. };
  1311. } );
  1312. describe( 'by InsertOperation', () => {
  1313. it( 'target at different position than move range and target: no operation update', () => {
  1314. const transformBy = new InsertOperation(
  1315. new Position( root, [ 1, 3, 2 ] ),
  1316. [ nodeA, nodeB ],
  1317. baseVersion
  1318. );
  1319. const transOp = transform( op, transformBy );
  1320. expect( transOp.length ).to.equal( 1 );
  1321. expectOperation( transOp[ 0 ], expected );
  1322. } );
  1323. it( 'target inside node from move range: no operation update', () => {
  1324. const transformBy = new InsertOperation(
  1325. new Position( root, [ 2, 2, 4, 1 ] ),
  1326. [ nodeA, nodeB ],
  1327. baseVersion
  1328. );
  1329. const transOp = transform( op, transformBy );
  1330. expect( transOp.length ).to.equal( 1 );
  1331. expectOperation( transOp[ 0 ], expected );
  1332. } );
  1333. it( 'target at offset before range offset: increment range offset', () => {
  1334. const transformBy = new InsertOperation(
  1335. new Position( root, [ 2, 2, 0 ] ),
  1336. [ nodeA, nodeB ],
  1337. baseVersion
  1338. );
  1339. const transOp = transform( op, transformBy );
  1340. expected.sourcePosition.offset += 2;
  1341. expect( transOp.length ).to.equal( 1 );
  1342. expectOperation( transOp[ 0 ], expected );
  1343. } );
  1344. it( 'target at offset after range offset: no operation update', () => {
  1345. const transformBy = new InsertOperation(
  1346. new Position( root, [ 2, 2, 7 ] ),
  1347. [ nodeA, nodeB ],
  1348. baseVersion
  1349. );
  1350. const transOp = transform( op, transformBy );
  1351. expect( transOp.length ).to.equal( 1 );
  1352. expectOperation( transOp[ 0 ], expected );
  1353. } );
  1354. it( 'target before node from range start path: increment index on range start path', () => {
  1355. const transformBy = new InsertOperation(
  1356. new Position( root, [ 2, 0 ] ),
  1357. [ nodeA, nodeB ],
  1358. baseVersion
  1359. );
  1360. const transOp = transform( op, transformBy );
  1361. expected.sourcePosition.path[ 1 ] += 2;
  1362. expect( transOp.length ).to.equal( 1 );
  1363. expectOperation( transOp[ 0 ], expected );
  1364. } );
  1365. it( 'target after node from range start path: no operation update', () => {
  1366. const transformBy = new InsertOperation(
  1367. new Position( root, [ 2, 3 ] ),
  1368. [ nodeA, nodeB ],
  1369. baseVersion
  1370. );
  1371. const transOp = transform( op, transformBy );
  1372. expect( transOp.length ).to.equal( 1 );
  1373. expectOperation( transOp[ 0 ], expected );
  1374. } );
  1375. it( 'target offset before move target offset: increment target offset', () => {
  1376. const transformBy = new InsertOperation(
  1377. new Position( root, [ 3, 3, 2 ] ),
  1378. [ nodeA, nodeB ],
  1379. baseVersion
  1380. );
  1381. const transOp = transform( op, transformBy );
  1382. expected.targetPosition.offset += 2;
  1383. expect( transOp.length ).to.equal( 1 );
  1384. expectOperation( transOp[ 0 ], expected );
  1385. } );
  1386. it( 'target offset after move target offset: no operation update', () => {
  1387. const transformBy = new InsertOperation(
  1388. new Position( root, [ 3, 3, 4 ] ),
  1389. [ nodeA, nodeB ],
  1390. baseVersion
  1391. );
  1392. const transOp = transform( op, transformBy );
  1393. expect( transOp.length ).to.equal( 1 );
  1394. expectOperation( transOp[ 0 ], expected );
  1395. } );
  1396. it( 'target before node from move target position path: increment index on move target position path', () => {
  1397. const transformBy = new InsertOperation(
  1398. new Position( root, [ 3, 3 ] ),
  1399. [ nodeA, nodeB ],
  1400. baseVersion
  1401. );
  1402. const transOp = transform( op, transformBy );
  1403. expected.targetPosition.path[ 1 ] += 2;
  1404. expect( transOp.length ).to.equal( 1 );
  1405. expectOperation( transOp[ 0 ], expected );
  1406. } );
  1407. it( 'target after node from move target position path: no operation update', () => {
  1408. const transformBy = new InsertOperation(
  1409. new Position( root, [ 3, 6 ] ),
  1410. [ nodeA, nodeB ],
  1411. baseVersion
  1412. );
  1413. const transOp = transform( op, transformBy );
  1414. expect( transOp.length ).to.equal( 1 );
  1415. expectOperation( transOp[ 0 ], expected );
  1416. } );
  1417. it( 'target offset same as move target offset and is important: increment target offset', () => {
  1418. const transformBy = new InsertOperation(
  1419. new Position( root, [ 3, 3, 3 ] ),
  1420. [ nodeA, nodeB ],
  1421. baseVersion
  1422. );
  1423. const transOp = transform( op, transformBy );
  1424. expected.targetPosition.offset += 2;
  1425. expect( transOp.length ).to.equal( 1 );
  1426. expectOperation( transOp[ 0 ], expected );
  1427. } );
  1428. it( 'target offset same as move target offset and is less important: no operation update', () => {
  1429. const transformBy = new InsertOperation(
  1430. new Position( root, [ 3, 3, 3 ] ),
  1431. [ nodeA, nodeB ],
  1432. baseVersion
  1433. );
  1434. const transOp = transform( op, transformBy, { isStrong: true } );
  1435. expect( transOp.length ).to.equal( 1 );
  1436. expectOperation( transOp[ 0 ], expected );
  1437. } );
  1438. it( 'target offset same as move target offset and context.insertBefore = true: increment target offset', () => {
  1439. const transformBy = new InsertOperation(
  1440. new Position( root, [ 3, 3, 3 ] ),
  1441. [ nodeA, nodeB ],
  1442. baseVersion
  1443. );
  1444. const transOp = transform( op, transformBy, { isStrong: true, insertBefore: true } );
  1445. expected.targetPosition.offset += 2;
  1446. expect( transOp.length ).to.equal( 1 );
  1447. expectOperation( transOp[ 0 ], expected );
  1448. } );
  1449. it( 'target offset same as move target offset and context.insertBefore = false: no operation update', () => {
  1450. const transformBy = new InsertOperation(
  1451. new Position( root, [ 3, 3, 3 ] ),
  1452. [ nodeA, nodeB ],
  1453. baseVersion
  1454. );
  1455. const transOp = transform( op, transformBy, { isStrong: false, insertBefore: false } );
  1456. expect( transOp.length ).to.equal( 1 );
  1457. expectOperation( transOp[ 0 ], expected );
  1458. } );
  1459. it( 'target inside move range: expand range', () => {
  1460. const transformBy = new InsertOperation(
  1461. new Position( root, [ 2, 2, 5 ] ),
  1462. [ nodeA, nodeB ],
  1463. baseVersion
  1464. );
  1465. const transOp = transform( op, transformBy );
  1466. expect( transOp.length ).to.equal( 1 );
  1467. expected.howMany = 4;
  1468. expectOperation( transOp[ 0 ], expected );
  1469. } );
  1470. it( 'target at offset same as range end boundary: no operation update', () => {
  1471. const transformBy = new InsertOperation(
  1472. new Position( root, [ 2, 2, 6 ] ),
  1473. [ nodeA, nodeB ],
  1474. baseVersion
  1475. );
  1476. const transOp = transform( op, transformBy );
  1477. expect( transOp.length ).to.equal( 1 );
  1478. expectOperation( transOp[ 0 ], expected );
  1479. } );
  1480. it( 'target at offset same as range end boundary (sticky move): expand range', () => {
  1481. const transformBy = new InsertOperation(
  1482. new Position( root, [ 2, 2, 6 ] ),
  1483. [ nodeA, nodeB ],
  1484. baseVersion
  1485. );
  1486. op.isSticky = true;
  1487. const transOp = transform( op, transformBy );
  1488. expected.howMany = 4;
  1489. expect( transOp.length ).to.equal( 1 );
  1490. expectOperation( transOp[ 0 ], expected );
  1491. } );
  1492. } );
  1493. describe( 'by AttributeOperation', () => {
  1494. it( 'no operation update', () => {
  1495. const transformBy = new AttributeOperation(
  1496. new Range( sourcePosition, rangeEnd ),
  1497. 'abc',
  1498. true,
  1499. false,
  1500. baseVersion
  1501. );
  1502. const transOp = transform( op, transformBy );
  1503. expect( transOp.length ).to.equal( 1 );
  1504. expectOperation( transOp[ 0 ], expected );
  1505. } );
  1506. } );
  1507. describe( 'by RootAttributeOperation', () => {
  1508. it( 'no operation update', () => {
  1509. const transformBy = new RootAttributeOperation(
  1510. root,
  1511. 'foo',
  1512. null,
  1513. 'bar',
  1514. baseVersion
  1515. );
  1516. const transOp = transform( op, transformBy );
  1517. expect( transOp.length ).to.equal( 1 );
  1518. expectOperation( transOp[ 0 ], expected );
  1519. } );
  1520. } );
  1521. describe( 'by MoveOperation', () => {
  1522. it( 'range and target different than transforming range and target: no operation update', () => {
  1523. const transformBy = new MoveOperation(
  1524. new Position( root, [ 1, 2 ] ),
  1525. 3,
  1526. new Position( root, [ 4, 1, 0 ] ),
  1527. baseVersion
  1528. );
  1529. const transOp = transform( op, transformBy );
  1530. expect( transOp.length ).to.equal( 1 );
  1531. expectOperation( transOp[ 0 ], expected );
  1532. } );
  1533. it( 'target offset before transforming range start offset: increment range offset', () => {
  1534. const transformBy = new MoveOperation(
  1535. new Position( root, [ 4, 1, 0 ] ),
  1536. 2,
  1537. new Position( root, [ 2, 2, 0 ] ),
  1538. baseVersion
  1539. );
  1540. const transOp = transform( op, transformBy );
  1541. expected.sourcePosition.offset += 2;
  1542. expect( transOp.length ).to.equal( 1 );
  1543. expectOperation( transOp[ 0 ], expected );
  1544. } );
  1545. it( 'target offset after transforming range start offset: no operation update', () => {
  1546. const transformBy = new MoveOperation(
  1547. new Position( root, [ 4, 1, 0 ] ),
  1548. 2,
  1549. new Position( root, [ 2, 2, 7 ] ),
  1550. baseVersion
  1551. );
  1552. const transOp = transform( op, transformBy );
  1553. expect( transOp.length ).to.equal( 1 );
  1554. expectOperation( transOp[ 0 ], expected );
  1555. } );
  1556. it( 'range start offset before transforming range start offset: decrement range offset', () => {
  1557. const transformBy = new MoveOperation(
  1558. new Position( root, [ 2, 2, 0 ] ),
  1559. 2,
  1560. new Position( root, [ 4, 1, 0 ] ),
  1561. baseVersion
  1562. );
  1563. const transOp = transform( op, transformBy );
  1564. expected.sourcePosition.offset -= 2;
  1565. expect( transOp.length ).to.equal( 1 );
  1566. expectOperation( transOp[ 0 ], expected );
  1567. } );
  1568. it( 'range start offset after transforming range start offset: no operation update', () => {
  1569. const transformBy = new MoveOperation(
  1570. new Position( root, [ 2, 2, 9 ] ),
  1571. 2,
  1572. new Position( root, [ 4, 1, 0 ] ),
  1573. baseVersion
  1574. );
  1575. const transOp = transform( op, transformBy, { isStrong: true } );
  1576. expect( transOp.length ).to.equal( 1 );
  1577. expectOperation( transOp[ 0 ], expected );
  1578. } );
  1579. it( 'target before node from transforming range start path: increment index on range start path', () => {
  1580. const transformBy = new MoveOperation(
  1581. new Position( root, [ 4, 1, 0 ] ),
  1582. 2,
  1583. new Position( root, [ 2, 1 ] ),
  1584. baseVersion
  1585. );
  1586. const transOp = transform( op, transformBy );
  1587. expected.sourcePosition.path[ 1 ] += 2;
  1588. expect( transOp.length ).to.equal( 1 );
  1589. expectOperation( transOp[ 0 ], expected );
  1590. } );
  1591. it( 'target after node from transforming range start path: no operation update', () => {
  1592. const transformBy = new MoveOperation(
  1593. new Position( root, [ 4, 1, 0 ] ),
  1594. 2,
  1595. new Position( root, [ 2, 5 ] ),
  1596. baseVersion
  1597. );
  1598. const transOp = transform( op, transformBy );
  1599. expect( transOp.length ).to.equal( 1 );
  1600. expectOperation( transOp[ 0 ], expected );
  1601. } );
  1602. it( 'range before node from transforming range start path: decrement index on range start path', () => {
  1603. const transformBy = new MoveOperation(
  1604. new Position( root, [ 2, 0 ] ),
  1605. 1,
  1606. new Position( root, [ 4, 1, 0 ] ),
  1607. baseVersion
  1608. );
  1609. const transOp = transform( op, transformBy );
  1610. expected.sourcePosition.path[ 1 ] -= 1;
  1611. expect( transOp.length ).to.equal( 1 );
  1612. expectOperation( transOp[ 0 ], expected );
  1613. } );
  1614. it( 'range after node from transforming range start path: no operation update', () => {
  1615. const transformBy = new MoveOperation(
  1616. new Position( root, [ 2, 3 ] ),
  1617. 2,
  1618. new Position( root, [ 4, 1, 0 ] ),
  1619. baseVersion
  1620. );
  1621. const transOp = transform( op, transformBy );
  1622. expect( transOp.length ).to.equal( 1 );
  1623. expectOperation( transOp[ 0 ], expected );
  1624. } );
  1625. it( 'target offset before transforming target offset: increment target offset', () => {
  1626. const transformBy = new MoveOperation(
  1627. new Position( root, [ 4, 1, 0 ] ),
  1628. 2,
  1629. new Position( root, [ 3, 3, 0 ] ),
  1630. baseVersion
  1631. );
  1632. const transOp = transform( op, transformBy );
  1633. expected.targetPosition.offset += 2;
  1634. expect( transOp.length ).to.equal( 1 );
  1635. expectOperation( transOp[ 0 ], expected );
  1636. } );
  1637. it( 'target offset after transforming target offset: no operation update', () => {
  1638. const transformBy = new MoveOperation(
  1639. new Position( root, [ 4, 1, 0 ] ),
  1640. 2,
  1641. new Position( root, [ 3, 3, 5 ] ),
  1642. baseVersion
  1643. );
  1644. const transOp = transform( op, transformBy );
  1645. expect( transOp.length ).to.equal( 1 );
  1646. expectOperation( transOp[ 0 ], expected );
  1647. } );
  1648. it( 'range offset before transforming target offset: decrement target offset', () => {
  1649. const transformBy = new MoveOperation(
  1650. new Position( root, [ 3, 3, 0 ] ),
  1651. 2,
  1652. new Position( root, [ 4, 1, 0 ] ),
  1653. baseVersion
  1654. );
  1655. const transOp = transform( op, transformBy );
  1656. expected.targetPosition.offset -= 2;
  1657. expect( transOp.length ).to.equal( 1 );
  1658. expectOperation( transOp[ 0 ], expected );
  1659. } );
  1660. it( 'range offset after transforming target offset: no operation update', () => {
  1661. const transformBy = new MoveOperation(
  1662. new Position( root, [ 3, 3, 5 ] ),
  1663. 2,
  1664. new Position( root, [ 4, 1, 0 ] ),
  1665. baseVersion
  1666. );
  1667. const transOp = transform( op, transformBy );
  1668. expect( transOp.length ).to.equal( 1 );
  1669. expectOperation( transOp[ 0 ], expected );
  1670. } );
  1671. it( 'target before node from transforming target path: increment index on target path', () => {
  1672. const transformBy = new MoveOperation(
  1673. new Position( root, [ 4, 1, 0 ] ),
  1674. 2,
  1675. new Position( root, [ 3, 1 ] ),
  1676. baseVersion
  1677. );
  1678. const transOp = transform( op, transformBy );
  1679. expected.targetPosition.path[ 1 ] += 2;
  1680. expect( transOp.length ).to.equal( 1 );
  1681. expectOperation( transOp[ 0 ], expected );
  1682. } );
  1683. it( 'target after node from transforming target path: no operation update', () => {
  1684. const transformBy = new MoveOperation(
  1685. new Position( root, [ 4, 1, 0 ] ),
  1686. 2,
  1687. new Position( root, [ 3, 5 ] ),
  1688. baseVersion
  1689. );
  1690. const transOp = transform( op, transformBy );
  1691. expect( transOp.length ).to.equal( 1 );
  1692. expectOperation( transOp[ 0 ], expected );
  1693. } );
  1694. it( 'range before node from transforming target path: decrement index on target path', () => {
  1695. const transformBy = new MoveOperation(
  1696. new Position( root, [ 3, 0 ] ),
  1697. 2,
  1698. new Position( root, [ 4, 1, 0 ] ),
  1699. baseVersion
  1700. );
  1701. const transOp = transform( op, transformBy );
  1702. expected.targetPosition.path[ 1 ] -= 2;
  1703. expect( transOp.length ).to.equal( 1 );
  1704. expectOperation( transOp[ 0 ], expected );
  1705. } );
  1706. it( 'range after node from transforming target path: no operation update', () => {
  1707. const transformBy = new MoveOperation(
  1708. new Position( root, [ 3, 5 ] ),
  1709. 2,
  1710. new Position( root, [ 4, 1, 0 ] ),
  1711. baseVersion
  1712. );
  1713. const transOp = transform( op, transformBy );
  1714. expect( transOp.length ).to.equal( 1 );
  1715. expectOperation( transOp[ 0 ], expected );
  1716. } );
  1717. it( 'target inside transforming move range: expand move range', () => {
  1718. const transformBy = new MoveOperation(
  1719. new Position( root, [ 4, 1, 0 ] ),
  1720. 2,
  1721. new Position( root, [ 2, 2, 5 ] ),
  1722. baseVersion
  1723. );
  1724. const transOp = transform( op, transformBy );
  1725. expect( transOp.length ).to.equal( 1 );
  1726. expected.howMany = 4;
  1727. expectOperation( transOp[ 0 ], expected );
  1728. } );
  1729. it( 'target at start boundary of transforming move range: increment source offset', () => {
  1730. const transformBy = new MoveOperation(
  1731. new Position( root, [ 4, 1, 0 ] ),
  1732. 2,
  1733. new Position( root, [ 2, 2, 4 ] ),
  1734. baseVersion
  1735. );
  1736. const transOp = transform( op, transformBy );
  1737. expect( transOp.length ).to.equal( 1 );
  1738. expected.sourcePosition.offset = 6;
  1739. expectOperation( transOp[ 0 ], expected );
  1740. } );
  1741. it( 'target at start boundary of transforming move range (sticky move): expand move range', () => {
  1742. const transformBy = new MoveOperation(
  1743. new Position( root, [ 4, 1, 0 ] ),
  1744. 2,
  1745. new Position( root, [ 2, 2, 4 ] ),
  1746. baseVersion
  1747. );
  1748. op.isSticky = true;
  1749. const transOp = transform( op, transformBy );
  1750. expect( transOp.length ).to.equal( 1 );
  1751. expected.howMany = 4;
  1752. expectOperation( transOp[ 0 ], expected );
  1753. } );
  1754. it( 'target at end boundary of transforming move range: no operation update', () => {
  1755. const transformBy = new MoveOperation(
  1756. new Position( root, [ 4, 1, 0 ] ),
  1757. 2,
  1758. new Position( root, [ 2, 2, 6 ] ),
  1759. baseVersion
  1760. );
  1761. const transOp = transform( op, transformBy );
  1762. expect( transOp.length ).to.equal( 1 );
  1763. expectOperation( transOp[ 0 ], expected );
  1764. } );
  1765. it( 'target at end boundary of transforming move range (sticky move): expand move range', () => {
  1766. const transformBy = new MoveOperation(
  1767. new Position( root, [ 4, 1, 0 ] ),
  1768. 2,
  1769. new Position( root, [ 2, 2, 6 ] ),
  1770. baseVersion
  1771. );
  1772. op.isSticky = true;
  1773. const transOp = transform( op, transformBy );
  1774. expect( transOp.length ).to.equal( 1 );
  1775. expected.howMany = 4;
  1776. expectOperation( transOp[ 0 ], expected );
  1777. } );
  1778. it( 'target inside a node from transforming range: no operation update', () => {
  1779. const transformBy = new MoveOperation(
  1780. new Position( root, [ 4, 1, 0 ] ),
  1781. 2,
  1782. new Position( root, [ 2, 2, 5, 1 ] ),
  1783. baseVersion
  1784. );
  1785. const transOp = transform( op, transformBy );
  1786. expect( transOp.length ).to.equal( 1 );
  1787. expectOperation( transOp[ 0 ], expected );
  1788. } );
  1789. it( 'range has node that contains transforming range: update range path', () => {
  1790. const transformBy = new MoveOperation(
  1791. new Position( root, [ 2, 1 ] ),
  1792. 3,
  1793. new Position( root, [ 4, 2 ] ),
  1794. baseVersion
  1795. );
  1796. const transOp = transform( op, transformBy );
  1797. expected.sourcePosition.path = [ 4, 3, 4 ];
  1798. expect( transOp.length ).to.equal( 1 );
  1799. expectOperation( transOp[ 0 ], expected );
  1800. } );
  1801. it( 'range has node that contains transforming target: update target path', () => {
  1802. const transformBy = new MoveOperation(
  1803. new Position( root, [ 3, 2 ] ),
  1804. 3,
  1805. new Position( root, [ 0, 1 ] ),
  1806. baseVersion
  1807. );
  1808. const transOp = transform( op, transformBy );
  1809. expected.targetPosition.path = [ 0, 2, 3 ];
  1810. expect( transOp.length ).to.equal( 1 );
  1811. expectOperation( transOp[ 0 ], expected );
  1812. } );
  1813. it( 'target inside a node from transforming range and vice versa: reverse transform-by operation', () => {
  1814. const transformBy = new MoveOperation(
  1815. new Position( root, [ 3, 2 ] ),
  1816. 3,
  1817. new Position( root, [ 2, 2, 5, 0 ] ),
  1818. baseVersion
  1819. );
  1820. const transOp = transform( op, transformBy );
  1821. const reversed = transformBy.getReversed();
  1822. expected.sourcePosition = reversed.sourcePosition;
  1823. expected.targetPosition = reversed.targetPosition;
  1824. expected.howMany = reversed.howMany;
  1825. expect( transOp.length ).to.equal( 1 );
  1826. expectOperation( transOp[ 0 ], expected );
  1827. } );
  1828. it( 'range is same as transforming range and is important: convert to NoOperation', () => {
  1829. const transformBy = new MoveOperation(
  1830. op.sourcePosition,
  1831. op.howMany,
  1832. new Position( root, [ 4, 1, 0 ] ),
  1833. baseVersion
  1834. );
  1835. const transOp = transform( op, transformBy );
  1836. expect( transOp.length ).to.equal( 1 );
  1837. expectOperation( transOp[ 0 ], {
  1838. type: NoOperation,
  1839. baseVersion: baseVersion + 1
  1840. } );
  1841. } );
  1842. it( 'range is same as transforming range and is less important: update range path', () => {
  1843. const transformBy = new MoveOperation(
  1844. op.sourcePosition,
  1845. op.howMany,
  1846. new Position( root, [ 4, 1, 0 ] ),
  1847. baseVersion
  1848. );
  1849. const transOp = transform( op, transformBy, { isStrong: true } );
  1850. expected.sourcePosition.path = [ 4, 1, 0 ];
  1851. expect( transOp.length ).to.equal( 1 );
  1852. expectOperation( transOp[ 0 ], expected );
  1853. } );
  1854. it( 'range contains transforming range and is important: convert to NoOperation', () => {
  1855. const transformBy = new MoveOperation(
  1856. new Position( root, [ 2, 2, 3 ] ),
  1857. 4,
  1858. new Position( root, [ 4, 1, 0 ] ),
  1859. baseVersion
  1860. );
  1861. const transOp = transform( op, transformBy );
  1862. expect( transOp.length ).to.equal( 1 );
  1863. expectOperation( transOp[ 0 ], {
  1864. type: NoOperation,
  1865. baseVersion: baseVersion + 1
  1866. } );
  1867. } );
  1868. it( 'range contains transforming range and is less important: update range path', () => {
  1869. const transformBy = new MoveOperation(
  1870. new Position( root, [ 2, 2, 3 ] ),
  1871. 4,
  1872. new Position( root, [ 4, 1, 0 ] ),
  1873. baseVersion
  1874. );
  1875. const transOp = transform( op, transformBy, { isStrong: true } );
  1876. expected.sourcePosition.path = [ 4, 1, 1 ];
  1877. expect( transOp.length ).to.equal( 1 );
  1878. expectOperation( transOp[ 0 ], expected );
  1879. } );
  1880. it( 'range contains transforming range and target and is important: update range path and target', () => {
  1881. op.targetPosition.path = [ 2, 2, 7 ];
  1882. const transformBy = new MoveOperation(
  1883. new Position( root, [ 2, 2, 3 ] ),
  1884. 5,
  1885. new Position( root, [ 4, 1, 0 ] ),
  1886. baseVersion
  1887. );
  1888. const transOp = transform( op, transformBy );
  1889. expect( transOp.length ).to.equal( 1 );
  1890. expected.sourcePosition.path = [ 4, 1, 1 ];
  1891. expected.targetPosition.path = [ 4, 1, 4 ];
  1892. expectOperation( transOp[ 0 ], expected );
  1893. } );
  1894. it( 'range contains transforming range and target and is less important: update range path and target', () => {
  1895. op.targetPosition.path = [ 2, 2, 7 ];
  1896. const transformBy = new MoveOperation(
  1897. new Position( root, [ 2, 2, 3 ] ),
  1898. 5,
  1899. new Position( root, [ 4, 1, 0 ] ),
  1900. baseVersion
  1901. );
  1902. const transOp = transform( op, transformBy, { isStrong: true } );
  1903. expect( transOp.length ).to.equal( 1 );
  1904. expected.sourcePosition.path = [ 4, 1, 1 ];
  1905. expected.targetPosition.path = [ 4, 1, 4 ];
  1906. expectOperation( transOp[ 0 ], expected );
  1907. } );
  1908. it( 'range intersects on left side of transforming range and is important: shrink range', () => {
  1909. const transformBy = new MoveOperation(
  1910. new Position( root, [ 2, 2, 3 ] ),
  1911. 2,
  1912. new Position( root, [ 4, 1, 0 ] ),
  1913. baseVersion
  1914. );
  1915. const transOp = transform( op, transformBy );
  1916. expected.sourcePosition.path = [ 2, 2, 3 ];
  1917. expected.howMany = 1;
  1918. expect( transOp.length ).to.equal( 1 );
  1919. expectOperation( transOp[ 0 ], expected );
  1920. } );
  1921. it( 'range intersects on left side of transforming range and is less important: split into two operations', () => {
  1922. // Get more test cases and better code coverage
  1923. const otherRoot = new RootElement( null );
  1924. const transformBy = new MoveOperation(
  1925. new Position( root, [ 2, 2, 3 ] ),
  1926. 2,
  1927. new Position( otherRoot, [ 4, 1, 0 ] ),
  1928. baseVersion
  1929. );
  1930. const transOp = transform( op, transformBy, { isStrong: true } );
  1931. expect( transOp.length ).to.equal( 2 );
  1932. expected.sourcePosition.path = [ 2, 2, 3 ];
  1933. expected.howMany = 1;
  1934. expectOperation( transOp[ 0 ], expected );
  1935. expected.sourcePosition = new Position( otherRoot, [ 4, 1, 1 ] );
  1936. expected.baseVersion++;
  1937. expectOperation( transOp[ 1 ], expected );
  1938. } );
  1939. it( 'range intersects on right side of transforming range and is important: shrink range', () => {
  1940. const transformBy = new MoveOperation(
  1941. new Position( root, [ 2, 2, 5 ] ),
  1942. 2,
  1943. new Position( root, [ 4, 1, 0 ] ),
  1944. baseVersion
  1945. );
  1946. const transOp = transform( op, transformBy );
  1947. expected.howMany = 1;
  1948. expect( transOp.length ).to.equal( 1 );
  1949. expectOperation( transOp[ 0 ], expected );
  1950. } );
  1951. it( 'range intersects on right side of transforming range and is less important: split into two operations', () => {
  1952. const transformBy = new MoveOperation(
  1953. new Position( root, [ 2, 2, 5 ] ),
  1954. 2,
  1955. new Position( root, [ 4, 1, 0 ] ),
  1956. baseVersion
  1957. );
  1958. const transOp = transform( op, transformBy, { isStrong: true } );
  1959. expect( transOp.length ).to.equal( 2 );
  1960. expected.sourcePosition.path = [ 4, 1, 0 ];
  1961. expected.howMany = 1;
  1962. expectOperation( transOp[ 0 ], expected );
  1963. expected.sourcePosition.path = op.sourcePosition.path;
  1964. expected.baseVersion++;
  1965. expectOperation( transOp[ 1 ], expected );
  1966. } );
  1967. it( 'range intersects on left side, target inside transforming range and is important: expand move range', () => {
  1968. op.howMany = 4;
  1969. const transformBy = new MoveOperation(
  1970. new Position( root, [ 2, 2, 3 ] ),
  1971. 2,
  1972. new Position( root, [ 2, 2, 6 ] ),
  1973. baseVersion
  1974. );
  1975. const transOp = transform( op, transformBy );
  1976. expect( transOp.length ).to.equal( 1 );
  1977. expected.sourcePosition.path = [ 2, 2, 3 ];
  1978. expected.howMany = 5;
  1979. expectOperation( transOp[ 0 ], expected );
  1980. } );
  1981. it( 'range intersects on left side, target inside transforming range and is less important: expand move range', () => {
  1982. op.howMany = 4;
  1983. const transformBy = new MoveOperation(
  1984. new Position( root, [ 2, 2, 3 ] ),
  1985. 2,
  1986. new Position( root, [ 2, 2, 6 ] ),
  1987. baseVersion
  1988. );
  1989. const transOp = transform( op, transformBy, { isStrong: true } );
  1990. expect( transOp.length ).to.equal( 1 );
  1991. expected.sourcePosition.path = [ 2, 2, 3 ];
  1992. expected.howMany = 5;
  1993. expectOperation( transOp[ 0 ], expected );
  1994. } );
  1995. it( 'range intersects on right side of transforming range and is important: shrink range', () => {
  1996. const transformBy = new MoveOperation(
  1997. new Position( root, [ 2, 2, 5 ] ),
  1998. 2,
  1999. new Position( root, [ 4, 1, 0 ] ),
  2000. baseVersion
  2001. );
  2002. const transOp = transform( op, transformBy );
  2003. expected.howMany = 1;
  2004. expect( transOp.length ).to.equal( 1 );
  2005. expectOperation( transOp[ 0 ], expected );
  2006. } );
  2007. it( 'range intersects on right side of transforming range and is less important: split into two operations', () => {
  2008. const transformBy = new MoveOperation(
  2009. new Position( root, [ 2, 2, 5 ] ),
  2010. 2,
  2011. new Position( root, [ 4, 1, 0 ] ),
  2012. baseVersion
  2013. );
  2014. const transOp = transform( op, transformBy, { isStrong: true } );
  2015. expect( transOp.length ).to.equal( 2 );
  2016. expected.sourcePosition.path = [ 4, 1, 0 ];
  2017. expected.howMany = 1;
  2018. expectOperation( transOp[ 0 ], expected );
  2019. expected.sourcePosition.path = op.sourcePosition.path;
  2020. expected.baseVersion++;
  2021. expectOperation( transOp[ 1 ], expected );
  2022. } );
  2023. it( 'range intersects, target inside transforming range and is important: split into two operations', () => {
  2024. op.targetPosition.path = [ 2, 2, 7 ];
  2025. const transformBy = new MoveOperation(
  2026. new Position( root, [ 2, 2, 5 ] ),
  2027. 4,
  2028. new Position( root, [ 4, 1, 0 ] ),
  2029. baseVersion
  2030. );
  2031. const transOp = transform( op, transformBy, { isStrong: true } );
  2032. expect( transOp.length ).to.equal( 2 );
  2033. expected.sourcePosition.path = [ 4, 1, 0 ];
  2034. expected.targetPosition.path = [ 4, 1, 2 ];
  2035. expected.howMany = 1;
  2036. expectOperation( transOp[ 0 ], expected );
  2037. expected.sourcePosition.path = [ 2, 2, 4 ];
  2038. expected.targetPosition.path = [ 4, 1, 2 ];
  2039. expected.howMany = 1;
  2040. expected.baseVersion++;
  2041. expectOperation( transOp[ 1 ], expected );
  2042. } );
  2043. it( 'range intersects, target inside transforming range and is less important: shrink range', () => {
  2044. op.targetPosition.path = [ 2, 2, 7 ];
  2045. const transformBy = new MoveOperation(
  2046. new Position( root, [ 2, 2, 5 ] ),
  2047. 4,
  2048. new Position( root, [ 4, 1, 0 ] ),
  2049. baseVersion
  2050. );
  2051. const transOp = transform( op, transformBy );
  2052. expect( transOp.length ).to.equal( 1 );
  2053. expected.sourcePosition.path = [ 2, 2, 4 ];
  2054. expected.targetPosition.path = [ 4, 1, 2 ];
  2055. expected.howMany = 1;
  2056. expectOperation( transOp[ 0 ], expected );
  2057. } );
  2058. it( 'range inside transforming range and is important: shrink range', () => {
  2059. op.howMany = 4;
  2060. const transformBy = new MoveOperation(
  2061. new Position( root, [ 2, 2, 5 ] ),
  2062. 2,
  2063. new Position( root, [ 4, 1, 0 ] ),
  2064. baseVersion
  2065. );
  2066. const transOp = transform( op, transformBy );
  2067. expect( transOp.length ).to.equal( 1 );
  2068. expected.howMany = 2;
  2069. expectOperation( transOp[ 0 ], expected );
  2070. } );
  2071. it( 'range inside transforming range and is less important: split into two operations', () => {
  2072. op.howMany = 4;
  2073. const transformBy = new MoveOperation(
  2074. new Position( root, [ 2, 2, 5 ] ),
  2075. 2,
  2076. new Position( root, [ 4, 1, 0 ] ),
  2077. baseVersion
  2078. );
  2079. const transOp = transform( op, transformBy, { isStrong: true } );
  2080. expect( transOp.length ).to.equal( 2 );
  2081. expected.sourcePosition.path = [ 4, 1, 0 ];
  2082. expected.howMany = 2;
  2083. expectOperation( transOp[ 0 ], expected );
  2084. expected.sourcePosition.path = [ 2, 2, 4 ];
  2085. expected.howMany = 2;
  2086. expected.baseVersion++;
  2087. expectOperation( transOp[ 1 ], expected );
  2088. } );
  2089. it( 'range and target inside transforming range and is important: no operation update', () => {
  2090. op.howMany = 6;
  2091. const transformBy = new MoveOperation(
  2092. new Position( root, [ 2, 2, 5 ] ),
  2093. 2,
  2094. new Position( root, [ 2, 2, 9 ] ),
  2095. baseVersion
  2096. );
  2097. const transOp = transform( op, transformBy );
  2098. expect( transOp.length ).to.equal( 1 );
  2099. expected.howMany = 6;
  2100. expectOperation( transOp[ 0 ], expected );
  2101. } );
  2102. it( 'range and target inside transforming range and is less important: no operation update', () => {
  2103. op.howMany = 6;
  2104. const transformBy = new MoveOperation(
  2105. new Position( root, [ 2, 2, 5 ] ),
  2106. 2,
  2107. new Position( root, [ 2, 2, 9 ] ),
  2108. baseVersion
  2109. );
  2110. const transOp = transform( op, transformBy, { isStrong: true } );
  2111. expect( transOp.length ).to.equal( 1 );
  2112. expected.howMany = 6;
  2113. expectOperation( transOp[ 0 ], expected );
  2114. } );
  2115. } );
  2116. describe( 'by RemoveOperation', () => {
  2117. let transformBy;
  2118. beforeEach( () => {
  2119. transformBy = new RemoveOperation(
  2120. Position.createFromPosition( op.sourcePosition ),
  2121. op.howMany,
  2122. new Position( doc.graveyard, [ 0 ] ),
  2123. baseVersion
  2124. );
  2125. } );
  2126. it( 'should skip context.isStrong and be less important than RemoveOperation', () => {
  2127. const transOp = transform( op, transformBy, { isStrong: true } );
  2128. expect( transOp.length ).to.equal( 1 );
  2129. expectOperation( transOp[ 0 ], {
  2130. type: NoOperation,
  2131. baseVersion: baseVersion + 1
  2132. } );
  2133. } );
  2134. it( 'should use context.isStrong if forceWeakRemove flag is used', () => {
  2135. const transOp = transform( op, transformBy, { isStrong: true, forceWeakRemove: true } );
  2136. expect( transOp.length ).to.equal( 1 );
  2137. expected.sourcePosition = transformBy.targetPosition;
  2138. expectOperation( transOp[ 0 ], expected );
  2139. } );
  2140. it( 'should skip context.isStrong and be less important if RemoveOperation is permanent', () => {
  2141. transformBy.isPermanent = true;
  2142. const transOp = transform( op, transformBy, { isStrong: true, forceWeakRemove: true } );
  2143. expect( transOp.length ).to.equal( 1 );
  2144. expectOperation( transOp[ 0 ], {
  2145. type: NoOperation,
  2146. baseVersion: baseVersion + 1
  2147. } );
  2148. } );
  2149. } );
  2150. describe( 'by NoOperation', () => {
  2151. it( 'no operation update', () => {
  2152. const transformBy = new NoOperation( baseVersion );
  2153. const transOp = transform( op, transformBy );
  2154. expect( transOp.length ).to.equal( 1 );
  2155. expectOperation( transOp[ 0 ], expected );
  2156. } );
  2157. } );
  2158. describe( 'by RenameOperation', () => {
  2159. it( 'no position update', () => {
  2160. const transformBy = new RenameOperation( new Position( root, [ 2, 2, 4 ] ), 'oldName', 'newName', baseVersion );
  2161. const transOp = transform( op, transformBy );
  2162. expect( transOp.length ).to.equal( 1 );
  2163. expectOperation( transOp[ 0 ], expected );
  2164. } );
  2165. } );
  2166. describe( 'by MarkerOperation', () => {
  2167. it( 'no position update', () => {
  2168. const newRange = new Range( new Position( root, [ 2, 2, 3 ] ), new Position( root, [ 2, 2, 8 ] ) );
  2169. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  2170. const transOp = transform( op, transformBy );
  2171. expect( transOp.length ).to.equal( 1 );
  2172. expectOperation( transOp[ 0 ], expected );
  2173. } );
  2174. } );
  2175. } );
  2176. describe( 'RemoveOperation', () => {
  2177. describe( 'by MoveOperation', () => {
  2178. it( 'should force removing content even if was less important', () => {
  2179. const op = new RemoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), baseVersion );
  2180. const targetPosition = Position.createFromPosition( op.targetPosition );
  2181. const transformBy = new MoveOperation( new Position( root, [ 8 ] ), 2, new Position( root, [ 1 ] ), baseVersion );
  2182. const sourcePosition = Position.createFromPosition( transformBy.targetPosition );
  2183. const transOp = transform( op, transformBy );
  2184. expect( transOp.length ).to.equal( 1 );
  2185. expectOperation( transOp[ 0 ], {
  2186. type: RemoveOperation,
  2187. howMany: 2,
  2188. sourcePosition,
  2189. targetPosition,
  2190. baseVersion: baseVersion + 1
  2191. } );
  2192. } );
  2193. } );
  2194. describe( 'by RemoveOperation', () => {
  2195. it( 'should use isPermanent flag even if both operations are remove operations', () => {
  2196. const op = new RemoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), baseVersion );
  2197. const transformBy = op.clone();
  2198. transformBy.isPermanent = true;
  2199. // `context.isStrong` will not be considered, because `transformBy` is permanent.
  2200. const transOp = transform( op, transformBy, { isStrong: true } );
  2201. expect( transOp.length ).to.equal( 1 );
  2202. expectOperation( transOp[ 0 ], {
  2203. type: NoOperation,
  2204. baseVersion: baseVersion + 1
  2205. } );
  2206. } );
  2207. } );
  2208. } );
  2209. describe( 'NoOperation', () => {
  2210. beforeEach( () => {
  2211. op = new NoOperation( baseVersion );
  2212. expected = {
  2213. type: NoOperation,
  2214. baseVersion: baseVersion + 1
  2215. };
  2216. } );
  2217. describe( 'by InsertOperation', () => {
  2218. it( 'no operation update', () => {
  2219. const transformBy = new InsertOperation(
  2220. new Position( root, [ 0 ] ),
  2221. 'a',
  2222. baseVersion
  2223. );
  2224. const transOp = transform( op, transformBy );
  2225. expect( transOp.length ).to.equal( 1 );
  2226. expectOperation( transOp[ 0 ], expected );
  2227. } );
  2228. } );
  2229. describe( 'by AttributeOperation', () => {
  2230. it( 'no operation update', () => {
  2231. const transformBy = new AttributeOperation(
  2232. new Range(
  2233. new Position( root, [ 0 ] ),
  2234. new Position( root, [ 1 ] )
  2235. ),
  2236. 'foo',
  2237. 'bar',
  2238. 'xyz',
  2239. baseVersion
  2240. );
  2241. const transOp = transform( op, transformBy );
  2242. expect( transOp.length ).to.equal( 1 );
  2243. expectOperation( transOp[ 0 ], expected );
  2244. } );
  2245. } );
  2246. describe( 'by RootAttributeOperation', () => {
  2247. it( 'no operation update', () => {
  2248. const transformBy = new RootAttributeOperation(
  2249. root,
  2250. 'foo',
  2251. null,
  2252. 'bar',
  2253. baseVersion
  2254. );
  2255. const transOp = transform( op, transformBy );
  2256. expect( transOp.length ).to.equal( 1 );
  2257. expectOperation( transOp[ 0 ], expected );
  2258. } );
  2259. } );
  2260. describe( 'by MoveOperation', () => {
  2261. it( 'no operation update', () => {
  2262. const transformBy = new MoveOperation(
  2263. new Position( root, [ 0 ] ),
  2264. 2,
  2265. new Position( root, [ 1 ] ),
  2266. baseVersion
  2267. );
  2268. const transOp = transform( op, transformBy );
  2269. expect( transOp.length ).to.equal( 1 );
  2270. expectOperation( transOp[ 0 ], expected );
  2271. } );
  2272. } );
  2273. describe( 'by NoOperation', () => {
  2274. it( 'no operation update', () => {
  2275. const transformBy = new NoOperation( baseVersion );
  2276. const transOp = transform( op, transformBy );
  2277. expect( transOp.length ).to.equal( 1 );
  2278. expectOperation( transOp[ 0 ], expected );
  2279. } );
  2280. } );
  2281. describe( 'by RenameOperation', () => {
  2282. it( 'no position update', () => {
  2283. const transformBy = new RenameOperation( new Position( root, [ 0, 2, 0 ] ), 'oldName', 'newName', baseVersion );
  2284. const transOp = transform( op, transformBy );
  2285. expect( transOp.length ).to.equal( 1 );
  2286. expectOperation( transOp[ 0 ], expected );
  2287. } );
  2288. } );
  2289. describe( 'by MarkerOperation', () => {
  2290. it( 'no position update', () => {
  2291. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  2292. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  2293. const transOp = transform( op, transformBy );
  2294. expect( transOp.length ).to.equal( 1 );
  2295. expectOperation( transOp[ 0 ], expected );
  2296. } );
  2297. } );
  2298. } );
  2299. describe( 'RenameOperation', () => {
  2300. beforeEach( () => {
  2301. const position = new Position( root, [ 0, 2, 2 ] );
  2302. op = new RenameOperation( position, 'oldName', 'newName', baseVersion );
  2303. expected = {
  2304. position,
  2305. oldName: 'oldName',
  2306. newName: 'newName',
  2307. baseVersion: baseVersion + 1
  2308. };
  2309. } );
  2310. describe( 'by InsertOperation', () => {
  2311. it( 'target before renamed element: offset update', () => {
  2312. const transformBy = new InsertOperation(
  2313. new Position( root, [ 0, 2, 1 ] ),
  2314. [ nodeA, nodeB ],
  2315. baseVersion
  2316. );
  2317. const transOp = transform( op, transformBy );
  2318. expect( transOp.length ).to.equal( 1 );
  2319. expected.position.offset = 4;
  2320. expectOperation( transOp[ 0 ], expected );
  2321. } );
  2322. it( 'target after renamed element: no change', () => {
  2323. const transformBy = new InsertOperation(
  2324. new Position( root, [ 0, 2, 3 ] ),
  2325. [ nodeA, nodeB ],
  2326. baseVersion
  2327. );
  2328. const transOp = transform( op, transformBy );
  2329. expect( transOp.length ).to.equal( 1 );
  2330. expectOperation( transOp[ 0 ], expected );
  2331. } );
  2332. it( 'target before a node on path to renamed element: path update', () => {
  2333. const transformBy = new InsertOperation(
  2334. new Position( root, [ 0, 1 ] ),
  2335. [ nodeA, nodeB ],
  2336. baseVersion
  2337. );
  2338. const transOp = transform( op, transformBy );
  2339. expect( transOp.length ).to.equal( 1 );
  2340. expected.position.path = [ 0, 4, 2 ];
  2341. expectOperation( transOp[ 0 ], expected );
  2342. } );
  2343. it( 'target after a node on path to renamed element: no change', () => {
  2344. const transformBy = new InsertOperation(
  2345. new Position( root, [ 0, 3 ] ),
  2346. [ nodeA, nodeB ],
  2347. baseVersion
  2348. );
  2349. const transOp = transform( op, transformBy );
  2350. expect( transOp.length ).to.equal( 1 );
  2351. expectOperation( transOp[ 0 ], expected );
  2352. } );
  2353. } );
  2354. describe( 'by AttributeOperation', () => {
  2355. it( 'no operation update', () => {
  2356. const transformBy = new AttributeOperation(
  2357. new Range(
  2358. new Position( root, [ 0, 2, 1 ] ),
  2359. new Position( root, [ 1, 3 ] )
  2360. ),
  2361. 'foo',
  2362. 'bar',
  2363. 'xyz',
  2364. baseVersion
  2365. );
  2366. const transOp = transform( op, transformBy );
  2367. expect( transOp.length ).to.equal( 1 );
  2368. expectOperation( transOp[ 0 ], expected );
  2369. } );
  2370. } );
  2371. describe( 'by RootAttributeOperation', () => {
  2372. it( 'no operation update', () => {
  2373. const transformBy = new RootAttributeOperation(
  2374. root,
  2375. 'foo',
  2376. null,
  2377. 'bar',
  2378. baseVersion
  2379. );
  2380. const transOp = transform( op, transformBy );
  2381. expect( transOp.length ).to.equal( 1 );
  2382. expectOperation( transOp[ 0 ], expected );
  2383. } );
  2384. } );
  2385. describe( 'by MarkerOperation', () => {
  2386. it( 'no operation update', () => {
  2387. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  2388. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  2389. const transOp = transform( op, transformBy );
  2390. expect( transOp.length ).to.equal( 1 );
  2391. expectOperation( transOp[ 0 ], expected );
  2392. } );
  2393. } );
  2394. describe( 'by RenameOperation', () => {
  2395. it( 'different element: no change', () => {
  2396. const transformBy = new RenameOperation(
  2397. new Position( root, [ 0, 2, 1 ] ),
  2398. 'foo',
  2399. 'bar',
  2400. baseVersion
  2401. );
  2402. const transOp = transform( op, transformBy );
  2403. expect( transOp.length ).to.equal( 1 );
  2404. expectOperation( transOp[ 0 ], expected );
  2405. } );
  2406. it( 'same element and is important: convert to NoOperation', () => {
  2407. const transformBy = new RenameOperation(
  2408. new Position( root, [ 0, 2, 2 ] ),
  2409. 'oldName',
  2410. 'otherName',
  2411. baseVersion
  2412. );
  2413. const transOp = transform( op, transformBy );
  2414. expect( transOp.length ).to.equal( 1 );
  2415. expectOperation( transOp[ 0 ], {
  2416. type: NoOperation,
  2417. baseVersion: baseVersion + 1
  2418. } );
  2419. } );
  2420. it( 'same element and is not important: change old name to new name', () => {
  2421. const transformBy = new RenameOperation(
  2422. new Position( root, [ 0, 2, 2 ] ),
  2423. 'oldName',
  2424. 'otherName',
  2425. baseVersion
  2426. );
  2427. const transOp = transform( op, transformBy, { isStrong: true } );
  2428. expect( transOp.length ).to.equal( 1 );
  2429. expected.oldName = 'otherName';
  2430. expectOperation( transOp[ 0 ], expected );
  2431. } );
  2432. } );
  2433. describe( 'by MoveOperation', () => {
  2434. it( 'moved range before renamed element: update offset', () => {
  2435. const transformBy = new MoveOperation(
  2436. new Position( root, [ 0, 2, 0 ] ),
  2437. 2,
  2438. new Position( root, [ 2, 5 ] ),
  2439. baseVersion
  2440. );
  2441. const transOp = transform( op, transformBy );
  2442. expect( transOp.length ).to.equal( 1 );
  2443. expected.position.offset = 0;
  2444. expectOperation( transOp[ 0 ], expected );
  2445. } );
  2446. it( 'moved range before an element on path to renamed element: update path', () => {
  2447. const transformBy = new MoveOperation(
  2448. new Position( root, [ 0, 0 ] ),
  2449. 2,
  2450. new Position( root, [ 2, 5 ] ),
  2451. baseVersion
  2452. );
  2453. const transOp = transform( op, transformBy );
  2454. expect( transOp.length ).to.equal( 1 );
  2455. expected.position.path = [ 0, 0, 2 ];
  2456. expectOperation( transOp[ 0 ], expected );
  2457. } );
  2458. it( 'moved range contains renamed element: update path', () => {
  2459. const transformBy = new MoveOperation(
  2460. new Position( root, [ 0, 2, 1 ] ),
  2461. 3,
  2462. new Position( root, [ 2, 5 ] ),
  2463. baseVersion
  2464. );
  2465. const transOp = transform( op, transformBy );
  2466. expect( transOp.length ).to.equal( 1 );
  2467. expected.position.path = [ 2, 6 ];
  2468. expectOperation( transOp[ 0 ], expected );
  2469. } );
  2470. it( 'moved range contains renamed element parent: updated path', () => {
  2471. const transformBy = new MoveOperation(
  2472. new Position( root, [ 0, 1 ] ),
  2473. 3,
  2474. new Position( root, [ 2, 5 ] ),
  2475. baseVersion
  2476. );
  2477. const transOp = transform( op, transformBy );
  2478. expect( transOp.length ).to.equal( 1 );
  2479. expected.position.path = [ 2, 6, 2 ];
  2480. expectOperation( transOp[ 0 ], expected );
  2481. } );
  2482. it( 'move target before renamed element: update offset', () => {
  2483. const transformBy = new MoveOperation(
  2484. new Position( root, [ 2, 5 ] ),
  2485. 2,
  2486. new Position( root, [ 0, 2, 1 ] ),
  2487. baseVersion
  2488. );
  2489. const transOp = transform( op, transformBy );
  2490. expect( transOp.length ).to.equal( 1 );
  2491. expected.position.offset = 4;
  2492. expectOperation( transOp[ 0 ], expected );
  2493. } );
  2494. it( 'move target before an element on path to renamed element: update path', () => {
  2495. const transformBy = new MoveOperation(
  2496. new Position( root, [ 0, 2, 0 ] ),
  2497. 2,
  2498. new Position( root, [ 2, 5 ] ),
  2499. baseVersion
  2500. );
  2501. const transOp = transform( op, transformBy );
  2502. expect( transOp.length ).to.equal( 1 );
  2503. expected.position.offset = 0;
  2504. expectOperation( transOp[ 0 ], expected );
  2505. } );
  2506. } );
  2507. } );
  2508. describe( 'MarkerOperation', () => {
  2509. let oldRange, newRange;
  2510. beforeEach( () => {
  2511. oldRange = Range.createFromParentsAndOffsets( root, 1, root, 4 );
  2512. newRange = Range.createFromParentsAndOffsets( root, 10, root, 12 );
  2513. op = new MarkerOperation( 'name', oldRange, newRange, doc.markers, baseVersion );
  2514. expected = {
  2515. name: 'name',
  2516. oldRange,
  2517. newRange,
  2518. baseVersion: baseVersion + 1
  2519. };
  2520. } );
  2521. describe( 'by InsertOperation', () => {
  2522. it( 'insert position affecting oldRange: update oldRange', () => {
  2523. // Just CC things.
  2524. op.newRange = null;
  2525. const transformBy = new InsertOperation( Position.createAt( root, 0 ), [ nodeA, nodeB ], baseVersion );
  2526. const transOp = transform( op, transformBy );
  2527. expected.newRange = null;
  2528. expected.oldRange.start.offset = 3;
  2529. expected.oldRange.end.offset = 6;
  2530. expect( transOp.length ).to.equal( 1 );
  2531. expectOperation( transOp[ 0 ], expected );
  2532. } );
  2533. it( 'insert position affecting newRange: update newRange', () => {
  2534. // Just CC things.
  2535. op.oldRange = null;
  2536. const transformBy = new InsertOperation( Position.createAt( root, 8 ), [ nodeA, nodeB ], baseVersion );
  2537. const transOp = transform( op, transformBy );
  2538. expected.oldRange = null;
  2539. expected.newRange.start.offset = 12;
  2540. expected.newRange.end.offset = 14;
  2541. expect( transOp.length ).to.equal( 1 );
  2542. expectOperation( transOp[ 0 ], expected );
  2543. } );
  2544. } );
  2545. describe( 'by AttributeOperation', () => {
  2546. it( 'no operation update', () => {
  2547. const transformBy = new AttributeOperation(
  2548. new Range(
  2549. new Position( root, [ 2 ] ),
  2550. new Position( root, [ 11 ] )
  2551. ),
  2552. 'foo',
  2553. 'bar',
  2554. 'xyz',
  2555. baseVersion
  2556. );
  2557. const transOp = transform( op, transformBy );
  2558. expect( transOp.length ).to.equal( 1 );
  2559. expectOperation( transOp[ 0 ], expected );
  2560. } );
  2561. } );
  2562. describe( 'by MoveOperation', () => {
  2563. it( 'moved range is before oldRange: update oldRange', () => {
  2564. // Just CC things.
  2565. op.newRange = null;
  2566. const transformBy = new MoveOperation( Position.createAt( root, 0 ), 1, Position.createAt( root, 20 ), baseVersion );
  2567. const transOp = transform( op, transformBy );
  2568. expected.newRange = null;
  2569. expected.oldRange.start.offset = 0;
  2570. expected.oldRange.end.offset = 3;
  2571. expect( transOp.length ).to.equal( 1 );
  2572. expectOperation( transOp[ 0 ], expected );
  2573. } );
  2574. it( 'moved range contains oldRange and is before newRange: update oldRange and newRange', () => {
  2575. const transformBy = new MoveOperation( Position.createAt( root, 2 ), 2, Position.createAt( root, 20 ), baseVersion );
  2576. const transOp = transform( op, transformBy );
  2577. expected.oldRange.start.offset = 1;
  2578. expected.oldRange.end.offset = 2;
  2579. expected.newRange.start.offset = 8;
  2580. expected.newRange.end.offset = 10;
  2581. expect( transOp.length ).to.equal( 1 );
  2582. expectOperation( transOp[ 0 ], expected );
  2583. } );
  2584. it( 'target position is inside newRange: update newRange', () => {
  2585. // Just CC things.
  2586. op.oldRange = null;
  2587. const transformBy = new MoveOperation( Position.createAt( root, 20 ), 2, Position.createAt( root, 11 ), baseVersion );
  2588. const transOp = transform( op, transformBy );
  2589. expected.oldRange = null;
  2590. expected.newRange.start.offset = 10;
  2591. expected.newRange.end.offset = 14;
  2592. expect( transOp.length ).to.equal( 1 );
  2593. expectOperation( transOp[ 0 ], expected );
  2594. } );
  2595. it( 'target position is inside oldRange and before newRange: update oldRange and newRange', () => {
  2596. const transformBy = new MoveOperation( Position.createAt( root, 20 ), 4, Position.createAt( root, 2 ), baseVersion );
  2597. const transOp = transform( op, transformBy );
  2598. expected.oldRange.start.offset = 1;
  2599. expected.oldRange.end.offset = 8;
  2600. expected.newRange.start.offset = 14;
  2601. expected.newRange.end.offset = 16;
  2602. expect( transOp.length ).to.equal( 1 );
  2603. expectOperation( transOp[ 0 ], expected );
  2604. } );
  2605. } );
  2606. describe( 'by RootAttributeOperation', () => {
  2607. it( 'no operation update', () => {
  2608. const transformBy = new RootAttributeOperation(
  2609. root,
  2610. 'foo',
  2611. null,
  2612. 'bar',
  2613. baseVersion
  2614. );
  2615. const transOp = transform( op, transformBy );
  2616. expect( transOp.length ).to.equal( 1 );
  2617. expectOperation( transOp[ 0 ], expected );
  2618. } );
  2619. } );
  2620. describe( 'by RenameOperation', () => {
  2621. it( 'no operation update', () => {
  2622. const transformBy = new RenameOperation( new Position( root, [ 1 ] ), 'oldName', 'newName', baseVersion );
  2623. const transOp = transform( op, transformBy );
  2624. expect( transOp.length ).to.equal( 1 );
  2625. expectOperation( transOp[ 0 ], expected );
  2626. } );
  2627. } );
  2628. describe( 'by MarkerOperation', () => {
  2629. it( 'different marker name: no operation update', () => {
  2630. const transformBy = new MarkerOperation( 'otherName', oldRange, newRange, doc.markers, baseVersion );
  2631. const transOp = transform( op, transformBy );
  2632. expect( transOp.length ).to.equal( 1 );
  2633. expectOperation( transOp[ 0 ], expected );
  2634. } );
  2635. it( 'same marker name and is important: convert to NoOperation', () => {
  2636. const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
  2637. const transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
  2638. const transOp = transform( op, transformBy );
  2639. expect( transOp.length ).to.equal( 1 );
  2640. expectOperation( transOp[ 0 ], {
  2641. type: NoOperation,
  2642. baseVersion: baseVersion + 1
  2643. } );
  2644. } );
  2645. it( 'same marker name and is less important: update oldRange parameter', () => {
  2646. const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
  2647. const transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
  2648. const transOp = transform( op, transformBy, { isStrong: true } );
  2649. expected.oldRange = anotherRange;
  2650. expect( transOp.length ).to.equal( 1 );
  2651. expectOperation( transOp[ 0 ], expected );
  2652. } );
  2653. } );
  2654. } );
  2655. } );