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)));