Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/__tests__/features/opds/useOfflineLibraryState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
);
});
});

Expand Down
Loading