-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathWorkspaceStatusIndicator.test.tsx
More file actions
144 lines (130 loc) · 5.48 KB
/
WorkspaceStatusIndicator.test.tsx
File metadata and controls
144 lines (130 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import "../../../../tests/ui/dom";
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
import { cleanup, fireEvent, render } from "@testing-library/react";
import { installDom } from "../../../../tests/ui/dom";
import * as WorkspaceStoreModule from "@/browser/stores/WorkspaceStore";
import { formatModelDisplayName } from "@/common/utils/ai/modelDisplay";
import { getModelName } from "@/common/utils/ai/models";
import { WorkspaceStatusIndicator } from "./WorkspaceStatusIndicator";
const FALLBACK_MODEL = "anthropic:claude-sonnet-4-5";
const PENDING_MODEL = "openai:gpt-4o-mini";
const PENDING_DISPLAY_NAME = formatModelDisplayName(getModelName(PENDING_MODEL));
function createSidebarState(
overrides: Partial<WorkspaceStoreModule.WorkspaceSidebarState> = {}
): WorkspaceStoreModule.WorkspaceSidebarState {
return {
canInterrupt: false,
isStarting: false,
awaitingUserQuestion: false,
lastAbortReason: null,
currentModel: null,
pendingStreamModel: null,
recencyTimestamp: null,
loadedSkills: [],
skillLoadErrors: [],
agentStatus: undefined,
terminalActiveCount: 0,
terminalSessionCount: 0,
...overrides,
};
}
function renderIndicator(
overrides: Partial<WorkspaceStoreModule.WorkspaceSidebarState> = {},
workspaceId = "workspace"
) {
const state = createSidebarState(overrides);
spyOn(WorkspaceStoreModule, "useWorkspaceSidebarState").mockImplementation(() => state);
const view = render(
<WorkspaceStatusIndicator workspaceId={workspaceId} fallbackModel={FALLBACK_MODEL} />
);
return {
state,
view,
rerender(nextWorkspaceId = workspaceId) {
view.rerender(
<WorkspaceStatusIndicator workspaceId={nextWorkspaceId} fallbackModel={FALLBACK_MODEL} />
);
},
phaseSlot: () => view.container.querySelector("[data-phase-slot]"),
phaseIcon: () => view.container.querySelector("[data-phase-slot] svg"),
modelDisplay: () => view.container.querySelector("[data-model-display]"),
};
}
describe("WorkspaceStatusIndicator", () => {
let cleanupDom: (() => void) | null = null;
beforeEach(() => {
cleanupDom = installDom();
});
afterEach(() => {
cleanup();
cleanupDom?.();
cleanupDom = null;
mock.restore();
});
for (const [name, overrides, spins] of [
[
"keeps unfinished todo status static once the stream is idle",
{ agentStatus: { emoji: "🔄", message: "Run checks" } },
false,
],
[
"keeps refresh-style status animated while a stream is still active",
{ canInterrupt: true, agentStatus: { emoji: "🔄", message: "Run checks" } },
true,
],
] satisfies Array<[string, Partial<WorkspaceStoreModule.WorkspaceSidebarState>, boolean]>) {
test(name, () => {
const { view } = renderIndicator(overrides, name);
const className = view.container.querySelector("svg")?.getAttribute("class") ?? "";
expect(view.container.querySelector("svg")).toBeTruthy();
expect(className.includes("animate-spin")).toBe(spins);
});
}
test("keeps the model label anchored when starting hands off to streaming", () => {
const indicator = renderIndicator(
{ isStarting: true, pendingStreamModel: PENDING_MODEL },
"workspace-phase-shift-starting"
);
expect(indicator.phaseSlot()?.getAttribute("class") ?? "").toContain("w-3");
expect(indicator.phaseSlot()?.getAttribute("class") ?? "").toContain("mr-1.5");
expect(indicator.phaseIcon()?.getAttribute("class") ?? "").toContain("animate-spin");
expect(indicator.modelDisplay()?.textContent ?? "").toContain(PENDING_DISPLAY_NAME);
expect(indicator.view.container.textContent?.toLowerCase()).toContain("starting");
Object.assign(indicator.state, {
isStarting: false,
canInterrupt: true,
currentModel: PENDING_MODEL,
pendingStreamModel: null,
});
indicator.rerender("workspace-phase-shift-streaming");
expect(indicator.phaseSlot()?.getAttribute("class") ?? "").toContain("w-0");
expect(indicator.phaseSlot()?.getAttribute("class") ?? "").toContain("mr-0");
expect(indicator.phaseIcon()?.getAttribute("class") ?? "").not.toContain("animate-spin");
fireEvent.transitionEnd(indicator.phaseSlot()!, { propertyName: "width" });
expect(indicator.phaseSlot()).toBeNull();
expect(indicator.modelDisplay()?.textContent ?? "").toContain(PENDING_DISPLAY_NAME);
expect(indicator.view.container.textContent?.toLowerCase()).toContain("streaming");
});
test("does not leak the collapsed handoff slot after agent status hides it", () => {
const indicator = renderIndicator(
{ isStarting: true, pendingStreamModel: PENDING_MODEL },
"workspace-status-handoff-starting"
);
expect(indicator.phaseSlot()?.getAttribute("class") ?? "").toContain("w-3");
Object.assign(indicator.state, {
isStarting: false,
canInterrupt: true,
currentModel: PENDING_MODEL,
pendingStreamModel: null,
agentStatus: { emoji: "🔄", message: "Run checks" },
});
indicator.rerender("workspace-status-handoff-status");
expect(indicator.phaseSlot()).toBeNull();
expect(indicator.view.container.textContent ?? "").toContain("Run checks");
indicator.state.agentStatus = undefined;
indicator.rerender("workspace-status-handoff-streaming");
expect(indicator.phaseSlot()).toBeNull();
expect(indicator.modelDisplay()?.textContent ?? "").toContain(PENDING_DISPLAY_NAME);
expect(indicator.view.container.textContent?.toLowerCase()).toContain("streaming");
});
});