From 13dca87d04026fe554df517a1de474a18c5f218c Mon Sep 17 00:00:00 2001 From: le king fu Date: Tue, 20 Oct 2026 20:15:05 -0400 Subject: [PATCH] test(categories): a failed re-read of the categories shows in the window (#393) Review 25974, suggestion 1 (Q6): the JSDoc, architecture.md and the PR body say a failure of readCategoriesAgain shows in the hierarchy window, and no test held it. The read is rejected once at the opening (the diagnostic does not run on the old categories) and once after a committed reattachment: each time the window shows the message, the page's banner behind it stays empty, and saving is over. Co-Authored-By: Claude Opus 5.5 --- src/hooks/useCategories.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/hooks/useCategories.test.ts b/src/hooks/useCategories.test.ts index 7e47133..b15d2b0 100644 --- a/src/hooks/useCategories.test.ts +++ b/src/hooks/useCategories.test.ts @@ -313,6 +313,32 @@ describe("useCategories — « Vérifier la hiérarchie » (#393)", () => { expect(getAllCategoriesWithCounts).toHaveBeenCalledTimes(3); }); + it("shows a failed read of the categories in the window, never in the page's banner behind it", async () => { + vi.mocked(findOrphanCategories).mockResolvedValueOnce([CYCLE]).mockResolvedValueOnce([]); + vi.mocked(reattachCategory).mockResolvedValue(3); + let api = await mount(); + + // At the opening: the diagnostic does not run on the old categories. + vi.mocked(getAllCategoriesWithCounts).mockRejectedValueOnce(new Error("database is locked")); + await api.checkHierarchy(); + let state = harness.render(useCategories).state; + expect(state.hierarchyCheck).toEqual({ orphans: null, error: { message: "database is locked" } }); + expect(state.error).toBeNull(); + expect(findOrphanCategories).not.toHaveBeenCalled(); + + // After a committed reattachment. + api = harness.render(useCategories); + await api.checkHierarchy(); + api = harness.render(useCategories); + vi.mocked(getAllCategoriesWithCounts).mockRejectedValueOnce(new Error("disk I/O error")); + await api.reattachOrphan(CYCLE, null); + state = harness.render(useCategories).state; + expect(reattachCategory).toHaveBeenCalledWith(3, null); + expect(state.hierarchyCheck).toEqual({ orphans: [], error: { message: "disk I/O error" } }); + expect(state.error).toBeNull(); + expect(state.isSaving).toBe(false); + }); + it("reads the categories once the drag-and-drop's writes are over, never halfway", async () => { let written: () => void = () => undefined; vi.mocked(updateCategorySortOrders).mockReturnValue(new Promise((r) => (written = r)));