From 826e7fdcb372d04b789c36875fbf5718cd348afb Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 20 Nov 2023 17:44:24 +0800 Subject: [PATCH] test: add import via frontiers test --- loro-js/tests/basic.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/loro-js/tests/basic.test.ts b/loro-js/tests/basic.test.ts index fea7e0a0..0d20dcef 100644 --- a/loro-js/tests/basic.test.ts +++ b/loro-js/tests/basic.test.ts @@ -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");