From 0df79486ad7634a50f0391617ebd1138b5b4eea3 Mon Sep 17 00:00:00 2001 From: jdluu Date: Sat, 29 Aug 2026 13:38:11 -0700 Subject: [PATCH] test: stabilize offline library snapshot coverage Closes #111 --- .../opds/useOfflineLibraryState.test.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/__tests__/features/opds/useOfflineLibraryState.test.tsx b/src/__tests__/features/opds/useOfflineLibraryState.test.tsx index 0b20942..17695ca 100644 --- a/src/__tests__/features/opds/useOfflineLibraryState.test.tsx +++ b/src/__tests__/features/opds/useOfflineLibraryState.test.tsx @@ -163,22 +163,28 @@ describe("useOfflineLibraryState", () => { ); }); - it("updates the snapshot and does not toast on success, preserving prior state on failure", async () => { + it("updates the snapshot and preserves prior state when a later refresh fails", async () => { const { result } = renderOfflineState(); await waitFor(() => { - expect(mockList).toHaveBeenCalledTimes(1); + expect(result.current.libraryInfoByPublicationId["book-1"]?.primary?.revision_id).toBe(11); }); - expect(result.current.libraryInfoByPublicationId["book-1"]?.primary?.revision_id).toBe(11); expect(mockNotify).not.toHaveBeenCalled(); + mockNotify.mockClear(); + mockList.mockRejectedValueOnce(new Error("Snapshot read failed")); - result.current.refreshLibrarySnapshot(); - await waitFor(() => { - expect(mockList).toHaveBeenCalledTimes(2); + await act(async () => { + await result.current.refreshLibrarySnapshot(); }); expect(result.current.libraryInfoByPublicationId["book-1"]?.primary?.revision_id).toBe(11); - expect(mockNotify).not.toHaveBeenCalled(); + expect(mockNotify).toHaveBeenCalledWith( + expect.objectContaining({ message: "Snapshot read failed" }), + { + context: "Offline library", + fallback: "Failed to load the offline library", + }, + ); }); });