test: add import via frontiers test

This commit is contained in:
Zixuan Chen 2023-11-20 17:44:24 +08:00
parent b940214985
commit 826e7fdcb3
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { ContainerID, Loro, LoroList, LoroMap, setPanicHook } from "../src";
import { ContainerID, Loro, LoroList, LoroMap, setPanicHook, toEncodedVersion } from "../src";
setPanicHook();
@ -130,6 +130,18 @@ describe("import", () => {
expect(a.getText("text").toString()).toBe("abc");
});
it("import by frontiers", () => {
const a = new Loro();
a.getText("text").insert(0, "a");
const b = new Loro();
b.import(a.exportFrom());
b.getText("text").insert(1, "b");
b.getList("list").insert(0, [1, 2]);
const updates = b.exportFrom(toEncodedVersion(b.frontiersToVV(a.frontiers())));
a.import(updates);
expect(a.toJson()).toStrictEqual(b.toJson());
});
it("from snapshot", () => {
const a = new Loro();
a.getText("text").insert(0, "hello");