| ... | ... | @@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | 4 | import { |
| 5 | 5 | clearThreadUi, |
| 6 | 6 | hydratePersistedProjectState, |
| 7 | markThreadVisited, |
| 7 | 8 | markThreadUnread, |
| 8 | 9 | PERSISTED_STATE_KEY, |
| 9 | 10 | type PersistedUiState, |
| ... | ... | @@ -27,6 +28,28 @@ function makeUiState(overrides: Partial<UiState> = {}): UiState { |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | describe("uiStateStore pure functions", () => { |
| 31 | it("markThreadVisited stores the provided server timestamp", () => { |
| 32 | const threadId = ThreadId.make("thread-1"); |
| 33 | const initialState = makeUiState(); |
| 34 | |
| 35 | const next = markThreadVisited(initialState, threadId, "2026-02-25T12:30:00.700Z"); |
| 36 | |
| 37 | expect(next.threadLastVisitedAtById[threadId]).toBe("2026-02-25T12:30:00.700Z"); |
| 38 | }); |
| 39 | |
| 40 | it("markThreadVisited does not move visit state backwards under clock skew", () => { |
| 41 | const threadId = ThreadId.make("thread-1"); |
| 42 | const initialState = makeUiState({ |
| 43 | threadLastVisitedAtById: { |
| 44 | [threadId]: "2026-02-25T12:30:00.700Z", |
| 45 | }, |
| 46 | }); |
| 47 | |
| 48 | const next = markThreadVisited(initialState, threadId, "2026-02-25T12:30:00.000Z"); |
| 49 | |
| 50 | expect(next).toBe(initialState); |
| 51 | }); |
| 52 | |
| 30 | 53 | it("markThreadUnread moves lastVisitedAt before completion for a completed thread", () => { |
| 31 | 54 | const threadId = ThreadId.make("thread-1"); |
| 32 | 55 | const latestTurnCompletedAt = "2026-02-25T12:30:00.000Z"; |