The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { MessageId, RunId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | import { observeTimelineRun, resolveDisclosureRevealScrollDelta } from "./timelineScrollAnchoring"; |
| 4 | |
| 5 | describe("observeTimelineRun", () => { |
| 6 | const existing = { |
| 7 | threadKey: "environment:thread", |
| 8 | hydrated: true, |
| 9 | runId: RunId.make("existing-run"), |
| 10 | queued: false, |
| 11 | messageId: MessageId.make("existing-message"), |
| 12 | }; |
| 13 | const next = { |
| 14 | ...existing, |
| 15 | runId: RunId.make("new-run"), |
| 16 | messageId: MessageId.make("new-message"), |
| 17 | }; |
| 18 | |
| 19 | it("does not mistake delayed hydration for a newly started turn", () => { |
| 20 | const loading = { ...existing, hydrated: false, runId: null, messageId: null }; |
| 21 | const opened = observeTimelineRun(null, loading); |
| 22 | const stillLoading = observeTimelineRun(opened.observation, loading); |
| 23 | const hydrated = observeTimelineRun(stillLoading.observation, existing); |
| 24 | expect(hydrated.anchorMessageId).toBeNull(); |
| 25 | expect(observeTimelineRun(hydrated.observation, next).anchorMessageId).toBe(next.messageId); |
| 26 | }); |
| 27 | |
| 28 | it("keeps the end position while a stale cached run is replaced during synchronization", () => { |
| 29 | const cached = observeTimelineRun(null, { ...existing, hydrated: false }); |
| 30 | const synchronizing = observeTimelineRun(cached.observation, { ...next, hydrated: false }); |
| 31 | expect(synchronizing.anchorMessageId).toBeNull(); |
| 32 | const live = observeTimelineRun(synchronizing.observation, next); |
| 33 | expect(live.anchorMessageId).toBeNull(); |
| 34 | expect( |
| 35 | observeTimelineRun(live.observation, { |
| 36 | ...next, |
| 37 | runId: RunId.make("later-run"), |
| 38 | messageId: MessageId.make("later-message"), |
| 39 | }).anchorMessageId, |
| 40 | ).toBe("later-message"); |
| 41 | }); |
| 42 | |
| 43 | it("waits for a new run's user message and frames it only once", () => { |
| 44 | const opened = observeTimelineRun(null, existing); |
| 45 | const waiting = observeTimelineRun(opened.observation, { ...next, messageId: null }); |
| 46 | expect(waiting.anchorMessageId).toBeNull(); |
| 47 | const ready = observeTimelineRun(waiting.observation, next); |
| 48 | expect(ready.anchorMessageId).toBe(next.messageId); |
| 49 | expect(observeTimelineRun(ready.observation, next).anchorMessageId).toBeNull(); |
| 50 | }); |
| 51 | |
| 52 | it("does not reset the baseline during a temporary loss of projection data", () => { |
| 53 | const opened = observeTimelineRun(null, existing); |
| 54 | const reconnecting = observeTimelineRun(opened.observation, { |
| 55 | ...existing, |
| 56 | hydrated: false, |
| 57 | runId: null, |
| 58 | }); |
| 59 | expect(observeTimelineRun(reconnecting.observation, existing).anchorMessageId).toBeNull(); |
| 60 | }); |
| 61 | |
| 62 | it("waits for a queued run to start before framing it", () => { |
| 63 | const opened = observeTimelineRun(null, { ...existing, queued: true }); |
| 64 | expect(opened.anchorMessageId).toBeNull(); |
| 65 | expect(observeTimelineRun(opened.observation, existing).anchorMessageId).toBe( |
| 66 | existing.messageId, |
| 67 | ); |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | describe("resolveDisclosureRevealScrollDelta", () => { |
| 72 | const viewport = { |
| 73 | viewportTop: 0, |
| 74 | viewportBottom: 800, |
| 75 | composerOverlayHeight: 150, |
| 76 | anchorOffset: 24, |
| 77 | }; |
| 78 | |
| 79 | it("does not scroll when the expanded row ends above the composer", () => { |
| 80 | expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 300, rowBottom: 650 })).toBe( |
| 81 | 0, |
| 82 | ); |
| 83 | }); |
| 84 | |
| 85 | it("scrolls content hidden behind the composer into view", () => { |
| 86 | expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 560, rowBottom: 900 })).toBe( |
| 87 | 250, |
| 88 | ); |
| 89 | }); |
| 90 | |
| 91 | it("keeps the header of a row taller than the usable viewport visible", () => { |
| 92 | expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: 600, rowBottom: 2000 })).toBe( |
| 93 | 576, |
| 94 | ); |
| 95 | }); |
| 96 | |
| 97 | it("never scrolls backwards when the row header is already above the anchor inset", () => { |
| 98 | expect(resolveDisclosureRevealScrollDelta({ ...viewport, rowTop: -40, rowBottom: 1200 })).toBe( |
| 99 | 0, |
| 100 | ); |
| 101 | }); |
| 102 | }); |