| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { threadRouteIsHydrating } from "./thread-route-hydration"; |
| 4 | |
| 5 | const settled = { |
| 6 | isLoadingConnections: false, |
| 7 | connectionState: "connected" as const, |
| 8 | shellStatus: "live" as const, |
| 9 | shellHasError: false, |
| 10 | detailStatus: "live" as const, |
| 11 | detailHasError: false, |
| 12 | }; |
| 13 | |
| 14 | describe("threadRouteIsHydrating", () => { |
| 15 | it("waits for shell and thread detail hydration", () => { |
| 16 | expect(threadRouteIsHydrating({ ...settled, shellStatus: "synchronizing" })).toBe(true); |
| 17 | expect(threadRouteIsHydrating({ ...settled, shellStatus: "empty" })).toBe(true); |
| 18 | expect(threadRouteIsHydrating({ ...settled, detailStatus: "synchronizing" })).toBe(true); |
| 19 | expect(threadRouteIsHydrating({ ...settled, detailStatus: "empty" })).toBe(true); |
| 20 | }); |
| 21 | |
| 22 | it("stops waiting once an empty detail has an actionable outcome", () => { |
| 23 | expect( |
| 24 | threadRouteIsHydrating({ |
| 25 | ...settled, |
| 26 | shellStatus: "empty", |
| 27 | shellHasError: true, |
| 28 | detailStatus: "deleted", |
| 29 | }), |
| 30 | ).toBe(false); |
| 31 | expect( |
| 32 | threadRouteIsHydrating({ |
| 33 | ...settled, |
| 34 | detailStatus: "empty", |
| 35 | detailHasError: true, |
| 36 | }), |
| 37 | ).toBe(false); |
| 38 | expect( |
| 39 | threadRouteIsHydrating({ |
| 40 | ...settled, |
| 41 | connectionState: "available", |
| 42 | detailStatus: "empty", |
| 43 | }), |
| 44 | ).toBe(false); |
| 45 | expect(threadRouteIsHydrating({ ...settled, detailStatus: "deleted" })).toBe(false); |
| 46 | }); |
| 47 | |
| 48 | it("prioritizes terminal outcomes over unrelated hydration", () => { |
| 49 | expect( |
| 50 | threadRouteIsHydrating({ |
| 51 | ...settled, |
| 52 | connectionState: "reconnecting", |
| 53 | shellStatus: "synchronizing", |
| 54 | detailStatus: "deleted", |
| 55 | }), |
| 56 | ).toBe(false); |
| 57 | expect( |
| 58 | threadRouteIsHydrating({ |
| 59 | ...settled, |
| 60 | connectionState: "reconnecting", |
| 61 | shellStatus: "synchronizing", |
| 62 | detailHasError: true, |
| 63 | }), |
| 64 | ).toBe(false); |
| 65 | expect( |
| 66 | threadRouteIsHydrating({ |
| 67 | ...settled, |
| 68 | connectionState: "offline", |
| 69 | shellStatus: "synchronizing", |
| 70 | detailStatus: "synchronizing", |
| 71 | }), |
| 72 | ).toBe(false); |
| 73 | }); |
| 74 | }); |