|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { LoroDoc } from "loro-crdt"; |
| 3 | +import { diffContainer } from "../../src/core/diff"; |
| 4 | +import { schema } from "../../src/schema"; |
| 5 | + |
| 6 | +describe("diffMap equality for falsy primitives", () => { |
| 7 | + it("does not emit changes when string field stays ''", () => { |
| 8 | + const doc = new LoroDoc(); |
| 9 | + // Ensure the container exists (name must match schema field) |
| 10 | + doc.getMap("profile"); |
| 11 | + |
| 12 | + const rootSchema = schema({ |
| 13 | + profile: schema.LoroMap({ |
| 14 | + bio: schema.String(), |
| 15 | + }), |
| 16 | + }); |
| 17 | + |
| 18 | + const oldState = { profile: { bio: "" } } as const; |
| 19 | + const newState = { profile: { bio: "" } } as const; |
| 20 | + |
| 21 | + const changes = diffContainer(doc, oldState, newState, "", rootSchema); |
| 22 | + expect(changes.length).toBe(0); |
| 23 | + }); |
| 24 | + |
| 25 | + it("does not emit changes when field stays null", () => { |
| 26 | + const doc = new LoroDoc(); |
| 27 | + doc.getMap("profile"); |
| 28 | + |
| 29 | + const rootSchema = schema({ |
| 30 | + profile: schema.LoroMap({ |
| 31 | + note: schema.String(), |
| 32 | + }), |
| 33 | + }); |
| 34 | + |
| 35 | + const oldState = { profile: { note: null } } as const; |
| 36 | + const newState = { profile: { note: null } } as const; |
| 37 | + |
| 38 | + const changes = diffContainer(doc, oldState, newState, "", rootSchema); |
| 39 | + expect(changes.length).toBe(0); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
0 commit comments