mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-11 06:42:21 +00:00
test(js): update signature for map set container
This commit is contained in:
parent
66d74c1e74
commit
a68482a495
5 changed files with 33 additions and 10 deletions
|
@ -7,6 +7,7 @@
|
|||
"test": "cargo nextest run --features=test_utils",
|
||||
"test-all": "deno task test & deno task quick-fuzz & deno task test-wasm",
|
||||
"test-wasm": "cd crates/loro-wasm && deno task dev && cd ../../loro-js && pnpm i && pnpm run test",
|
||||
"release-wasm": "cd crates/loro-wasm && deno task release && cd ../../loro-js && pnpm i && pnpm run test",
|
||||
"check": "cargo clippy --all-features",
|
||||
"quick-fuzz": "cd crates/loro-internal && deno task quick-fuzz",
|
||||
"fix": "cargo clippy --fix --features=test_utils",
|
||||
|
|
|
@ -112,10 +112,10 @@ declare module "loro-wasm" {
|
|||
}
|
||||
|
||||
interface LoroMap<T extends Record<string, any> = Record<string, any>> {
|
||||
insertContainer(key: string, container_type: "Map"): LoroMap;
|
||||
insertContainer(key: string, container_type: "List"): LoroList;
|
||||
insertContainer(key: string, container_type: "Text"): LoroText;
|
||||
insertContainer(key: string, container_type: string): never;
|
||||
setContainer(key: string, container_type: "Map"): LoroMap;
|
||||
setContainer(key: string, container_type: "List"): LoroList;
|
||||
setContainer(key: string, container_type: "Text"): LoroText;
|
||||
setContainer(key: string, container_type: string): never;
|
||||
|
||||
get(key: string): Value;
|
||||
getTyped<Key extends keyof T & string>(txn: Loro, key: Key): T[Key];
|
||||
|
|
|
@ -22,3 +22,25 @@ describe("list", () => {
|
|||
|
||||
it.todo("iterate");
|
||||
})
|
||||
|
||||
describe("import", () => {
|
||||
it('pending', () => {
|
||||
const a = new Loro();
|
||||
a.getText("text").insert(0, "a");
|
||||
const b = new Loro();
|
||||
b.import(a.exportFrom());
|
||||
b.getText("text").insert(1, "b");
|
||||
const c = new Loro();
|
||||
c.import(b.exportFrom());
|
||||
c.getText("text").insert(2, "c");
|
||||
|
||||
// c export from b's version, which cannot be imported directly to a.
|
||||
// This operation is pending.
|
||||
a.import(c.exportFrom(b.version()))
|
||||
expect(a.getText("text").toString()).toBe("a");
|
||||
|
||||
// a import the missing ops from b. It makes the pending operation from c valid.
|
||||
a.import(b.exportFrom(a.version()))
|
||||
expect(a.getText("text").toString()).toBe("abc");
|
||||
})
|
||||
})
|
||||
|
|
|
@ -31,12 +31,12 @@ describe("event", () => {
|
|||
lastEvent = event;
|
||||
});
|
||||
const map = loro.getMap("map");
|
||||
const subMap = map.insertContainer("sub", "Map");
|
||||
const subMap = map.setContainer("sub", "Map");
|
||||
subMap.set("0", "1");
|
||||
loro.commit();
|
||||
|
||||
expect(lastEvent?.path).toStrictEqual(["map", "sub"]);
|
||||
const list = subMap.insertContainer("list", "List");
|
||||
const list = subMap.setContainer("list", "List");
|
||||
list.insert(0, "2");
|
||||
const text = list.insertContainer(1, "Text");
|
||||
loro.commit();
|
||||
|
@ -155,10 +155,10 @@ describe("event", () => {
|
|||
times += 1;
|
||||
});
|
||||
|
||||
const subMap = map.insertContainer("sub", "Map");
|
||||
const subMap = map.setContainer("sub", "Map");
|
||||
loro.commit();
|
||||
expect(times).toBe(1);
|
||||
const text = subMap.insertContainer("k", "Text");
|
||||
const text = subMap.setContainer("k", "Text");
|
||||
loro.commit();
|
||||
expect(times).toBe(2);
|
||||
text.insert(0, "123");
|
||||
|
|
|
@ -250,7 +250,7 @@ describe("wasm", () => {
|
|||
b.set("ab", 123);
|
||||
loro.commit();
|
||||
|
||||
const bText = b.insertContainer("hh", "Text");
|
||||
const bText = b.setContainer("hh", "Text");
|
||||
loro.commit();
|
||||
|
||||
it("map get", () => {
|
||||
|
@ -284,7 +284,7 @@ describe("type", () => {
|
|||
it("test recursive map type", () => {
|
||||
const loro = new Loro<{ map: LoroMap<{ map: LoroMap<{ name: "he" }> }> }>();
|
||||
const map = loro.getTypedMap("map");
|
||||
map.insertContainer("map", "Map");
|
||||
map.setContainer("map", "Map");
|
||||
|
||||
const subMap = map.getTyped(loro, "map");
|
||||
const name = subMap.getTyped(loro, "name");
|
||||
|
|
Loading…
Reference in a new issue