-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathWorkspaceShell.test.tsx
More file actions
225 lines (188 loc) · 6.27 KB
/
WorkspaceShell.test.tsx
File metadata and controls
225 lines (188 loc) · 6.27 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import "../../../../tests/ui/dom";
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
import { cleanup, render } from "@testing-library/react";
import { installDom } from "../../../../tests/ui/dom";
interface MockWorkspaceState {
loading?: boolean;
isHydratingTranscript?: boolean;
isStreamStarting?: boolean;
messages?: Array<{ id: string }>;
queuedMessage?: { id: string } | null;
}
let cleanupDom: (() => void) | null = null;
let workspaceState: MockWorkspaceState | undefined;
const openTerminalMock = mock(() => Promise.resolve());
const addReviewMock = mock(() => undefined);
// Mock lottie-react before importing WorkspaceShell.
void mock.module("lottie-react", () => ({
__esModule: true,
default: () => <div data-testid="lottie-animation" />,
}));
void mock.module("@/browser/stores/WorkspaceStore", () => ({
useWorkspaceState: () =>
workspaceState
? {
messages: [],
queuedMessage: null,
...workspaceState,
}
: workspaceState,
}));
void mock.module("../ChatPane/ChatPane", () => ({
ChatPane: (props: { workspaceId: string }) => (
<div data-testid="chat-pane">Chat pane for {props.workspaceId}</div>
),
}));
void mock.module("@/browser/features/RightSidebar/RightSidebar", () => ({
RightSidebar: () => <div data-testid="right-sidebar" />,
}));
void mock.module("@/browser/contexts/ThemeContext", () => ({
useTheme: () => ({ theme: "dark" }),
}));
void mock.module("@/browser/contexts/BackgroundBashContext", () => ({
useBackgroundBashError: () => ({
error: null,
clearError: () => undefined,
showError: () => undefined,
}),
}));
void mock.module("@/browser/hooks/useOpenTerminal", () => ({
useOpenTerminal: () => openTerminalMock,
}));
void mock.module("@/browser/hooks/useReviews", () => ({
useReviews: () => ({
addReview: addReviewMock,
}),
}));
void mock.module("../ConnectionStatusToast/ConnectionStatusToast", () => ({
ConnectionStatusToast: () => null,
}));
import { WorkspaceShell, estimateWorkspaceShellFallbackWidthPx } from "./WorkspaceShell";
const defaultProps = {
workspaceId: "workspace-1",
projectPath: "/projects/demo",
projectName: "demo",
workspaceName: "feature-branch",
namedWorkspacePath: "/projects/demo/workspaces/feature-branch",
leftSidebarCollapsed: false,
onToggleLeftSidebarCollapsed: () => undefined,
};
describe("estimateWorkspaceShellFallbackWidthPx", () => {
it("subtracts the expanded left sidebar width from the viewport fallback", () => {
expect(
estimateWorkspaceShellFallbackWidthPx({
viewportWidthPx: 1440,
isStacked: false,
leftSidebarCollapsed: false,
persistedLeftSidebarWidthPx: 360,
})
).toBe(1080);
});
it("uses the collapsed sidebar width when the left sidebar is hidden", () => {
expect(
estimateWorkspaceShellFallbackWidthPx({
viewportWidthPx: 1440,
isStacked: false,
leftSidebarCollapsed: true,
persistedLeftSidebarWidthPx: 360,
})
).toBe(1420);
});
it("falls back to the default left sidebar width for malformed persisted values", () => {
expect(
estimateWorkspaceShellFallbackWidthPx({
viewportWidthPx: 1440,
isStacked: false,
leftSidebarCollapsed: false,
persistedLeftSidebarWidthPx: { bad: true },
})
).toBe(1152);
});
it("leaves stacked layouts at full viewport width", () => {
expect(
estimateWorkspaceShellFallbackWidthPx({
viewportWidthPx: 700,
isStacked: true,
leftSidebarCollapsed: false,
persistedLeftSidebarWidthPx: 360,
})
).toBe(700);
});
});
describe("WorkspaceShell loading placeholders", () => {
beforeEach(() => {
cleanupDom = installDom();
workspaceState = undefined;
});
afterEach(() => {
cleanup();
mock.restore();
cleanupDom?.();
cleanupDom = null;
workspaceState = undefined;
openTerminalMock.mockClear();
addReviewMock.mockClear();
});
it("keeps the chat pane mounted during hydration in web mode", () => {
workspaceState = {
isHydratingTranscript: true,
loading: false,
};
const view = render(<WorkspaceShell {...defaultProps} />);
expect(view.queryByText("Catching up with the agent...")).toBeNull();
expect(view.getByTestId("chat-pane")).toBeTruthy();
});
it("keeps the chat pane mounted during initial web workspace loading", () => {
workspaceState = {
loading: true,
isHydratingTranscript: true,
isStreamStarting: false,
};
const view = render(<WorkspaceShell {...defaultProps} />);
expect(view.queryByText("Loading workspace...")).toBeNull();
expect(view.getByTestId("chat-pane")).toBeTruthy();
});
it("keeps cached transcript content visible during web hydration", () => {
workspaceState = {
isHydratingTranscript: true,
isStreamStarting: false,
loading: false,
messages: [{ id: "message-1" }],
queuedMessage: null,
};
const view = render(<WorkspaceShell {...defaultProps} />);
expect(view.queryByText("Catching up with the agent...")).toBeNull();
expect(view.getByTestId("chat-pane")).toBeTruthy();
});
it("keeps the same chat pane DOM node across workspace switches", () => {
workspaceState = {
isHydratingTranscript: false,
isStreamStarting: false,
loading: false,
messages: [{ id: "message-1" }],
queuedMessage: null,
};
const view = render(<WorkspaceShell {...defaultProps} />);
const firstChatPane = view.getByTestId("chat-pane");
view.rerender(
<WorkspaceShell
{...defaultProps}
workspaceId="workspace-2"
workspaceName="feature-two"
namedWorkspacePath="/projects/demo/workspaces/feature-two"
/>
);
const secondChatPane = view.getByTestId("chat-pane");
expect(secondChatPane).toBe(firstChatPane);
expect(secondChatPane.textContent).toContain("workspace-2");
});
it("renders loading animation during non-hydrating workspace loading", () => {
workspaceState = {
loading: true,
isHydratingTranscript: false,
};
const view = render(<WorkspaceShell {...defaultProps} />);
expect(view.getByText("Loading workspace...")).toBeTruthy();
expect(view.getByTestId("lottie-animation")).toBeTruthy();
});
});