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 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-10-20 20:15:05 -04:00
parent a17c1b7604
commit 13dca87d04

View file

@ -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<void>((r) => (written = r)));