From eed7340663ea3ec9d66a7333e1c70197bfe4b95e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 19 Jan 2023 15:02:48 +0000 Subject: [PATCH] Add additional tests --- test/SlidingSyncManager-test.ts | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/SlidingSyncManager-test.ts b/test/SlidingSyncManager-test.ts index 132ad769ea..6b5a854e84 100644 --- a/test/SlidingSyncManager-test.ts +++ b/test/SlidingSyncManager-test.ts @@ -78,6 +78,69 @@ describe("SlidingSyncManager", () => { }); }); + describe("ensureListRegistered", () => { + it("creates a new list based on the key", async () => { + const listKey = "key"; + mocked(slidingSync.getListParams).mockReturnValue(null); + mocked(slidingSync.setList).mockResolvedValue("yep"); + await manager.ensureListRegistered(listKey, { + sort: ["by_recency"], + }); + expect(slidingSync.setList).toBeCalledWith( + listKey, + expect.objectContaining({ + sort: ["by_recency"], + }), + ); + }); + + it("updates an existing list based on the key", async () => { + const listKey = "key"; + mocked(slidingSync.getListParams).mockReturnValue({ + ranges: [[0, 42]], + }); + mocked(slidingSync.setList).mockResolvedValue("yep"); + await manager.ensureListRegistered(listKey, { + sort: ["by_recency"], + }); + expect(slidingSync.setList).toBeCalledWith( + listKey, + expect.objectContaining({ + sort: ["by_recency"], + ranges: [[0, 42]], + }), + ); + }); + + it("updates ranges on an existing list based on the key if there's no other changes", async () => { + const listKey = "key"; + mocked(slidingSync.getListParams).mockReturnValue({ + ranges: [[0, 42]], + }); + mocked(slidingSync.setList).mockResolvedValue("yep"); + await manager.ensureListRegistered(listKey, { + ranges: [[0, 52]], + }); + expect(slidingSync.setList).not.toBeCalled(); + expect(slidingSync.setListRanges).toBeCalledWith(listKey, [[0, 52]]); + }); + + it("no-ops for idential changes", async () => { + const listKey = "key"; + mocked(slidingSync.getListParams).mockReturnValue({ + ranges: [[0, 42]], + sort: ["by_recency"], + }); + mocked(slidingSync.setList).mockResolvedValue("yep"); + await manager.ensureListRegistered(listKey, { + ranges: [[0, 42]], + sort: ["by_recency"], + }); + expect(slidingSync.setList).not.toBeCalled(); + expect(slidingSync.setListRanges).not.toBeCalled(); + }); + }); + describe("startSpidering", () => { it("requests in batchSizes", async () => { const gapMs = 1;