2023-04-05 12:31:58 +00:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
|
|
Delta,
|
|
|
|
ListDiff,
|
|
|
|
Loro,
|
|
|
|
LoroEvent,
|
|
|
|
MapDiff as MapDiff,
|
2023-07-28 18:03:51 +00:00
|
|
|
setPanicHook,
|
2023-04-05 12:31:58 +00:00
|
|
|
TextDiff,
|
|
|
|
} from "../src";
|
|
|
|
|
2023-07-28 18:03:51 +00:00
|
|
|
setPanicHook();
|
2023-04-05 12:31:58 +00:00
|
|
|
describe("Frontiers", () => {
|
|
|
|
it("two clients", () => {
|
|
|
|
const doc = new Loro();
|
|
|
|
const text = doc.getText("text");
|
2023-07-28 18:03:51 +00:00
|
|
|
const txn = doc.txn();
|
|
|
|
text.insert(txn, 0, "0");
|
|
|
|
txn.commit();
|
|
|
|
|
2023-04-05 12:31:58 +00:00
|
|
|
const v0 = doc.frontiers();
|
|
|
|
const docB = new Loro();
|
|
|
|
docB.import(doc.exportFrom());
|
|
|
|
expect(docB.cmpFrontiers(v0)).toBe(0);
|
2023-07-28 18:03:51 +00:00
|
|
|
doc.transact((t) => {
|
|
|
|
text.insert(t, 1, "0");
|
|
|
|
});
|
2023-04-05 12:31:58 +00:00
|
|
|
expect(docB.cmpFrontiers(doc.frontiers())).toBe(-1);
|
|
|
|
const textB = docB.getText("text");
|
2023-07-28 18:03:51 +00:00
|
|
|
docB.transact((t) => {
|
|
|
|
textB.insert(t, 0, "0");
|
|
|
|
});
|
2023-04-05 12:31:58 +00:00
|
|
|
expect(docB.cmpFrontiers(doc.frontiers())).toBe(-1);
|
|
|
|
docB.import(doc.exportFrom());
|
|
|
|
expect(docB.cmpFrontiers(doc.frontiers())).toBe(1);
|
|
|
|
doc.import(docB.exportFrom());
|
|
|
|
expect(docB.cmpFrontiers(doc.frontiers())).toBe(0);
|
|
|
|
});
|
|
|
|
});
|