import { strict as assert } from "assert" ; import { Container } from "@fluidframework/container-loader" ; import { requestFluidObject } from "@fluidframework/runtime-utils" ; import { SharedString } from "@fluidframework/sequence" ; import { ITestObjectProvider , ITestContainerConfig , DataObjectFactoryType , ChannelFactoryRegistry , ITestFluidObject , } from "@fluidframework/test-utils" ; import { describeFullCompat } from "@fluidframework/test-version-utils" ; const stringId = "sharedStringKey" ; const registry = [ [ stringId , SharedString . getFactory ( ) ] ] ; const testContainerConfig = { fluidDataObjectType : DataObjectFactoryType . Test , registry } ; describeFullCompat ( "SharedString" , ( getTestObjectProvider ) => { let provider ; beforeEach ( ( ) => { provider = getTestObjectProvider ( ) ; } ) ; let sharedString1 ; let sharedString2 ; beforeEach ( async ( ) => { const container1 = await provider . makeTestContainer ( testContainerConfig ) as Container ; const dataObject1 = await requestFluidObject < ITestFluidObject > ( container1 , "default" ) ; sharedString1 = await dataObject1 . getSharedObject < SharedString > ( stringId ) ; const container2 = await provider . loadTestContainer ( testContainerConfig ) as Container ; const dataObject2 = await requestFluidObject < ITestFluidObject > ( container2 , "default" ) ; sharedString2 = await dataObject2 . getSharedObject < SharedString > ( stringId ) ; } ) ; it ( "can sync SharedString across multiple containers" , async ( ) => { const text = "syncSharedString" ; sharedString1 . insertText ( 0 , text ) ; assert . equal ( sharedString1 . getText ( ) , text , "The retrieved text should match the inserted text." ) ; await provider . ensureSynchronized ( ) ; assert . equal ( sharedString2 . getText ( ) , text , "The inserted text should have synced across the containers" ) ; } ) ; it ( "can sync SharedString to a newly loaded container" , async ( ) => { const text = "syncToNewContainer" ; sharedString1 . insertText ( 0 , text ) ; assert . equal ( sharedString1 . getText ( ) , text , "The retrieved text should match the inserted text." ) ; await provider . ensureSynchronized ( ) ; const newContainer = await provider . loadTestContainer ( testContainerConfig ) as Container ; const newComponent = await requestFluidObject < ITestFluidObject > ( newContainer , "default" ) ; const newSharedString = await newComponent . getSharedObject < SharedString > ( stringId ) ; assert . equal ( newSharedString . getText ( ) , text , "The new container should receive the inserted text on creation" ) ; } ) ; } ) ;