transform.js 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483
  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: split into two operations', () => {
  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( 2 );
  2068. expected.howMany = 1;
  2069. expected.sourcePosition.path = [ 2, 2, 5 ];
  2070. expectOperation( transOp[ 0 ], expected );
  2071. expected.howMany = 1;
  2072. expected.sourcePosition.path = [ 2, 2, 4 ];
  2073. expected.baseVersion++;
  2074. expectOperation( transOp[ 1 ], expected );
  2075. } );
  2076. it( 'range inside transforming range and is less important: split into three operations', () => {
  2077. op.howMany = 4;
  2078. const transformBy = new MoveOperation(
  2079. new Position( root, [ 2, 2, 5 ] ),
  2080. 2,
  2081. new Position( root, [ 4, 1, 0 ] ),
  2082. baseVersion
  2083. );
  2084. const transOp = transform( op, transformBy, { isStrong: true } );
  2085. expect( transOp.length ).to.equal( 3 );
  2086. expected.sourcePosition.path = [ 2, 2, 5 ];
  2087. expected.howMany = 1;
  2088. expectOperation( transOp[ 0 ], expected );
  2089. expected.sourcePosition.path = [ 4, 1, 0 ];
  2090. expected.howMany = 2;
  2091. expected.baseVersion++;
  2092. expectOperation( transOp[ 1 ], expected );
  2093. expected.sourcePosition.path = [ 2, 2, 4 ];
  2094. expected.howMany = 1;
  2095. expected.baseVersion++;
  2096. expectOperation( transOp[ 2 ], expected );
  2097. } );
  2098. it( 'range and target inside transforming range and is important: no operation update', () => {
  2099. op.howMany = 6;
  2100. const transformBy = new MoveOperation(
  2101. new Position( root, [ 2, 2, 5 ] ),
  2102. 2,
  2103. new Position( root, [ 2, 2, 9 ] ),
  2104. baseVersion
  2105. );
  2106. const transOp = transform( op, transformBy );
  2107. expect( transOp.length ).to.equal( 1 );
  2108. expected.howMany = 6;
  2109. expectOperation( transOp[ 0 ], expected );
  2110. } );
  2111. it( 'range and target inside transforming range and is less important: no operation update', () => {
  2112. op.howMany = 6;
  2113. const transformBy = new MoveOperation(
  2114. new Position( root, [ 2, 2, 5 ] ),
  2115. 2,
  2116. new Position( root, [ 2, 2, 9 ] ),
  2117. baseVersion
  2118. );
  2119. const transOp = transform( op, transformBy, { isStrong: true } );
  2120. expect( transOp.length ).to.equal( 1 );
  2121. expected.howMany = 6;
  2122. expectOperation( transOp[ 0 ], expected );
  2123. } );
  2124. } );
  2125. describe( 'by RemoveOperation', () => {
  2126. let transformBy;
  2127. beforeEach( () => {
  2128. transformBy = new RemoveOperation(
  2129. Position.createFromPosition( op.sourcePosition ),
  2130. op.howMany,
  2131. new Position( doc.graveyard, [ 0 ] ),
  2132. baseVersion
  2133. );
  2134. } );
  2135. it( 'should skip context.isStrong and be less important than RemoveOperation', () => {
  2136. const transOp = transform( op, transformBy, { isStrong: true } );
  2137. expect( transOp.length ).to.equal( 1 );
  2138. expectOperation( transOp[ 0 ], {
  2139. type: NoOperation,
  2140. baseVersion: baseVersion + 1
  2141. } );
  2142. } );
  2143. it( 'should use context.isStrong if forceWeakRemove flag is used', () => {
  2144. const transOp = transform( op, transformBy, { isStrong: true, forceWeakRemove: true } );
  2145. expect( transOp.length ).to.equal( 1 );
  2146. expected.sourcePosition = transformBy.targetPosition;
  2147. expectOperation( transOp[ 0 ], expected );
  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. } );
  2195. describe( 'NoOperation', () => {
  2196. beforeEach( () => {
  2197. op = new NoOperation( baseVersion );
  2198. expected = {
  2199. type: NoOperation,
  2200. baseVersion: baseVersion + 1
  2201. };
  2202. } );
  2203. describe( 'by InsertOperation', () => {
  2204. it( 'no operation update', () => {
  2205. const transformBy = new InsertOperation(
  2206. new Position( root, [ 0 ] ),
  2207. 'a',
  2208. baseVersion
  2209. );
  2210. const transOp = transform( op, transformBy );
  2211. expect( transOp.length ).to.equal( 1 );
  2212. expectOperation( transOp[ 0 ], expected );
  2213. } );
  2214. } );
  2215. describe( 'by AttributeOperation', () => {
  2216. it( 'no operation update', () => {
  2217. const transformBy = new AttributeOperation(
  2218. new Range(
  2219. new Position( root, [ 0 ] ),
  2220. new Position( root, [ 1 ] )
  2221. ),
  2222. 'foo',
  2223. 'bar',
  2224. 'xyz',
  2225. baseVersion
  2226. );
  2227. const transOp = transform( op, transformBy );
  2228. expect( transOp.length ).to.equal( 1 );
  2229. expectOperation( transOp[ 0 ], expected );
  2230. } );
  2231. } );
  2232. describe( 'by RootAttributeOperation', () => {
  2233. it( 'no operation update', () => {
  2234. const transformBy = new RootAttributeOperation(
  2235. root,
  2236. 'foo',
  2237. null,
  2238. 'bar',
  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 MoveOperation', () => {
  2247. it( 'no operation update', () => {
  2248. const transformBy = new MoveOperation(
  2249. new Position( root, [ 0 ] ),
  2250. 2,
  2251. new Position( root, [ 1 ] ),
  2252. baseVersion
  2253. );
  2254. const transOp = transform( op, transformBy );
  2255. expect( transOp.length ).to.equal( 1 );
  2256. expectOperation( transOp[ 0 ], expected );
  2257. } );
  2258. } );
  2259. describe( 'by NoOperation', () => {
  2260. it( 'no operation update', () => {
  2261. const transformBy = new NoOperation( baseVersion );
  2262. const transOp = transform( op, transformBy );
  2263. expect( transOp.length ).to.equal( 1 );
  2264. expectOperation( transOp[ 0 ], expected );
  2265. } );
  2266. } );
  2267. describe( 'by RenameOperation', () => {
  2268. it( 'no position update', () => {
  2269. const transformBy = new RenameOperation( new Position( root, [ 0, 2, 0 ] ), 'oldName', 'newName', baseVersion );
  2270. const transOp = transform( op, transformBy );
  2271. expect( transOp.length ).to.equal( 1 );
  2272. expectOperation( transOp[ 0 ], expected );
  2273. } );
  2274. } );
  2275. describe( 'by MarkerOperation', () => {
  2276. it( 'no position update', () => {
  2277. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  2278. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  2279. const transOp = transform( op, transformBy );
  2280. expect( transOp.length ).to.equal( 1 );
  2281. expectOperation( transOp[ 0 ], expected );
  2282. } );
  2283. } );
  2284. } );
  2285. describe( 'RenameOperation', () => {
  2286. beforeEach( () => {
  2287. const position = new Position( root, [ 0, 2, 2 ] );
  2288. op = new RenameOperation( position, 'oldName', 'newName', baseVersion );
  2289. expected = {
  2290. position,
  2291. oldName: 'oldName',
  2292. newName: 'newName',
  2293. baseVersion: baseVersion + 1
  2294. };
  2295. } );
  2296. describe( 'by InsertOperation', () => {
  2297. it( 'target before renamed element: offset update', () => {
  2298. const transformBy = new InsertOperation(
  2299. new Position( root, [ 0, 2, 1 ] ),
  2300. [ nodeA, nodeB ],
  2301. baseVersion
  2302. );
  2303. const transOp = transform( op, transformBy );
  2304. expect( transOp.length ).to.equal( 1 );
  2305. expected.position.offset = 4;
  2306. expectOperation( transOp[ 0 ], expected );
  2307. } );
  2308. it( 'target after renamed element: no change', () => {
  2309. const transformBy = new InsertOperation(
  2310. new Position( root, [ 0, 2, 3 ] ),
  2311. [ nodeA, nodeB ],
  2312. baseVersion
  2313. );
  2314. const transOp = transform( op, transformBy );
  2315. expect( transOp.length ).to.equal( 1 );
  2316. expectOperation( transOp[ 0 ], expected );
  2317. } );
  2318. it( 'target before a node on path to renamed element: path update', () => {
  2319. const transformBy = new InsertOperation(
  2320. new Position( root, [ 0, 1 ] ),
  2321. [ nodeA, nodeB ],
  2322. baseVersion
  2323. );
  2324. const transOp = transform( op, transformBy );
  2325. expect( transOp.length ).to.equal( 1 );
  2326. expected.position.path = [ 0, 4, 2 ];
  2327. expectOperation( transOp[ 0 ], expected );
  2328. } );
  2329. it( 'target after a node on path to renamed element: no change', () => {
  2330. const transformBy = new InsertOperation(
  2331. new Position( root, [ 0, 3 ] ),
  2332. [ nodeA, nodeB ],
  2333. baseVersion
  2334. );
  2335. const transOp = transform( op, transformBy );
  2336. expect( transOp.length ).to.equal( 1 );
  2337. expectOperation( transOp[ 0 ], expected );
  2338. } );
  2339. } );
  2340. describe( 'by AttributeOperation', () => {
  2341. it( 'no operation update', () => {
  2342. const transformBy = new AttributeOperation(
  2343. new Range(
  2344. new Position( root, [ 0, 2, 1 ] ),
  2345. new Position( root, [ 1, 3 ] )
  2346. ),
  2347. 'foo',
  2348. 'bar',
  2349. 'xyz',
  2350. baseVersion
  2351. );
  2352. const transOp = transform( op, transformBy );
  2353. expect( transOp.length ).to.equal( 1 );
  2354. expectOperation( transOp[ 0 ], expected );
  2355. } );
  2356. } );
  2357. describe( 'by RootAttributeOperation', () => {
  2358. it( 'no operation update', () => {
  2359. const transformBy = new RootAttributeOperation(
  2360. root,
  2361. 'foo',
  2362. null,
  2363. 'bar',
  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 MarkerOperation', () => {
  2372. it( 'no operation update', () => {
  2373. const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
  2374. const transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
  2375. const transOp = transform( op, transformBy );
  2376. expect( transOp.length ).to.equal( 1 );
  2377. expectOperation( transOp[ 0 ], expected );
  2378. } );
  2379. } );
  2380. describe( 'by RenameOperation', () => {
  2381. it( 'different element: no change', () => {
  2382. const transformBy = new RenameOperation(
  2383. new Position( root, [ 0, 2, 1 ] ),
  2384. 'foo',
  2385. 'bar',
  2386. baseVersion
  2387. );
  2388. const transOp = transform( op, transformBy );
  2389. expect( transOp.length ).to.equal( 1 );
  2390. expectOperation( transOp[ 0 ], expected );
  2391. } );
  2392. it( 'same element and is important: convert to NoOperation', () => {
  2393. const transformBy = new RenameOperation(
  2394. new Position( root, [ 0, 2, 2 ] ),
  2395. 'oldName',
  2396. 'otherName',
  2397. baseVersion
  2398. );
  2399. const transOp = transform( op, transformBy );
  2400. expect( transOp.length ).to.equal( 1 );
  2401. expectOperation( transOp[ 0 ], {
  2402. type: NoOperation,
  2403. baseVersion: baseVersion + 1
  2404. } );
  2405. } );
  2406. it( 'same element and is not important: change old name to new name', () => {
  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, { isStrong: true } );
  2414. expect( transOp.length ).to.equal( 1 );
  2415. expected.oldName = 'otherName';
  2416. expectOperation( transOp[ 0 ], expected );
  2417. } );
  2418. } );
  2419. describe( 'by MoveOperation', () => {
  2420. it( 'moved range before renamed element: update offset', () => {
  2421. const transformBy = new MoveOperation(
  2422. new Position( root, [ 0, 2, 0 ] ),
  2423. 2,
  2424. new Position( root, [ 2, 5 ] ),
  2425. baseVersion
  2426. );
  2427. const transOp = transform( op, transformBy );
  2428. expect( transOp.length ).to.equal( 1 );
  2429. expected.position.offset = 0;
  2430. expectOperation( transOp[ 0 ], expected );
  2431. } );
  2432. it( 'moved range before an element on path to renamed element: update path', () => {
  2433. const transformBy = new MoveOperation(
  2434. new Position( root, [ 0, 0 ] ),
  2435. 2,
  2436. new Position( root, [ 2, 5 ] ),
  2437. baseVersion
  2438. );
  2439. const transOp = transform( op, transformBy );
  2440. expect( transOp.length ).to.equal( 1 );
  2441. expected.position.path = [ 0, 0, 2 ];
  2442. expectOperation( transOp[ 0 ], expected );
  2443. } );
  2444. it( 'moved range contains renamed element: update path', () => {
  2445. const transformBy = new MoveOperation(
  2446. new Position( root, [ 0, 2, 1 ] ),
  2447. 3,
  2448. new Position( root, [ 2, 5 ] ),
  2449. baseVersion
  2450. );
  2451. const transOp = transform( op, transformBy );
  2452. expect( transOp.length ).to.equal( 1 );
  2453. expected.position.path = [ 2, 6 ];
  2454. expectOperation( transOp[ 0 ], expected );
  2455. } );
  2456. it( 'moved range contains renamed element parent: updated path', () => {
  2457. const transformBy = new MoveOperation(
  2458. new Position( root, [ 0, 1 ] ),
  2459. 3,
  2460. new Position( root, [ 2, 5 ] ),
  2461. baseVersion
  2462. );
  2463. const transOp = transform( op, transformBy );
  2464. expect( transOp.length ).to.equal( 1 );
  2465. expected.position.path = [ 2, 6, 2 ];
  2466. expectOperation( transOp[ 0 ], expected );
  2467. } );
  2468. it( 'move target before renamed element: update offset', () => {
  2469. const transformBy = new MoveOperation(
  2470. new Position( root, [ 2, 5 ] ),
  2471. 2,
  2472. new Position( root, [ 0, 2, 1 ] ),
  2473. baseVersion
  2474. );
  2475. const transOp = transform( op, transformBy );
  2476. expect( transOp.length ).to.equal( 1 );
  2477. expected.position.offset = 4;
  2478. expectOperation( transOp[ 0 ], expected );
  2479. } );
  2480. it( 'move target before an element on path to renamed element: update path', () => {
  2481. const transformBy = new MoveOperation(
  2482. new Position( root, [ 0, 2, 0 ] ),
  2483. 2,
  2484. new Position( root, [ 2, 5 ] ),
  2485. baseVersion
  2486. );
  2487. const transOp = transform( op, transformBy );
  2488. expect( transOp.length ).to.equal( 1 );
  2489. expected.position.offset = 0;
  2490. expectOperation( transOp[ 0 ], expected );
  2491. } );
  2492. } );
  2493. } );
  2494. describe( 'MarkerOperation', () => {
  2495. let oldRange, newRange;
  2496. beforeEach( () => {
  2497. oldRange = Range.createFromParentsAndOffsets( root, 1, root, 4 );
  2498. newRange = Range.createFromParentsAndOffsets( root, 10, root, 12 );
  2499. op = new MarkerOperation( 'name', oldRange, newRange, doc.markers, baseVersion );
  2500. expected = {
  2501. name: 'name',
  2502. oldRange,
  2503. newRange,
  2504. baseVersion: baseVersion + 1
  2505. };
  2506. } );
  2507. describe( 'by InsertOperation', () => {
  2508. it( 'insert position affecting oldRange: update oldRange', () => {
  2509. // Just CC things.
  2510. op.newRange = null;
  2511. const transformBy = new InsertOperation( Position.createAt( root, 0 ), [ nodeA, nodeB ], baseVersion );
  2512. const transOp = transform( op, transformBy );
  2513. expected.newRange = null;
  2514. expected.oldRange.start.offset = 3;
  2515. expected.oldRange.end.offset = 6;
  2516. expect( transOp.length ).to.equal( 1 );
  2517. expectOperation( transOp[ 0 ], expected );
  2518. } );
  2519. it( 'insert position affecting newRange: update newRange', () => {
  2520. // Just CC things.
  2521. op.oldRange = null;
  2522. const transformBy = new InsertOperation( Position.createAt( root, 8 ), [ nodeA, nodeB ], baseVersion );
  2523. const transOp = transform( op, transformBy );
  2524. expected.oldRange = null;
  2525. expected.newRange.start.offset = 12;
  2526. expected.newRange.end.offset = 14;
  2527. expect( transOp.length ).to.equal( 1 );
  2528. expectOperation( transOp[ 0 ], expected );
  2529. } );
  2530. } );
  2531. describe( 'by AttributeOperation', () => {
  2532. it( 'no operation update', () => {
  2533. const transformBy = new AttributeOperation(
  2534. new Range(
  2535. new Position( root, [ 2 ] ),
  2536. new Position( root, [ 11 ] )
  2537. ),
  2538. 'foo',
  2539. 'bar',
  2540. 'xyz',
  2541. baseVersion
  2542. );
  2543. const transOp = transform( op, transformBy );
  2544. expect( transOp.length ).to.equal( 1 );
  2545. expectOperation( transOp[ 0 ], expected );
  2546. } );
  2547. } );
  2548. describe( 'by MoveOperation', () => {
  2549. it( 'moved range is before oldRange: update oldRange', () => {
  2550. // Just CC things.
  2551. op.newRange = null;
  2552. const transformBy = new MoveOperation( Position.createAt( root, 0 ), 1, Position.createAt( root, 20 ), baseVersion );
  2553. const transOp = transform( op, transformBy );
  2554. expected.newRange = null;
  2555. expected.oldRange.start.offset = 0;
  2556. expected.oldRange.end.offset = 3;
  2557. expect( transOp.length ).to.equal( 1 );
  2558. expectOperation( transOp[ 0 ], expected );
  2559. } );
  2560. it( 'moved range contains oldRange and is before newRange: update oldRange and newRange', () => {
  2561. const transformBy = new MoveOperation( Position.createAt( root, 2 ), 2, Position.createAt( root, 20 ), baseVersion );
  2562. const transOp = transform( op, transformBy );
  2563. expected.oldRange.start.offset = 1;
  2564. expected.oldRange.end.offset = 2;
  2565. expected.newRange.start.offset = 8;
  2566. expected.newRange.end.offset = 10;
  2567. expect( transOp.length ).to.equal( 1 );
  2568. expectOperation( transOp[ 0 ], expected );
  2569. } );
  2570. it( 'target position is inside newRange: update newRange', () => {
  2571. // Just CC things.
  2572. op.oldRange = null;
  2573. const transformBy = new MoveOperation( Position.createAt( root, 20 ), 2, Position.createAt( root, 11 ), baseVersion );
  2574. const transOp = transform( op, transformBy );
  2575. expected.oldRange = null;
  2576. expected.newRange.start.offset = 10;
  2577. expected.newRange.end.offset = 14;
  2578. expect( transOp.length ).to.equal( 1 );
  2579. expectOperation( transOp[ 0 ], expected );
  2580. } );
  2581. it( 'target position is inside oldRange and before newRange: update oldRange and newRange', () => {
  2582. const transformBy = new MoveOperation( Position.createAt( root, 20 ), 4, Position.createAt( root, 2 ), baseVersion );
  2583. const transOp = transform( op, transformBy );
  2584. expected.oldRange.start.offset = 1;
  2585. expected.oldRange.end.offset = 8;
  2586. expected.newRange.start.offset = 14;
  2587. expected.newRange.end.offset = 16;
  2588. expect( transOp.length ).to.equal( 1 );
  2589. expectOperation( transOp[ 0 ], expected );
  2590. } );
  2591. } );
  2592. describe( 'by RootAttributeOperation', () => {
  2593. it( 'no operation update', () => {
  2594. const transformBy = new RootAttributeOperation(
  2595. root,
  2596. 'foo',
  2597. null,
  2598. 'bar',
  2599. baseVersion
  2600. );
  2601. const transOp = transform( op, transformBy );
  2602. expect( transOp.length ).to.equal( 1 );
  2603. expectOperation( transOp[ 0 ], expected );
  2604. } );
  2605. } );
  2606. describe( 'by RenameOperation', () => {
  2607. it( 'no operation update', () => {
  2608. const transformBy = new RenameOperation( new Position( root, [ 1 ] ), 'oldName', 'newName', baseVersion );
  2609. const transOp = transform( op, transformBy );
  2610. expect( transOp.length ).to.equal( 1 );
  2611. expectOperation( transOp[ 0 ], expected );
  2612. } );
  2613. } );
  2614. describe( 'by MarkerOperation', () => {
  2615. it( 'different marker name: no operation update', () => {
  2616. const transformBy = new MarkerOperation( 'otherName', oldRange, newRange, doc.markers, baseVersion );
  2617. const transOp = transform( op, transformBy );
  2618. expect( transOp.length ).to.equal( 1 );
  2619. expectOperation( transOp[ 0 ], expected );
  2620. } );
  2621. it( 'same marker name and is important: convert to NoOperation', () => {
  2622. const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
  2623. const transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
  2624. const transOp = transform( op, transformBy );
  2625. expect( transOp.length ).to.equal( 1 );
  2626. expectOperation( transOp[ 0 ], {
  2627. type: NoOperation,
  2628. baseVersion: baseVersion + 1
  2629. } );
  2630. } );
  2631. it( 'same marker name and is less important: update oldRange parameter', () => {
  2632. const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
  2633. const transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
  2634. const transOp = transform( op, transformBy, { isStrong: true } );
  2635. expected.oldRange = anotherRange;
  2636. expect( transOp.length ).to.equal( 1 );
  2637. expectOperation( transOp[ 0 ], expected );
  2638. } );
  2639. } );
  2640. } );
  2641. } );