import { strict as assert } from "assert" ; import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions" ; import { LocalClientId , UnassignedSequenceNumber , UniversalSequenceNumber } from "../constants" ; import { MergeTree } from "../mergeTree" ; import { MergeTreeMaintenanceType } from "../mergeTreeDeltaCallback" ; import { MergeTreeDeltaType } from "../ops" ; import { TextSegment } from "../textSegment" ; import { countOperations } from "./testUtils" ; describe ( "MergeTree" , ( ) => { let mergeTree ; const localClientId = 17 ; let currentSequenceNumber ; beforeEach ( ( ) => { mergeTree = new MergeTree ( ) ; mergeTree . insertSegments ( 0 , [ TextSegment . make ( "hello world!" ) ] , UniversalSequenceNumber , LocalClientId , UniversalSequenceNumber , undefined ) ; currentSequenceNumber = 0 ; mergeTree . startCollaboration ( localClientId , currentSequenceNumber , currentSequenceNumber ) ; } ) ; describe ( "markRangeRemoved" , ( ) => { it ( "Event on Removal" , ( ) => { const count = countOperations ( mergeTree ) ; mergeTree . markRangeRemoved ( 4 , 6 , currentSequenceNumber , localClientId , UnassignedSequenceNumber , false , undefined ) ; assert . deepStrictEqual ( count , { [ MergeTreeDeltaType . REMOVE ] : 1 , [ MergeTreeMaintenanceType . SPLIT ] : 2 } ) ; } ) ; it ( "Event on Unlink" , ( ) => { const count = countOperations ( mergeTree ) ; const start = 4 ; const end = 6 ; mergeTree . markRangeRemoved ( start , end , currentSequenceNumber , localClientId , UnassignedSequenceNumber , false , undefined ) ; mergeTree . ackPendingSegment ( { op : { pos1 : start , pos2 : end , type : MergeTreeDeltaType . REMOVE } , sequencedMessage : { sequenceNumber : ++ currentSequenceNumber } as ISequencedDocumentMessage } ) ; mergeTree . getCollabWindow ( ) . currentSeq = currentSequenceNumber ; mergeTree . setMinSeq ( currentSequenceNumber ) ; assert . deepStrictEqual ( count , { [ MergeTreeDeltaType . REMOVE ] : 1 , [ MergeTreeMaintenanceType . SPLIT ] : 2 , [ MergeTreeMaintenanceType . UNLINK ] : 1 , [ MergeTreeMaintenanceType . ACKNOWLEDGED ] : 1 } ) ; } ) ; it ( "Remote Before Local" , ( ) => { const remoteClientId = 35 ; let remoteSequenceNumber = currentSequenceNumber ; mergeTree . markRangeRemoved ( 4 , 6 , remoteSequenceNumber , remoteClientId , ++ remoteSequenceNumber , false , undefined ) ; const count = countOperations ( mergeTree ) ; mergeTree . markRangeRemoved ( 3 , 5 , currentSequenceNumber , localClientId , UnassignedSequenceNumber , false , undefined ) ; assert . deepStrictEqual ( count , { [ MergeTreeDeltaType . REMOVE ] : 1 , [ MergeTreeMaintenanceType . SPLIT ] : 2 } ) ; } ) ; it ( "Local Before Remote" , ( ) => { const remoteClientId = 35 ; let remoteSequenceNumber = currentSequenceNumber ; mergeTree . markRangeRemoved ( 4 , 6 , currentSequenceNumber , localClientId , UnassignedSequenceNumber , false , undefined ) ; const count = countOperations ( mergeTree ) ; mergeTree . markRangeRemoved ( 3 , 5 , remoteSequenceNumber , remoteClientId , ++ remoteSequenceNumber , false , undefined ) ; assert . deepStrictEqual ( count , { [ MergeTreeDeltaType . REMOVE ] : 1 , [ MergeTreeMaintenanceType . SPLIT ] : 2 } ) ; } ) ; } ) ; } ) ;