| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { projectThreadContentPresentation } from "./threadContentPresentation"; |
| 4 | |
| 5 | describe("thread content presentation", () => { |
| 6 | it("renders cached detail while its environment reconnects", () => { |
| 7 | expect( |
| 8 | projectThreadContentPresentation({ |
| 9 | hasDetail: true, |
| 10 | detailError: null, |
| 11 | detailDeleted: false, |
| 12 | connectionState: "reconnecting", |
| 13 | }), |
| 14 | ).toEqual({ kind: "ready" }); |
| 15 | }); |
| 16 | |
| 17 | it("loads missing detail inside the thread screen when connected", () => { |
| 18 | expect( |
| 19 | projectThreadContentPresentation({ |
| 20 | hasDetail: false, |
| 21 | detailError: null, |
| 22 | detailDeleted: false, |
| 23 | connectionState: "connected", |
| 24 | }), |
| 25 | ).toEqual({ kind: "loading" }); |
| 26 | }); |
| 27 | |
| 28 | it("explains uncached detail while disconnected instead of loading forever", () => { |
| 29 | expect( |
| 30 | projectThreadContentPresentation({ |
| 31 | hasDetail: false, |
| 32 | detailError: null, |
| 33 | detailDeleted: false, |
| 34 | connectionState: "error", |
| 35 | }), |
| 36 | ).toEqual({ |
| 37 | kind: "unavailable", |
| 38 | title: "Messages not cached", |
| 39 | detail: "Reconnect this environment to load the conversation.", |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | it("surfaces detail errors before presenting a loading state", () => { |
| 44 | expect( |
| 45 | projectThreadContentPresentation({ |
| 46 | hasDetail: false, |
| 47 | detailError: "The thread stream failed.", |
| 48 | detailDeleted: false, |
| 49 | connectionState: "connected", |
| 50 | }), |
| 51 | ).toEqual({ |
| 52 | kind: "unavailable", |
| 53 | title: "Could not load conversation", |
| 54 | detail: "The thread stream failed.", |
| 55 | }); |
| 56 | }); |
| 57 | }); |