mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix browser tab not showing the most recent screenshot (#8389)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
29f3e028e5
commit
507c02e518
62
frontend/__tests__/services/observations.test.tsx
Normal file
62
frontend/__tests__/services/observations.test.tsx
Normal file
@ -0,0 +1,62 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { handleObservationMessage } from "#/services/observations";
|
||||
import { setScreenshotSrc, setUrl } from "#/state/browser-slice";
|
||||
import ObservationType from "#/types/observation-type";
|
||||
import store from "#/store";
|
||||
|
||||
// Mock the store module
|
||||
vi.mock("#/store", () => ({
|
||||
default: {
|
||||
dispatch: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("handleObservationMessage", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it("updates browser state when receiving a browse observation", () => {
|
||||
const message = {
|
||||
id: "test-id",
|
||||
cause: "test-cause",
|
||||
observation: ObservationType.BROWSE,
|
||||
content: "test content",
|
||||
message: "test message",
|
||||
extras: {
|
||||
url: "https://example.com",
|
||||
screenshot: "base64-screenshot-data",
|
||||
},
|
||||
};
|
||||
|
||||
handleObservationMessage(message);
|
||||
|
||||
// Check that setScreenshotSrc and setUrl were called with the correct values
|
||||
expect(store.dispatch).toHaveBeenCalledWith(setScreenshotSrc("base64-screenshot-data"));
|
||||
expect(store.dispatch).toHaveBeenCalledWith(setUrl("https://example.com"));
|
||||
});
|
||||
|
||||
it("updates browser state when receiving a browse_interactive observation", () => {
|
||||
const message = {
|
||||
id: "test-id",
|
||||
cause: "test-cause",
|
||||
observation: ObservationType.BROWSE_INTERACTIVE,
|
||||
content: "test content",
|
||||
message: "test message",
|
||||
extras: {
|
||||
url: "https://example.com",
|
||||
screenshot: "base64-screenshot-data",
|
||||
},
|
||||
};
|
||||
|
||||
handleObservationMessage(message);
|
||||
|
||||
// Check that setScreenshotSrc and setUrl were called with the correct values
|
||||
expect(store.dispatch).toHaveBeenCalledWith(setScreenshotSrc("base64-screenshot-data"));
|
||||
expect(store.dispatch).toHaveBeenCalledWith(setUrl("https://example.com"));
|
||||
});
|
||||
});
|
||||
@ -158,6 +158,13 @@ export function handleObservationMessage(message: ObservationMessage) {
|
||||
);
|
||||
break;
|
||||
case "browse":
|
||||
if (message.extras?.screenshot) {
|
||||
store.dispatch(setScreenshotSrc(message.extras.screenshot));
|
||||
}
|
||||
if (message.extras?.url) {
|
||||
store.dispatch(setUrl(message.extras.url));
|
||||
}
|
||||
|
||||
store.dispatch(
|
||||
addAssistantObservation({
|
||||
...baseObservation,
|
||||
@ -198,6 +205,13 @@ export function handleObservationMessage(message: ObservationMessage) {
|
||||
);
|
||||
break;
|
||||
case "browse_interactive":
|
||||
if (message.extras?.screenshot) {
|
||||
store.dispatch(setScreenshotSrc(message.extras.screenshot));
|
||||
}
|
||||
if (message.extras?.url) {
|
||||
store.dispatch(setUrl(message.extras.url));
|
||||
}
|
||||
|
||||
store.dispatch(
|
||||
addAssistantObservation({
|
||||
...baseObservation,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user