The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | isShowcaseThemeApplied, |
| 5 | showcaseReadinessKey, |
| 6 | showcaseSceneOnScreen, |
| 7 | shouldNavigateToShowcaseScene, |
| 8 | type ShowcaseReadinessInput, |
| 9 | } from "./showcaseCaptureModel"; |
| 10 | |
| 11 | const ready: ShowcaseReadinessInput = { |
| 12 | scene: "thread", |
| 13 | requestedScene: "thread", |
| 14 | hasFixture: true, |
| 15 | orientationSettled: true, |
| 16 | themeApplied: true, |
| 17 | agentActivityStaged: false, |
| 18 | themeId: "t3-code", |
| 19 | renderSignal: null, |
| 20 | renderReports: 0, |
| 21 | }; |
| 22 | |
| 23 | describe("showcaseSceneOnScreen", () => { |
| 24 | it("treats the threads list as the agent activity scene only when that scene is requested", () => { |
| 25 | expect(showcaseSceneOnScreen("agent-activity", "/")).toBe("agent-activity"); |
| 26 | expect(showcaseSceneOnScreen("threads", "/")).toBe("threads"); |
| 27 | expect(showcaseSceneOnScreen("agent-activity", "/threads/env/thread")).toBe("thread"); |
| 28 | expect(showcaseSceneOnScreen(null, "/threads/env/thread/review?x=1")).toBe("review"); |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | describe("isShowcaseThemeApplied", () => { |
| 33 | it("waits for the launch request when no theme is requested", () => { |
| 34 | const themeIds = { light: "t3-code", dark: "t3-code" } as const; |
| 35 | expect( |
| 36 | isShowcaseThemeApplied({ launchRequestRead: false, requestedTheme: null, themeIds }), |
| 37 | ).toBe(false); |
| 38 | expect( |
| 39 | isShowcaseThemeApplied({ launchRequestRead: true, requestedTheme: null, themeIds }), |
| 40 | ).toBe(true); |
| 41 | }); |
| 42 | |
| 43 | it("requires both appearances to use the requested theme", () => { |
| 44 | expect( |
| 45 | isShowcaseThemeApplied({ |
| 46 | launchRequestRead: true, |
| 47 | requestedTheme: "t3-code", |
| 48 | themeIds: { light: "t3-code", dark: "material-you" }, |
| 49 | }), |
| 50 | ).toBe(false); |
| 51 | }); |
| 52 | }); |
| 53 | |
| 54 | describe("showcaseReadinessKey", () => { |
| 55 | it("is null until every precondition holds", () => { |
| 56 | expect(showcaseReadinessKey(ready)).not.toBeNull(); |
| 57 | expect(showcaseReadinessKey({ ...ready, requestedScene: "terminal" })).toBeNull(); |
| 58 | expect(showcaseReadinessKey({ ...ready, hasFixture: false })).toBeNull(); |
| 59 | expect(showcaseReadinessKey({ ...ready, orientationSettled: false })).toBeNull(); |
| 60 | expect(showcaseReadinessKey({ ...ready, themeApplied: false })).toBeNull(); |
| 61 | }); |
| 62 | |
| 63 | it("waits for agent activity to be staged", () => { |
| 64 | const agentActivity = { |
| 65 | ...ready, |
| 66 | scene: "agent-activity", |
| 67 | requestedScene: "agent-activity", |
| 68 | } as const; |
| 69 | expect(showcaseReadinessKey(agentActivity)).toBeNull(); |
| 70 | expect(showcaseReadinessKey({ ...agentActivity, agentActivityStaged: true })).not.toBeNull(); |
| 71 | }); |
| 72 | |
| 73 | it("waits for review to report a draw in the current theme, and changes key when it redraws", () => { |
| 74 | const review = { ...ready, scene: "review", requestedScene: "review" } as const; |
| 75 | expect(showcaseReadinessKey(review)).toBeNull(); |
| 76 | expect( |
| 77 | showcaseReadinessKey({ |
| 78 | ...review, |
| 79 | renderSignal: { scene: "review", themeId: "material-you" }, |
| 80 | }), |
| 81 | ).toBeNull(); |
| 82 | const drawn = { ...review, renderSignal: { scene: "review", themeId: "t3-code" } } as const; |
| 83 | const firstDraw = showcaseReadinessKey({ ...drawn, renderReports: 1 }); |
| 84 | expect(firstDraw).not.toBeNull(); |
| 85 | expect(showcaseReadinessKey({ ...drawn, renderReports: 2 })).not.toBe(firstDraw); |
| 86 | }); |
| 87 | }); |
| 88 | |
| 89 | describe("shouldNavigateToShowcaseScene", () => { |
| 90 | it("dispatches again when the thread shell changes while the scene is still not on screen", () => { |
| 91 | const shell = { id: "remote-command-center" }; |
| 92 | const first = { requestedScene: "review", scene: "threads", thread: shell } as const; |
| 93 | expect(shouldNavigateToShowcaseScene(null, first)).toBe(true); |
| 94 | expect(shouldNavigateToShowcaseScene(first, { ...first })).toBe(false); |
| 95 | expect(shouldNavigateToShowcaseScene(first, { ...first, thread: { ...shell } })).toBe(true); |
| 96 | expect(shouldNavigateToShowcaseScene(first, { ...first, scene: "thread" })).toBe(true); |
| 97 | expect(shouldNavigateToShowcaseScene(first, { ...first, scene: "review" })).toBe(false); |
| 98 | }); |
| 99 | }); |