Skip to content

Commit ae97f1d

Browse files
committed
add apply cancellation test
1 parent a2879d1 commit ae97f1d

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

core/edit/recursiveStream.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export async function* recursiveStream(
6868
});
6969

7070
for await (const chunk of generator) {
71-
console.log(chunk);
7271
yield chunk;
7372
const rendered = renderChatMessage(chunk);
7473
buffer += rendered;

gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { AnimatedEllipsis } from "../../..";
22

33
export function GeneratingIndicator({
44
text = "Generating",
5+
testId,
56
}: {
67
text?: string;
8+
testId?: string;
79
}) {
810
return (
9-
<div className="text-description-muted text-xs">
11+
<div className="text-description-muted text-xs" data-testid={testId}>
1012
<span>{text}</span>
1113
<AnimatedEllipsis />
1214
</div>

gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ export const IsApplyingToolbar = () => {
1313

1414
return (
1515
<Container>
16-
<GeneratingIndicator text="Applying" />
16+
<GeneratingIndicator text="Applying" testId={"notch-applying-text"} />
1717
<StopButton
18+
data-testid="notch-applying-cancel-button"
1819
className="text-description"
1920
onClick={() => {
2021
// Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option
2122
// Apply is prioritized because it can be more catastrophic
2223
// Intentional to be more WYSIWYG for now
2324
// Keyboard shortcut is handled in chat
24-
dispatch(cancelStream());
25+
void dispatch(cancelStream());
2526
ideMessenger.post("rejectDiff", {});
2627
}}
2728
>

gui/src/pages/gui/Chat.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,56 @@ describe("Chat page test", () => {
106106
).not.toBeInTheDocument();
107107
});
108108
});
109+
110+
it("should show apply cancellation", async () => {
111+
const { ideMessenger } = await renderWithProviders(<Chat />);
112+
113+
// Spy on the request method of ideMessenger
114+
const messengerPostSpy = vi.spyOn(ideMessenger, "post");
115+
116+
for (let i = 0; i < 5; i++) {
117+
ideMessenger.mockMessageToWebview("updateApplyState", {
118+
status: "streaming",
119+
streamId: `12345`,
120+
});
121+
}
122+
123+
// Wait for applying toolbar to appear
124+
await waitFor(() => {
125+
const cancelApplyButton = screen.getByTestId(
126+
"notch-applying-cancel-button",
127+
);
128+
const applyingText = screen.getByTestId("notch-applying-text");
129+
130+
expect(cancelApplyButton).toBeInTheDocument();
131+
expect(applyingText).toBeInTheDocument();
132+
});
133+
134+
const cancelApplyButton = screen.getByTestId(
135+
"notch-applying-cancel-button",
136+
);
137+
cancelApplyButton.click();
138+
139+
// Verify that rejectDiff message has been posted to ideMessenger
140+
expect(messengerPostSpy).toHaveBeenCalledWith("rejectDiff", {});
141+
142+
// Now simulate the IDE sending back a message that the apply state is closed
143+
ideMessenger.mockMessageToWebview("updateApplyState", {
144+
status: "closed",
145+
streamId: "12345",
146+
});
147+
148+
await waitFor(() => {
149+
const cancelApplyButton = screen.queryByTestId(
150+
"notch-applying-cancel-button",
151+
);
152+
const applyingText = screen.queryByTestId("notch-applying-text");
153+
154+
expect(cancelApplyButton).not.toBeInTheDocument();
155+
expect(applyingText).not.toBeInTheDocument();
156+
});
157+
158+
// Cleanup spy
159+
messengerPostSpy.mockRestore();
160+
});
109161
});

0 commit comments

Comments
 (0)