|
|
@ -80,9 +80,12 @@ const test = <U extends `${string}:${"L" | "R"}`>(
|
|
|
|
const reconciledIds = reconciled.map((x) => x.id);
|
|
|
|
const reconciledIds = reconciled.map((x) => x.id);
|
|
|
|
const reconciledIndices = reconciled.map((x) => x.index);
|
|
|
|
const reconciledIndices = reconciled.map((x) => x.index);
|
|
|
|
|
|
|
|
|
|
|
|
expect(target.length).equal(reconciled.length);
|
|
|
|
expect(target.length).toEqual(reconciled.length);
|
|
|
|
expect(reconciledIndices.length).equal(new Set([...reconciledIndices]).size); // expect no duplicated indices
|
|
|
|
expect(reconciledIndices.length).toEqual(
|
|
|
|
expect(reconciledIds).deep.equal(
|
|
|
|
new Set([...reconciledIndices]).size,
|
|
|
|
|
|
|
|
); // expect no duplicated indices
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
|
|
|
reconciledIds,
|
|
|
|
target.map((uid) => {
|
|
|
|
target.map((uid) => {
|
|
|
|
const [, id, source] = uid.match(/^(\w+):([LR])$/)!;
|
|
|
|
const [, id, source] = uid.match(/^(\w+):([LR])$/)!;
|
|
|
|
const element = (source === "L" ? _local : _remote).find(
|
|
|
|
const element = (source === "L" ? _local : _remote).find(
|
|
|
@ -96,13 +99,15 @@ const test = <U extends `${string}:${"L" | "R"}`>(
|
|
|
|
|
|
|
|
|
|
|
|
// convergent reconciliation on the remote client
|
|
|
|
// convergent reconciliation on the remote client
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
expect(
|
|
|
|
assert.deepEqual(
|
|
|
|
reconcileElements(
|
|
|
|
reconcileElements(
|
|
|
|
cloneJSON(_remote),
|
|
|
|
cloneJSON(_remote),
|
|
|
|
cloneJSON(_local as RemoteExcalidrawElement[]),
|
|
|
|
cloneJSON(_local as RemoteExcalidrawElement[]),
|
|
|
|
{} as AppState,
|
|
|
|
{} as AppState,
|
|
|
|
).map((x) => x.id),
|
|
|
|
).map((x) => x.id),
|
|
|
|
).deep.equal(reconciledIds, "convergent reconciliation");
|
|
|
|
reconciledIds,
|
|
|
|
|
|
|
|
"convergent reconciliation",
|
|
|
|
|
|
|
|
);
|
|
|
|
} catch (error: any) {
|
|
|
|
} catch (error: any) {
|
|
|
|
console.error("local original", _remote);
|
|
|
|
console.error("local original", _remote);
|
|
|
|
console.error("remote original", _local);
|
|
|
|
console.error("remote original", _local);
|
|
|
@ -111,13 +116,15 @@ const test = <U extends `${string}:${"L" | "R"}`>(
|
|
|
|
|
|
|
|
|
|
|
|
// bidirectional re-reconciliation on remote client
|
|
|
|
// bidirectional re-reconciliation on remote client
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
expect(
|
|
|
|
assert.deepEqual(
|
|
|
|
reconcileElements(
|
|
|
|
reconcileElements(
|
|
|
|
cloneJSON(_remote),
|
|
|
|
cloneJSON(_remote),
|
|
|
|
cloneJSON(reconciled as unknown as RemoteExcalidrawElement[]),
|
|
|
|
cloneJSON(reconciled as unknown as RemoteExcalidrawElement[]),
|
|
|
|
{} as AppState,
|
|
|
|
{} as AppState,
|
|
|
|
).map((x) => x.id),
|
|
|
|
).map((x) => x.id),
|
|
|
|
).deep.equal(reconciledIds, "local re-reconciliation");
|
|
|
|
reconciledIds,
|
|
|
|
|
|
|
|
"local re-reconciliation",
|
|
|
|
|
|
|
|
);
|
|
|
|
} catch (error: any) {
|
|
|
|
} catch (error: any) {
|
|
|
|
console.error("local original", _remote);
|
|
|
|
console.error("local original", _remote);
|
|
|
|
console.error("remote reconciled", reconciled);
|
|
|
|
console.error("remote reconciled", reconciled);
|
|
|
@ -309,7 +316,10 @@ describe("elements reconciliation", () => {
|
|
|
|
throw new Error("reconcileElements: duplicate elements found");
|
|
|
|
throw new Error("reconcileElements: duplicate elements found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expect(ret.map((x) => x.id)).to.deep.equal(expected);
|
|
|
|
assert.deepEqual(
|
|
|
|
|
|
|
|
ret.map((x) => x.id),
|
|
|
|
|
|
|
|
expected,
|
|
|
|
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// identical id/version/versionNonce/index
|
|
|
|
// identical id/version/versionNonce/index
|
|
|
|