Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions src/__tests__/features/opds/useOfflineLibraryState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@ describe("useOfflineLibraryState", () => {
});
});

describe("refreshLibrarySnapshot", () => {
it("surfaces a listing failure through notifyOpdsError and does not throw", async () => {
mockList.mockRejectedValue(new Error("Snapshot read failed"));

renderOfflineState();
await waitFor(() => {
expect(mockNotify).toHaveBeenCalledTimes(1);
});

expect(mockNotify).toHaveBeenCalledWith(
expect.objectContaining({ message: "Snapshot read failed" }),
{
context: "Offline library",
fallback: "Failed to load the offline library",
},
);
});

it("updates the snapshot and does not toast on success, preserving prior state on failure", async () => {
const { result } = renderOfflineState();
await waitFor(() => {
expect(mockList).toHaveBeenCalledTimes(1);
});

expect(result.current.libraryInfoByPublicationId["book-1"]?.primary?.revision_id).toBe(11);
expect(mockNotify).not.toHaveBeenCalled();

result.current.refreshLibrarySnapshot();
await waitFor(() => {
expect(mockList).toHaveBeenCalledTimes(2);
});

expect(result.current.libraryInfoByPublicationId["book-1"]?.primary?.revision_id).toBe(11);
expect(mockNotify).not.toHaveBeenCalled();
});
});

describe("handleDeleteLocal", () => {
it("surfaces the failure through notifyOpdsError and keeps the record visible", async () => {
mockDeleteContent.mockRejectedValue(new Error("Permission denied"));
Expand Down
7 changes: 6 additions & 1 deletion src/features/opds/useOfflineLibraryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export function useOfflineLibraryState({
try {
const snapshot = await offlineLibraryClient.list();
setLibraryInfoByPublicationId(buildPublicationLibraryInfo(snapshot));
} catch {}
} catch (error) {
notifyOpdsError(error, {
context: "Offline library",
fallback: "Failed to load the offline library",
});
}
}, []);

useEffect(() => {
Expand Down
Loading