@fluidframework/sequence 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/api-report/sequence.api.md +32 -32
- package/beta.d.ts +11 -0
- package/dist/{localValues.d.ts → IntervalCollectionValues.d.ts} +13 -12
- package/dist/IntervalCollectionValues.d.ts.map +1 -0
- package/dist/{localValues.js → IntervalCollectionValues.js} +6 -6
- package/dist/IntervalCollectionValues.js.map +1 -0
- package/dist/beta.d.ts +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/intervalCollection.d.ts +10 -10
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +103 -99
- package/dist/intervalCollection.js.map +1 -1
- package/dist/{defaultMap.d.ts → intervalCollectionMap.d.ts} +11 -44
- package/dist/intervalCollectionMap.d.ts.map +1 -0
- package/dist/{defaultMap.js → intervalCollectionMap.js} +15 -70
- package/dist/intervalCollectionMap.js.map +1 -0
- package/dist/{defaultMapInterfaces.d.ts → intervalCollectionMapInterfaces.d.ts} +17 -16
- package/dist/intervalCollectionMapInterfaces.d.ts.map +1 -0
- package/dist/{defaultMapInterfaces.js → intervalCollectionMapInterfaces.js} +1 -1
- package/dist/intervalCollectionMapInterfaces.js.map +1 -0
- package/dist/intervalIndex/endpointInRangeIndex.d.ts +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.js +3 -3
- package/dist/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/dist/intervalIndex/endpointIndex.d.ts +1 -1
- package/dist/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointIndex.js +3 -3
- package/dist/intervalIndex/endpointIndex.js.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.js +3 -3
- package/dist/intervalIndex/idIntervalIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +3 -3
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.js +2 -3
- package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js +6 -6
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.d.ts +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.js +3 -3
- package/dist/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/dist/intervalTree.d.ts +1 -1
- package/dist/intervalTree.d.ts.map +1 -1
- package/dist/intervalTree.js +2 -2
- package/dist/intervalTree.js.map +1 -1
- package/dist/intervals/interval.d.ts +1 -1
- package/dist/intervals/interval.d.ts.map +1 -1
- package/dist/intervals/interval.js +10 -10
- package/dist/intervals/interval.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +1 -1
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js +5 -5
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +1 -1
- package/dist/intervals/sequenceInterval.d.ts.map +1 -1
- package/dist/intervals/sequenceInterval.js +34 -34
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/legacy.d.ts +61 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +12 -0
- package/dist/revertibles.d.ts +2 -2
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +34 -34
- package/dist/revertibles.js.map +1 -1
- package/dist/sequence.d.ts +7 -6
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +34 -34
- package/dist/sequence.js.map +1 -1
- package/dist/sequenceDeltaEvent.d.ts +1 -1
- package/dist/sequenceDeltaEvent.d.ts.map +1 -1
- package/dist/sequenceDeltaEvent.js +4 -4
- package/dist/sequenceDeltaEvent.js.map +1 -1
- package/dist/sequenceFactory.d.ts +1 -1
- package/dist/sequenceFactory.d.ts.map +1 -1
- package/dist/sequenceFactory.js +3 -3
- package/dist/sequenceFactory.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts +4 -3
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/sharedIntervalCollection.js +5 -5
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedSequence.d.ts +3 -2
- package/dist/sharedSequence.d.ts.map +1 -1
- package/dist/sharedSequence.js +4 -4
- package/dist/sharedSequence.js.map +1 -1
- package/dist/sharedString.d.ts +2 -2
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +9 -9
- package/dist/sharedString.js.map +1 -1
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/{localValues.d.ts → IntervalCollectionValues.d.ts} +13 -12
- package/lib/IntervalCollectionValues.d.ts.map +1 -0
- package/lib/{localValues.js → IntervalCollectionValues.js} +3 -3
- package/lib/IntervalCollectionValues.js.map +1 -0
- package/lib/beta.d.ts +12 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/intervalCollection.d.ts +10 -10
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +8 -4
- package/lib/intervalCollection.js.map +1 -1
- package/lib/{defaultMap.d.ts → intervalCollectionMap.d.ts} +11 -44
- package/lib/intervalCollectionMap.d.ts.map +1 -0
- package/lib/{defaultMap.js → intervalCollectionMap.js} +8 -63
- package/lib/intervalCollectionMap.js.map +1 -0
- package/lib/{defaultMapInterfaces.d.ts → intervalCollectionMapInterfaces.d.ts} +17 -16
- package/lib/intervalCollectionMapInterfaces.d.ts.map +1 -0
- package/lib/{defaultMapInterfaces.js → intervalCollectionMapInterfaces.js} +1 -1
- package/lib/intervalCollectionMapInterfaces.js.map +1 -0
- package/lib/intervalIndex/endpointInRangeIndex.d.ts +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/lib/intervalIndex/endpointIndex.d.ts +1 -1
- package/lib/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointIndex.js +1 -1
- package/lib/intervalIndex/endpointIndex.js.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.js +1 -1
- package/lib/intervalIndex/idIntervalIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +3 -3
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +2 -3
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +2 -2
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.d.ts +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/lib/intervalTree.d.ts +1 -1
- package/lib/intervalTree.d.ts.map +1 -1
- package/lib/intervalTree.js +1 -1
- package/lib/intervalTree.js.map +1 -1
- package/lib/intervals/interval.d.ts +1 -1
- package/lib/intervals/interval.d.ts.map +1 -1
- package/lib/intervals/interval.js +3 -3
- package/lib/intervals/interval.js.map +1 -1
- package/lib/intervals/intervalUtils.d.ts +1 -1
- package/lib/intervals/intervalUtils.d.ts.map +1 -1
- package/lib/intervals/intervalUtils.js +1 -1
- package/lib/intervals/intervalUtils.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +1 -1
- package/lib/intervals/sequenceInterval.d.ts.map +1 -1
- package/lib/intervals/sequenceInterval.js +3 -3
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/legacy.d.ts +61 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +12 -0
- package/lib/revertibles.d.ts +2 -2
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +3 -4
- package/lib/revertibles.js.map +1 -1
- package/lib/sequence.d.ts +7 -6
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +11 -12
- package/lib/sequence.js.map +1 -1
- package/lib/sequenceDeltaEvent.d.ts +1 -1
- package/lib/sequenceDeltaEvent.d.ts.map +1 -1
- package/lib/sequenceDeltaEvent.js +3 -4
- package/lib/sequenceDeltaEvent.js.map +1 -1
- package/lib/sequenceFactory.d.ts +1 -1
- package/lib/sequenceFactory.d.ts.map +1 -1
- package/lib/sequenceFactory.js +1 -1
- package/lib/sequenceFactory.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts +4 -3
- package/lib/sharedIntervalCollection.d.ts.map +1 -1
- package/lib/sharedIntervalCollection.js +4 -4
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedSequence.d.ts +3 -2
- package/lib/sharedSequence.d.ts.map +1 -1
- package/lib/sharedSequence.js +2 -2
- package/lib/sharedSequence.js.map +1 -1
- package/lib/sharedString.d.ts +2 -2
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js +1 -1
- package/lib/sharedString.js.map +1 -1
- package/package.json +41 -58
- package/src/{localValues.ts → IntervalCollectionValues.ts} +26 -18
- package/src/index.ts +2 -2
- package/src/intervalCollection.ts +46 -47
- package/src/{defaultMap.ts → intervalCollectionMap.ts} +42 -105
- package/src/{defaultMapInterfaces.ts → intervalCollectionMapInterfaces.ts} +26 -16
- package/src/intervalIndex/endpointInRangeIndex.ts +4 -1
- package/src/intervalIndex/endpointIndex.ts +4 -1
- package/src/intervalIndex/idIntervalIndex.ts +4 -2
- package/src/intervalIndex/overlappingIntervalsIndex.ts +8 -5
- package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +6 -3
- package/src/intervalIndex/sequenceIntervalIndexes.ts +3 -1
- package/src/intervalIndex/startpointInRangeIndex.ts +4 -1
- package/src/intervalTree.ts +4 -3
- package/src/intervals/interval.ts +6 -3
- package/src/intervals/intervalUtils.ts +4 -2
- package/src/intervals/sequenceInterval.ts +5 -3
- package/src/packageVersion.ts +1 -1
- package/src/revertibles.ts +10 -10
- package/src/sequence.ts +24 -31
- package/src/sequenceDeltaEvent.ts +3 -4
- package/src/sequenceFactory.ts +4 -3
- package/src/sharedIntervalCollection.ts +12 -18
- package/src/sharedSequence.ts +9 -6
- package/src/sharedString.ts +4 -3
- package/api-extractor-cjs.json +0 -8
- package/dist/defaultMap.d.ts.map +0 -1
- package/dist/defaultMap.js.map +0 -1
- package/dist/defaultMapInterfaces.d.ts.map +0 -1
- package/dist/defaultMapInterfaces.js.map +0 -1
- package/dist/localValues.d.ts.map +0 -1
- package/dist/localValues.js.map +0 -1
- package/dist/sequence-alpha.d.ts +0 -1432
- package/dist/sequence-beta.d.ts +0 -246
- package/dist/sequence-public.d.ts +0 -246
- package/dist/sequence-untrimmed.d.ts +0 -1820
- package/lib/defaultMap.d.ts.map +0 -1
- package/lib/defaultMap.js.map +0 -1
- package/lib/defaultMapInterfaces.d.ts.map +0 -1
- package/lib/defaultMapInterfaces.js.map +0 -1
- package/lib/localValues.d.ts.map +0 -1
- package/lib/localValues.js.map +0 -1
- package/lib/sequence-alpha.d.ts +0 -1432
- package/lib/sequence-beta.d.ts +0 -246
- package/lib/sequence-public.d.ts +0 -246
- package/lib/sequence-untrimmed.d.ts +0 -1820
- package/lib/test/collections.intervalTree.js +0 -73
- package/lib/test/collections.intervalTree.js.map +0 -1
- package/lib/test/createSnapshotFiles.js +0 -15
- package/lib/test/createSnapshotFiles.js.map +0 -1
- package/lib/test/dirname.cjs +0 -16
- package/lib/test/dirname.cjs.map +0 -1
- package/lib/test/endpointInRangeIndex.spec.js +0 -182
- package/lib/test/endpointInRangeIndex.spec.js.map +0 -1
- package/lib/test/fuzz/fuzzUtils.js +0 -250
- package/lib/test/fuzz/fuzzUtils.js.map +0 -1
- package/lib/test/fuzz/intervalCollection.fuzz.spec.js +0 -200
- package/lib/test/fuzz/intervalCollection.fuzz.spec.js.map +0 -1
- package/lib/test/fuzz/intervalRevertibles.fuzz.spec.js +0 -129
- package/lib/test/fuzz/intervalRevertibles.fuzz.spec.js.map +0 -1
- package/lib/test/fuzz/sharedString.fuzz.spec.js +0 -91
- package/lib/test/fuzz/sharedString.fuzz.spec.js.map +0 -1
- package/lib/test/generateSharedStrings.js +0 -138
- package/lib/test/generateSharedStrings.js.map +0 -1
- package/lib/test/intervalCollection.detached.spec.js +0 -126
- package/lib/test/intervalCollection.detached.spec.js.map +0 -1
- package/lib/test/intervalCollection.events.spec.js +0 -491
- package/lib/test/intervalCollection.events.spec.js.map +0 -1
- package/lib/test/intervalCollection.perf.spec.js +0 -88
- package/lib/test/intervalCollection.perf.spec.js.map +0 -1
- package/lib/test/intervalCollection.snapshot.spec.js +0 -171
- package/lib/test/intervalCollection.snapshot.spec.js.map +0 -1
- package/lib/test/intervalCollection.spec.js +0 -1660
- package/lib/test/intervalCollection.spec.js.map +0 -1
- package/lib/test/intervalIndexTestUtils.js +0 -49
- package/lib/test/intervalIndexTestUtils.js.map +0 -1
- package/lib/test/intervalRebasing.spec.js +0 -589
- package/lib/test/intervalRebasing.spec.js.map +0 -1
- package/lib/test/intervalStashedOps.spec.js +0 -142
- package/lib/test/intervalStashedOps.spec.js.map +0 -1
- package/lib/test/intervalTestUtils.js +0 -81
- package/lib/test/intervalTestUtils.js.map +0 -1
- package/lib/test/marshalling.spec.js +0 -55
- package/lib/test/marshalling.spec.js.map +0 -1
- package/lib/test/memory/sharedSequence.spec.js +0 -82
- package/lib/test/memory/sharedSequence.spec.js.map +0 -1
- package/lib/test/memory/sharedString.spec.js +0 -134
- package/lib/test/memory/sharedString.spec.js.map +0 -1
- package/lib/test/overlappingSequenceIntervalsIndex.spec.js +0 -348
- package/lib/test/overlappingSequenceIntervalsIndex.spec.js.map +0 -1
- package/lib/test/partialLoad.spec.js +0 -211
- package/lib/test/partialLoad.spec.js.map +0 -1
- package/lib/test/rebasing.spec.js +0 -81
- package/lib/test/rebasing.spec.js.map +0 -1
- package/lib/test/reentrancy.spec.js +0 -174
- package/lib/test/reentrancy.spec.js.map +0 -1
- package/lib/test/revertibles.spec.js +0 -971
- package/lib/test/revertibles.spec.js.map +0 -1
- package/lib/test/sequenceDeltaEvent.spec.js +0 -2144
- package/lib/test/sequenceDeltaEvent.spec.js.map +0 -1
- package/lib/test/sharedIntervalCollection.spec.js +0 -159
- package/lib/test/sharedIntervalCollection.spec.js.map +0 -1
- package/lib/test/sharedString.spec.js +0 -532
- package/lib/test/sharedString.spec.js.map +0 -1
- package/lib/test/snapshotEmptyProps.spec.js +0 -45
- package/lib/test/snapshotEmptyProps.spec.js.map +0 -1
- package/lib/test/snapshotVersion.spec.js +0 -149
- package/lib/test/snapshotVersion.spec.js.map +0 -1
- package/lib/test/startpointInRangeIndex.spec.js +0 -182
- package/lib/test/startpointInRangeIndex.spec.js.map +0 -1
- package/lib/test/subSequence.spec.js +0 -92
- package/lib/test/subSequence.spec.js.map +0 -1
- package/lib/test/types/validateSequencePrevious.generated.js +0 -162
- package/lib/test/types/validateSequencePrevious.generated.js.map +0 -1
- package/lib/test/v1IntervalCollectionHelpers.js +0 -93
- package/lib/test/v1IntervalCollectionHelpers.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { appendToMergeTreeDeltaRevertibles, matchProperties, ReferenceType, reservedMarkerIdKey, reservedMarkerSimpleTypeKey, reservedTileLabelsKey, revertMergeTreeDeltaRevertibles, } from "@fluidframework/merge-tree";
|
|
7
|
-
import { MockFluidDataStoreRuntime, MockContainerRuntimeFactory, MockContainerRuntimeFactoryForReconnection, MockEmptyDeltaConnection, MockStorage, validateAssertionError, } from "@fluidframework/test-runtime-utils";
|
|
8
|
-
import { AttachState } from "@fluidframework/container-definitions";
|
|
9
|
-
import { getTextAndMarkers, SharedString } from "../sharedString.js";
|
|
10
|
-
import { SharedStringFactory } from "../sequenceFactory.js";
|
|
11
|
-
describe("SharedString", () => {
|
|
12
|
-
let sharedString;
|
|
13
|
-
let dataStoreRuntime1;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
dataStoreRuntime1 = new MockFluidDataStoreRuntime();
|
|
16
|
-
sharedString = new SharedString(dataStoreRuntime1, "shared-string-1", SharedStringFactory.Attributes);
|
|
17
|
-
});
|
|
18
|
-
describe("SharedString in local state", () => {
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
dataStoreRuntime1.local = true;
|
|
21
|
-
});
|
|
22
|
-
// Creates a new SharedString and loads it from the passed snapshot tree.
|
|
23
|
-
async function CreateStringAndCompare(summaryTree) {
|
|
24
|
-
const services = {
|
|
25
|
-
deltaConnection: new MockEmptyDeltaConnection(),
|
|
26
|
-
objectStorage: MockStorage.createFromSummary(summaryTree),
|
|
27
|
-
};
|
|
28
|
-
const dataStoreRuntime2 = new MockFluidDataStoreRuntime();
|
|
29
|
-
const sharedString2 = new SharedString(dataStoreRuntime2, "shared-string-2", SharedStringFactory.Attributes);
|
|
30
|
-
await sharedString2.load(services);
|
|
31
|
-
await sharedString2.loaded;
|
|
32
|
-
assert.equal(sharedString.getText(), sharedString2.getText(), "Could not correctly load from snapshot");
|
|
33
|
-
}
|
|
34
|
-
function verifyAndReturnSummaryTree() {
|
|
35
|
-
const summarizeResult = sharedString.getAttachSummary();
|
|
36
|
-
const summaryObjectKeys = Object.keys(summarizeResult.summary.tree);
|
|
37
|
-
assert.strictEqual(summaryObjectKeys.length, 1, "summary should have one entries");
|
|
38
|
-
assert.strictEqual(summaryObjectKeys[0], "content", "content not present in summary");
|
|
39
|
-
const subTree = summarizeResult.summary.tree.content;
|
|
40
|
-
const subTreeObjectKeys = Object.keys(subTree.tree);
|
|
41
|
-
assert.strictEqual(subTreeObjectKeys.length, 1, "sub tree should have one entries");
|
|
42
|
-
assert.strictEqual(subTreeObjectKeys[0], "header", "header not present in sub tree");
|
|
43
|
-
return summarizeResult.summary;
|
|
44
|
-
}
|
|
45
|
-
it("can insert text", async () => {
|
|
46
|
-
sharedString.insertText(0, "hello");
|
|
47
|
-
assert.equal(sharedString.getText(), "hello", "Could not insert text at beginning");
|
|
48
|
-
sharedString.insertText(5, "world");
|
|
49
|
-
assert.equal(sharedString.getText(), "helloworld", "Could not insert text at end");
|
|
50
|
-
sharedString.insertText(5, " ");
|
|
51
|
-
assert.equal(sharedString.getText(), "hello world", "Could not insert text in the middle");
|
|
52
|
-
});
|
|
53
|
-
it("can replace text", async () => {
|
|
54
|
-
sharedString.insertText(0, "hello world");
|
|
55
|
-
sharedString.replaceText(6, 11, "there!");
|
|
56
|
-
assert.equal(sharedString.getText(), "hello there!", "Could not replace text");
|
|
57
|
-
sharedString.replaceText(0, 5, "hi");
|
|
58
|
-
assert.equal(sharedString.getText(), "hi there!", "Could not replace text at beginning");
|
|
59
|
-
});
|
|
60
|
-
it("can remove text", async () => {
|
|
61
|
-
sharedString.insertText(0, "hello world");
|
|
62
|
-
sharedString.removeText(5, 11);
|
|
63
|
-
assert.equal(sharedString.getText(), "hello", "Could not remove text");
|
|
64
|
-
sharedString.removeText(0, 3);
|
|
65
|
-
assert.equal(sharedString.getText(), "lo", "Could not remove text from beginning");
|
|
66
|
-
});
|
|
67
|
-
it("can annotate the text", async () => {
|
|
68
|
-
const text = "hello world";
|
|
69
|
-
const styleProps = { style: "bold" };
|
|
70
|
-
sharedString.insertText(0, text, styleProps);
|
|
71
|
-
for (let i = 0; i < text.length; i++) {
|
|
72
|
-
assert.deepEqual({ ...sharedString.getPropertiesAtPosition(i) }, { ...styleProps }, "Could not add props");
|
|
73
|
-
}
|
|
74
|
-
const colorProps = { color: "green" };
|
|
75
|
-
sharedString.annotateRange(6, text.length, colorProps);
|
|
76
|
-
for (let i = 6; i < text.length; i++) {
|
|
77
|
-
assert.deepEqual({ ...sharedString.getPropertiesAtPosition(i) }, { ...styleProps, ...colorProps }, "Could not annotate props");
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
it("can handle null annotations in text", async () => {
|
|
81
|
-
const text = "hello world";
|
|
82
|
-
const startingProps = { style: "bold", color: null };
|
|
83
|
-
sharedString.insertText(0, text, startingProps);
|
|
84
|
-
for (let i = 0; i < text.length; i++) {
|
|
85
|
-
assert.strictEqual(sharedString.getPropertiesAtPosition(i)?.color, undefined, "Null values allowed in properties");
|
|
86
|
-
}
|
|
87
|
-
const updatedProps = { style: null };
|
|
88
|
-
sharedString.annotateRange(6, text.length, updatedProps);
|
|
89
|
-
for (let i = 6; i < text.length; i++) {
|
|
90
|
-
assert.strictEqual(sharedString.getPropertiesAtPosition(i)?.style, undefined, "Null values allowed in properties");
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
it("can handle empty annotations in text", async () => {
|
|
94
|
-
const text = "hello world";
|
|
95
|
-
const startingProps = Object.entries({});
|
|
96
|
-
sharedString.insertText(0, text, startingProps);
|
|
97
|
-
for (let i = 0; i < text.length; i++) {
|
|
98
|
-
const actualProps = sharedString.getPropertiesAtPosition(i);
|
|
99
|
-
assert(actualProps !== undefined, "Properties are undefined when they should be empty");
|
|
100
|
-
assert(startingProps.toString() === Object.entries(actualProps).toString(), `Properties are not empty at position ${i}`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
it("can insert marker", () => {
|
|
104
|
-
sharedString.insertText(0, "hello world");
|
|
105
|
-
// Insert a simple marker.
|
|
106
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
107
|
-
[reservedMarkerIdKey]: "markerId",
|
|
108
|
-
[reservedMarkerSimpleTypeKey]: "markerKeyValue",
|
|
109
|
-
});
|
|
110
|
-
// Verify that the simple marker can be retrieved via id.
|
|
111
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
112
|
-
assert.equal(simpleMarker?.type, "Marker", "Could not get simple marker");
|
|
113
|
-
assert.equal(simpleMarker?.properties?.markerId, "markerId", "markerId is incorrect");
|
|
114
|
-
assert.equal(simpleMarker?.properties?.markerSimpleType, "markerKeyValue", "markerSimpleType is incorrect");
|
|
115
|
-
// Insert a tile marker.
|
|
116
|
-
sharedString.insertMarker(0, ReferenceType.Tile, {
|
|
117
|
-
[reservedTileLabelsKey]: ["tileLabel"],
|
|
118
|
-
[reservedMarkerIdKey]: "tileMarkerId",
|
|
119
|
-
});
|
|
120
|
-
// Verify that the tile marker can be retrieved via label.
|
|
121
|
-
const { parallelMarkers } = getTextAndMarkers(sharedString, "tileLabel");
|
|
122
|
-
const parallelMarker = parallelMarkers[0];
|
|
123
|
-
assert.equal(parallelMarker.type, "Marker", "Could not get tile marker");
|
|
124
|
-
assert.equal(parallelMarker.properties?.markerId, "tileMarkerId", "tile markerId is incorrect");
|
|
125
|
-
});
|
|
126
|
-
it("can annotate marker", () => {
|
|
127
|
-
sharedString.insertText(0, "hello world");
|
|
128
|
-
// Insert a simple marker.
|
|
129
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
130
|
-
[reservedMarkerIdKey]: "markerId",
|
|
131
|
-
});
|
|
132
|
-
// Annotate the marker.
|
|
133
|
-
const props = { color: "blue" };
|
|
134
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
135
|
-
sharedString.annotateMarker(simpleMarker, props);
|
|
136
|
-
assert.equal(simpleMarker.properties?.color, "blue", "Could not annotate marker");
|
|
137
|
-
});
|
|
138
|
-
it("fails when the marker id is updated with a new string", () => {
|
|
139
|
-
sharedString.insertText(0, "hello world");
|
|
140
|
-
// Insert a simple marker.
|
|
141
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
142
|
-
[reservedMarkerIdKey]: "markerId",
|
|
143
|
-
});
|
|
144
|
-
// Annotate the marker.
|
|
145
|
-
const props = { color: "blue" };
|
|
146
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
147
|
-
sharedString.annotateMarker(simpleMarker, props);
|
|
148
|
-
assert.equal(simpleMarker.properties?.color, "blue", "Could not annotate marker");
|
|
149
|
-
// Annotate the marker's ID.
|
|
150
|
-
const newIdProps = { [reservedMarkerIdKey]: "newIdValue" };
|
|
151
|
-
assert.throws(() => {
|
|
152
|
-
sharedString.annotateMarker(simpleMarker, newIdProps);
|
|
153
|
-
}, (e) => validateAssertionError(e, "Cannot change the markerId of an existing marker"), "Error from attempting to update marker was not thrown or was not the expected error");
|
|
154
|
-
});
|
|
155
|
-
it("fails when the marker id is updated with null", () => {
|
|
156
|
-
sharedString.insertText(0, "hello world");
|
|
157
|
-
// Insert a simple marker.
|
|
158
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
159
|
-
[reservedMarkerIdKey]: "markerId",
|
|
160
|
-
});
|
|
161
|
-
// Annotate the marker's ID.
|
|
162
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
163
|
-
const newIdProps = { [reservedMarkerIdKey]: null };
|
|
164
|
-
assert.throws(() => {
|
|
165
|
-
sharedString.annotateMarker(simpleMarker, newIdProps);
|
|
166
|
-
}, (e) => validateAssertionError(e, "Cannot change the markerId of an existing marker"), "Error from attempting to update marker was not thrown or was not the expected error");
|
|
167
|
-
});
|
|
168
|
-
it("fails when the marker id is updated with undefined", () => {
|
|
169
|
-
sharedString.insertText(0, "hello world");
|
|
170
|
-
// Insert a simple marker.
|
|
171
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
172
|
-
[reservedMarkerIdKey]: "markerId",
|
|
173
|
-
});
|
|
174
|
-
// Annotate the marker's ID.
|
|
175
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
176
|
-
const newIdProps = { [reservedMarkerIdKey]: undefined };
|
|
177
|
-
assert.throws(() => {
|
|
178
|
-
sharedString.annotateMarker(simpleMarker, newIdProps);
|
|
179
|
-
}, (e) => validateAssertionError(e, "Cannot change the markerId of an existing marker"), "Error from attempting to update marker was not thrown or was not the expected error");
|
|
180
|
-
});
|
|
181
|
-
it("allows the markerId to be updated with the existing value", () => {
|
|
182
|
-
sharedString.insertText(0, "hello world");
|
|
183
|
-
// Insert a simple marker.
|
|
184
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
185
|
-
[reservedMarkerIdKey]: "markerId",
|
|
186
|
-
});
|
|
187
|
-
// Annotate the marker's ID.
|
|
188
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
189
|
-
const newIdProps = { [reservedMarkerIdKey]: "markerId" };
|
|
190
|
-
sharedString.annotateMarker(simpleMarker, newIdProps);
|
|
191
|
-
assert.equal(sharedString.getMarkerFromId("markerId"), simpleMarker, "Could not update marker with the existing id value");
|
|
192
|
-
assert.equal("markerId", simpleMarker.properties?.[reservedMarkerIdKey], `Actual value of marker id property - ${simpleMarker.properties?.[reservedMarkerIdKey]} - does not match the expected value`);
|
|
193
|
-
});
|
|
194
|
-
it("replace zero range", async () => {
|
|
195
|
-
sharedString.insertText(0, "123");
|
|
196
|
-
sharedString.replaceText(1, 1, "\u00e4\u00c4");
|
|
197
|
-
assert.equal(sharedString.getText(), "1\u00e4\u00c423", "Could not replace zero range");
|
|
198
|
-
});
|
|
199
|
-
it("replace negative range", async () => {
|
|
200
|
-
sharedString.insertText(0, "123");
|
|
201
|
-
sharedString.replaceText(2, 1, "aaa");
|
|
202
|
-
// This assert relies on the behavior that replacement for a reversed range
|
|
203
|
-
// will insert at the max end of the range but not delete the range
|
|
204
|
-
assert.equal(sharedString.getText(), "12aaa3", "Could not replace negative range");
|
|
205
|
-
});
|
|
206
|
-
it("can load a SharedString from summary", async () => {
|
|
207
|
-
const insertText = "text";
|
|
208
|
-
const segmentCount = 1000;
|
|
209
|
-
sharedString.initializeLocal();
|
|
210
|
-
for (let i = 0; i < segmentCount; i = i + 1) {
|
|
211
|
-
sharedString.insertText(0, `${insertText}${i}`);
|
|
212
|
-
}
|
|
213
|
-
// Verify that summary data is correct.
|
|
214
|
-
let summaryTree = verifyAndReturnSummaryTree();
|
|
215
|
-
// Load a new SharedString from the snapshot and verify it is loaded correctly.
|
|
216
|
-
await CreateStringAndCompare(summaryTree);
|
|
217
|
-
for (let i = 0; i < segmentCount; i = i + 1) {
|
|
218
|
-
sharedString.insertText(0, `${insertText}-${i}`);
|
|
219
|
-
}
|
|
220
|
-
// TODO: Due to segment packing, we have only "header" and no body
|
|
221
|
-
// Need to change test to include other types of segments (like marker) to exercise "body".
|
|
222
|
-
// Verify summary after changes.
|
|
223
|
-
summaryTree = verifyAndReturnSummaryTree();
|
|
224
|
-
// Load a new SharedString from the snapshot and verify it is loaded correctly.
|
|
225
|
-
await CreateStringAndCompare(summaryTree);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("SharedString op processing in local state", () => {
|
|
229
|
-
it("should correctly process operations sent in local state", async () => {
|
|
230
|
-
// Set the data store runtime to local.
|
|
231
|
-
dataStoreRuntime1.local = true;
|
|
232
|
-
// Initialize the shared string so that it is completely loaded before we take a snapshot.
|
|
233
|
-
sharedString.initializeLocal();
|
|
234
|
-
// Insert and replace text in first shared string.
|
|
235
|
-
sharedString.insertText(0, "hello world");
|
|
236
|
-
sharedString.replaceText(6, 11, "there");
|
|
237
|
-
// Load a new Ink in connected state from the snapshot of the first one.
|
|
238
|
-
const containerRuntimeFactory = new MockContainerRuntimeFactory();
|
|
239
|
-
const dataStoreRuntime2 = new MockFluidDataStoreRuntime();
|
|
240
|
-
const containerRuntime2 = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime2);
|
|
241
|
-
const services2 = {
|
|
242
|
-
deltaConnection: dataStoreRuntime2.createDeltaConnection(),
|
|
243
|
-
objectStorage: MockStorage.createFromSummary(sharedString.getAttachSummary().summary),
|
|
244
|
-
};
|
|
245
|
-
const sharedString2 = new SharedString(dataStoreRuntime2, "shared-string-2", SharedStringFactory.Attributes);
|
|
246
|
-
await sharedString2.load(services2);
|
|
247
|
-
// Now connect the first Ink
|
|
248
|
-
dataStoreRuntime1.setAttachState(AttachState.Attached);
|
|
249
|
-
const containerRuntime1 = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime1);
|
|
250
|
-
const services1 = {
|
|
251
|
-
deltaConnection: dataStoreRuntime1.createDeltaConnection(),
|
|
252
|
-
objectStorage: new MockStorage(undefined),
|
|
253
|
-
};
|
|
254
|
-
sharedString.connect(services1);
|
|
255
|
-
// Verify that both the shared strings have the text.
|
|
256
|
-
assert.equal(sharedString.getText(), "hello there", "The first string does not have the text");
|
|
257
|
-
assert.equal(sharedString2.getText(), "hello there", "The second string does not have the text");
|
|
258
|
-
// Insert and replace text in second shared string.
|
|
259
|
-
sharedString2.insertText(0, "well ");
|
|
260
|
-
// Process the message.
|
|
261
|
-
containerRuntimeFactory.processAllMessages();
|
|
262
|
-
// Verify that both the shared strings have the new text.
|
|
263
|
-
assert.equal(sharedString.getText(), "well hello there", "The first string does not have the text");
|
|
264
|
-
assert.equal(sharedString2.getText(), "well hello there", "The second string does not have the text");
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
describe("SharedString in connected state with a remote SharedString", () => {
|
|
268
|
-
let sharedString2;
|
|
269
|
-
let containerRuntimeFactory;
|
|
270
|
-
beforeEach(() => {
|
|
271
|
-
containerRuntimeFactory = new MockContainerRuntimeFactory();
|
|
272
|
-
// Connect the first SharedString.
|
|
273
|
-
dataStoreRuntime1.setAttachState(AttachState.Attached);
|
|
274
|
-
const containerRuntime1 = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime1);
|
|
275
|
-
const services1 = {
|
|
276
|
-
deltaConnection: dataStoreRuntime1.createDeltaConnection(),
|
|
277
|
-
objectStorage: new MockStorage(),
|
|
278
|
-
};
|
|
279
|
-
sharedString.initializeLocal();
|
|
280
|
-
sharedString.connect(services1);
|
|
281
|
-
// Create and connect a second SharedString.
|
|
282
|
-
const dataStoreRuntime2 = new MockFluidDataStoreRuntime();
|
|
283
|
-
const containerRuntime2 = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime2);
|
|
284
|
-
const services2 = {
|
|
285
|
-
deltaConnection: dataStoreRuntime2.createDeltaConnection(),
|
|
286
|
-
objectStorage: new MockStorage(),
|
|
287
|
-
};
|
|
288
|
-
sharedString2 = new SharedString(dataStoreRuntime2, "shared-string-2", SharedStringFactory.Attributes);
|
|
289
|
-
sharedString2.initializeLocal();
|
|
290
|
-
sharedString2.connect(services2);
|
|
291
|
-
});
|
|
292
|
-
it("can insert text", async () => {
|
|
293
|
-
// Insert text in first shared string.
|
|
294
|
-
sharedString.insertText(0, "hello");
|
|
295
|
-
// Process the messages.
|
|
296
|
-
containerRuntimeFactory.processAllMessages();
|
|
297
|
-
// Verify that both the shared strings inserted the text.
|
|
298
|
-
assert.equal(sharedString.getText(), "hello", "Could not insert text at beginning");
|
|
299
|
-
assert.equal(sharedString2.getText(), "hello", "Could not insert text at beginning in remote string");
|
|
300
|
-
// Insert text at the end of second shared string.
|
|
301
|
-
sharedString2.insertText(5, " world");
|
|
302
|
-
// Process the messages.
|
|
303
|
-
containerRuntimeFactory.processAllMessages();
|
|
304
|
-
// Verify that both the shared strings inserted the text.
|
|
305
|
-
assert.equal(sharedString.getText(), "hello world", "Could not insert text at end");
|
|
306
|
-
assert.equal(sharedString2.getText(), "hello world", "Could not insert text at end in remote string");
|
|
307
|
-
});
|
|
308
|
-
it("can replace text", async () => {
|
|
309
|
-
// Insert and replace text in first shared string.
|
|
310
|
-
sharedString.insertText(0, "hello world");
|
|
311
|
-
sharedString.replaceText(6, 11, "there!");
|
|
312
|
-
// Process the messages.
|
|
313
|
-
containerRuntimeFactory.processAllMessages();
|
|
314
|
-
// Verify that both the shared strings replaced the text.
|
|
315
|
-
assert.equal(sharedString.getText(), "hello there!", "Could not replace text");
|
|
316
|
-
assert.equal(sharedString2.getText(), "hello there!", "Could not replace text in remote string");
|
|
317
|
-
});
|
|
318
|
-
it("can remove text", async () => {
|
|
319
|
-
// Insert and remove text in first shared string.
|
|
320
|
-
sharedString.insertText(0, "hello world");
|
|
321
|
-
sharedString.removeText(5, 11);
|
|
322
|
-
// Process the messages.
|
|
323
|
-
containerRuntimeFactory.processAllMessages();
|
|
324
|
-
// Verify that both the shared strings removed the text.
|
|
325
|
-
assert.equal(sharedString.getText(), "hello", "Could not remove text");
|
|
326
|
-
assert.equal(sharedString2.getText(), "hello", "Could not remove text from remote string");
|
|
327
|
-
});
|
|
328
|
-
it("can annotate the text", async () => {
|
|
329
|
-
// Insert text with properties in the first shared string.
|
|
330
|
-
const text = "hello world";
|
|
331
|
-
const styleProps = { style: "bold" };
|
|
332
|
-
sharedString.insertText(0, text, styleProps);
|
|
333
|
-
// Process the messages.
|
|
334
|
-
containerRuntimeFactory.processAllMessages();
|
|
335
|
-
// Verify that both the shared strings have the properties.
|
|
336
|
-
for (let i = 0; i < text.length; i++) {
|
|
337
|
-
assert.deepEqual({ ...sharedString.getPropertiesAtPosition(i) }, { ...styleProps }, "Could not add props");
|
|
338
|
-
assert.deepEqual({ ...sharedString2.getPropertiesAtPosition(i) }, { ...styleProps }, "Could not add props to remote string");
|
|
339
|
-
}
|
|
340
|
-
// Annotate the properties.
|
|
341
|
-
const colorProps = { color: "green" };
|
|
342
|
-
sharedString.annotateRange(6, text.length, colorProps);
|
|
343
|
-
// Process the messages.
|
|
344
|
-
containerRuntimeFactory.processAllMessages();
|
|
345
|
-
// Verify that both the shared strings have the annotated properties.
|
|
346
|
-
for (let i = 6; i < text.length; i++) {
|
|
347
|
-
assert.deepEqual({ ...sharedString.getPropertiesAtPosition(i) }, { ...styleProps, ...colorProps }, "Could not annotate props");
|
|
348
|
-
assert.deepEqual({ ...sharedString2.getPropertiesAtPosition(i) }, { ...styleProps, ...colorProps }, "Could not annotate props in remote string");
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
it("can insert marker", () => {
|
|
352
|
-
const label = "tileLabel";
|
|
353
|
-
const id = "tileMarkerId";
|
|
354
|
-
const simpleKey = "tileMarkerKey";
|
|
355
|
-
const verifyMarker = (marker) => {
|
|
356
|
-
assert.equal(marker.type, "Marker", "Could not get simple marker");
|
|
357
|
-
assert.equal(marker.properties.markerId, id, "markerId is incorrect");
|
|
358
|
-
assert.equal(marker.properties.markerSimpleType, simpleKey, "markerSimpleType is incorrect");
|
|
359
|
-
assert.equal(marker.properties.referenceTileLabels[0], label, "markerSimpleType is incorrect");
|
|
360
|
-
};
|
|
361
|
-
sharedString.insertText(0, "hello world");
|
|
362
|
-
// Insert a tile marker.
|
|
363
|
-
sharedString.insertMarker(6, ReferenceType.Tile, {
|
|
364
|
-
[reservedTileLabelsKey]: [label],
|
|
365
|
-
[reservedMarkerIdKey]: id,
|
|
366
|
-
[reservedMarkerSimpleTypeKey]: simpleKey,
|
|
367
|
-
});
|
|
368
|
-
// Process the messages.
|
|
369
|
-
containerRuntimeFactory.processAllMessages();
|
|
370
|
-
// Verify that the marker can be retrieved via id from both the shared strings.
|
|
371
|
-
const simpleMarker1 = sharedString.getMarkerFromId(id);
|
|
372
|
-
verifyMarker(simpleMarker1);
|
|
373
|
-
const simpleMarker2 = sharedString2.getMarkerFromId(id);
|
|
374
|
-
verifyMarker(simpleMarker2);
|
|
375
|
-
// Verify that the marker can be retrieved via label from both the shared strings.
|
|
376
|
-
const textAndMarker1 = getTextAndMarkers(sharedString, label);
|
|
377
|
-
verifyMarker(textAndMarker1.parallelMarkers[0]);
|
|
378
|
-
const textAndMarker2 = getTextAndMarkers(sharedString2, label);
|
|
379
|
-
verifyMarker(textAndMarker2.parallelMarkers[0]);
|
|
380
|
-
});
|
|
381
|
-
it("can annotate marker", () => {
|
|
382
|
-
sharedString.insertText(0, "hello world");
|
|
383
|
-
// Insert a simple marker.
|
|
384
|
-
sharedString.insertMarker(6, ReferenceType.Simple, {
|
|
385
|
-
[reservedMarkerIdKey]: "markerId",
|
|
386
|
-
});
|
|
387
|
-
// Annotate the marker.
|
|
388
|
-
const props = { color: "blue" };
|
|
389
|
-
const simpleMarker = sharedString.getMarkerFromId("markerId");
|
|
390
|
-
sharedString.annotateMarker(simpleMarker, props);
|
|
391
|
-
// Process the messages.
|
|
392
|
-
containerRuntimeFactory.processAllMessages();
|
|
393
|
-
// Verify that the marker was annotated in both the shared strings.
|
|
394
|
-
const simpleMarker1 = sharedString.getMarkerFromId("markerId");
|
|
395
|
-
assert.equal(simpleMarker1.properties?.color, "blue", "Could not annotate marker");
|
|
396
|
-
const simpleMarker2 = sharedString.getMarkerFromId("markerId");
|
|
397
|
-
assert.equal(simpleMarker2.properties?.color, "blue", "Could not annotate marker in remote string");
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
describe("reconnect", () => {
|
|
401
|
-
let containerRuntimeFactory;
|
|
402
|
-
let containerRuntime1;
|
|
403
|
-
let containerRuntime2;
|
|
404
|
-
let sharedString2;
|
|
405
|
-
beforeEach(async () => {
|
|
406
|
-
containerRuntimeFactory = new MockContainerRuntimeFactoryForReconnection();
|
|
407
|
-
// Connect the first SharedString.
|
|
408
|
-
containerRuntime1 = containerRuntimeFactory.createContainerRuntime(dataStoreRuntime1);
|
|
409
|
-
const services1 = {
|
|
410
|
-
deltaConnection: dataStoreRuntime1.createDeltaConnection(),
|
|
411
|
-
objectStorage: new MockStorage(),
|
|
412
|
-
};
|
|
413
|
-
sharedString.initializeLocal();
|
|
414
|
-
sharedString.connect(services1);
|
|
415
|
-
// Create and connect a second SharedString.
|
|
416
|
-
const runtime2 = new MockFluidDataStoreRuntime();
|
|
417
|
-
containerRuntime2 = containerRuntimeFactory.createContainerRuntime(runtime2);
|
|
418
|
-
sharedString2 = new SharedString(runtime2, "shared-string-2", SharedStringFactory.Attributes);
|
|
419
|
-
const services2 = {
|
|
420
|
-
deltaConnection: runtime2.createDeltaConnection(),
|
|
421
|
-
objectStorage: new MockStorage(),
|
|
422
|
-
};
|
|
423
|
-
sharedString2.initializeLocal();
|
|
424
|
-
sharedString2.connect(services2);
|
|
425
|
-
});
|
|
426
|
-
it("can resend unacked ops on reconnection", async () => {
|
|
427
|
-
// Make couple of changes to the first SharedString.
|
|
428
|
-
sharedString.insertText(0, "helloworld");
|
|
429
|
-
sharedString.replaceText(5, 10, " friend");
|
|
430
|
-
for (let i = 0; i < 10; i++) {
|
|
431
|
-
// Disconnect and reconnect the first collection.
|
|
432
|
-
containerRuntime1.connected = false;
|
|
433
|
-
containerRuntime1.connected = true;
|
|
434
|
-
}
|
|
435
|
-
// Process the messages.
|
|
436
|
-
containerRuntimeFactory.processAllMessages();
|
|
437
|
-
// Verify that the changes were correctly received by the second SharedString
|
|
438
|
-
assert.equal(sharedString2.getText(), "hello friend");
|
|
439
|
-
});
|
|
440
|
-
it("insert in middle of multibyte character", async () => {
|
|
441
|
-
let base = "🎉";
|
|
442
|
-
sharedString.insertText(0, "🎉");
|
|
443
|
-
assert.equal(sharedString.getText(), base);
|
|
444
|
-
assert.equal(sharedString.getLength(), base.length);
|
|
445
|
-
containerRuntimeFactory.processAllMessages();
|
|
446
|
-
base = `${base.slice(0, 1)}a${base.slice(1)}`;
|
|
447
|
-
sharedString.insertText(1, "a");
|
|
448
|
-
containerRuntimeFactory.processAllMessages();
|
|
449
|
-
assert.equal(sharedString.getText(), base); // not 🎉a
|
|
450
|
-
assert.equal(sharedString.getLength(), base.length);
|
|
451
|
-
});
|
|
452
|
-
it("insert in middle of surrogate pair", async () => {
|
|
453
|
-
let base = "👨🏻🦱";
|
|
454
|
-
sharedString.insertText(0, "👨🏻🦱");
|
|
455
|
-
assert.equal(sharedString.getText(), base);
|
|
456
|
-
assert.equal(sharedString.getLength(), base.length);
|
|
457
|
-
containerRuntimeFactory.processAllMessages();
|
|
458
|
-
base = `${base.slice(0, 2)}a${base.slice(2)}`;
|
|
459
|
-
sharedString.insertText(2, "a");
|
|
460
|
-
containerRuntimeFactory.processAllMessages();
|
|
461
|
-
assert.equal(sharedString.getText(), base); // not 👨🏻🦱a
|
|
462
|
-
assert.equal(sharedString.getLength(), base.length);
|
|
463
|
-
});
|
|
464
|
-
it("can store ops in disconnected state and resend them on reconnection", async () => {
|
|
465
|
-
// Disconnect the first SharedString.
|
|
466
|
-
containerRuntime1.connected = false;
|
|
467
|
-
// Make couple of changes to it.
|
|
468
|
-
sharedString.insertText(0, "helloworld");
|
|
469
|
-
sharedString.replaceText(5, 10, " friend");
|
|
470
|
-
// Reconnect the first SharedString.
|
|
471
|
-
containerRuntime1.connected = true;
|
|
472
|
-
// Process the messages.
|
|
473
|
-
containerRuntimeFactory.processAllMessages();
|
|
474
|
-
// Verify that the changes were correctly received by the second SharedString
|
|
475
|
-
assert.equal(sharedString2.getText(), "hello friend");
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
// revertibles are deeply test in the merge tree package
|
|
479
|
-
// these test just validate high level integration
|
|
480
|
-
describe("revertible smoke tests", () => {
|
|
481
|
-
it("insert", () => {
|
|
482
|
-
const revertibles = [];
|
|
483
|
-
sharedString.on("sequenceDelta", (event) => appendToMergeTreeDeltaRevertibles(event.deltaArgs, revertibles));
|
|
484
|
-
for (let i = 0; i < 10; i++) {
|
|
485
|
-
sharedString.insertText(sharedString.getLength(), i.toString());
|
|
486
|
-
}
|
|
487
|
-
assert.equal(sharedString.getText(), "0123456789");
|
|
488
|
-
// undo all inserts
|
|
489
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
490
|
-
assert.equal(sharedString.getText(), "");
|
|
491
|
-
// redo all inserts
|
|
492
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
493
|
-
assert.equal(sharedString.getText(), "0123456789");
|
|
494
|
-
});
|
|
495
|
-
it("remove", () => {
|
|
496
|
-
sharedString.insertText(sharedString.getLength(), "hello world");
|
|
497
|
-
const revertibles = [];
|
|
498
|
-
sharedString.on("sequenceDelta", (event) => appendToMergeTreeDeltaRevertibles(event.deltaArgs, revertibles));
|
|
499
|
-
while (sharedString.getLength() > 0) {
|
|
500
|
-
const middle = Math.floor(sharedString.getLength() / 2);
|
|
501
|
-
sharedString.removeRange(middle, middle + 1);
|
|
502
|
-
}
|
|
503
|
-
assert.equal(sharedString.getText(), "");
|
|
504
|
-
// undo all removes
|
|
505
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
506
|
-
assert.equal(sharedString.getText(), "hello world");
|
|
507
|
-
// redo all removes
|
|
508
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
509
|
-
assert.equal(sharedString.getText(), "");
|
|
510
|
-
});
|
|
511
|
-
it("annotate", () => {
|
|
512
|
-
sharedString.insertText(0, "hello world");
|
|
513
|
-
Array.from({ length: sharedString.getLength() }).forEach((_, i) => assert(matchProperties(sharedString.getPropertiesAtPosition(i), undefined)));
|
|
514
|
-
const revertibles = [];
|
|
515
|
-
sharedString.on("sequenceDelta", (event) => appendToMergeTreeDeltaRevertibles(event.deltaArgs, revertibles));
|
|
516
|
-
for (let i = 0; i < sharedString.getLength(); i++) {
|
|
517
|
-
sharedString.annotateRange(i, i + 1, { test: i });
|
|
518
|
-
}
|
|
519
|
-
assert.equal(sharedString.getText(), "hello world");
|
|
520
|
-
Array.from({ length: sharedString.getLength() }).forEach((_, i) => assert(matchProperties(sharedString.getPropertiesAtPosition(i), { test: i })));
|
|
521
|
-
// undo all annotates
|
|
522
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
523
|
-
assert.equal(sharedString.getText(), "hello world");
|
|
524
|
-
Array.from({ length: sharedString.getLength() }).forEach((_, i) => assert(matchProperties(sharedString.getPropertiesAtPosition(i), {})));
|
|
525
|
-
// redo all annotates
|
|
526
|
-
revertMergeTreeDeltaRevertibles(sharedString, revertibles.splice(0));
|
|
527
|
-
assert.equal(sharedString.getText(), "hello world");
|
|
528
|
-
Array.from({ length: sharedString.getLength() }).forEach((_, i) => assert(matchProperties(sharedString.getPropertiesAtPosition(i), { test: i })));
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
//# sourceMappingURL=sharedString.spec.js.map
|