Skip to content

Commit 5cc1e72

Browse files
committed
clineprovider test different
1 parent 1bdc418 commit 5cc1e72

File tree

2 files changed

+19
-80
lines changed

2 files changed

+19
-80
lines changed

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ jest.mock("../../../services/browser/BrowserSession", () => ({
4040

4141
// Mock browserDiscovery
4242
jest.mock("../../../services/browser/browserDiscovery", () => ({
43-
discoverChromeInstances: jest.fn().mockImplementation(async () => {
43+
discoverChromeHostUrl: jest.fn().mockImplementation(async () => {
4444
return "http://localhost:9222"
4545
}),
46+
tryChromeHostUrl: jest.fn().mockImplementation(async (url) => {
47+
return url === "http://localhost:9222"
48+
}),
4649
}))
4750

4851
jest.mock(
@@ -629,7 +632,7 @@ describe("ClineProvider", () => {
629632
setModeConfig: jest.fn(),
630633
} as any
631634

632-
provider.updateGlobalState("currentApiConfigName", "current-config")
635+
provider.setValue("currentApiConfigName", "current-config")
633636

634637
// Switch to architect mode
635638
await messageHandler({ type: "mode", text: "architect" })
@@ -758,7 +761,7 @@ describe("ClineProvider", () => {
758761
},
759762
}
760763

761-
provider.updateGlobalState("customModePrompts", existingPrompts)
764+
provider.setValue("customModePrompts", existingPrompts)
762765

763766
// Test updating a prompt
764767
await messageHandler({
@@ -1915,9 +1918,9 @@ describe("ClineProvider", () => {
19151918
type: "testBrowserConnection",
19161919
})
19171920

1918-
// Verify discoverChromeInstances was called
1919-
const { discoverChromeInstances } = require("../../../services/browser/browserDiscovery")
1920-
expect(discoverChromeInstances).toHaveBeenCalled()
1921+
// Verify discoverChromeHostUrl was called
1922+
const { discoverChromeHostUrl } = require("../../../services/browser/browserDiscovery")
1923+
expect(discoverChromeHostUrl).toHaveBeenCalled()
19211924

19221925
// Verify postMessage was called with success result
19231926
expect(mockPostMessage).toHaveBeenCalledWith(
@@ -1928,77 +1931,6 @@ describe("ClineProvider", () => {
19281931
}),
19291932
)
19301933
})
1931-
1932-
test("handles discoverBrowser message", async () => {
1933-
// Get the message handler
1934-
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
1935-
1936-
// Test browser discovery
1937-
await messageHandler({
1938-
type: "discoverBrowser",
1939-
})
1940-
1941-
// Verify discoverChromeInstances was called
1942-
const { discoverChromeInstances } = require("../../../services/browser/browserDiscovery")
1943-
expect(discoverChromeInstances).toHaveBeenCalled()
1944-
1945-
// Verify postMessage was called with success result
1946-
expect(mockPostMessage).toHaveBeenCalledWith(
1947-
expect.objectContaining({
1948-
type: "browserConnectionResult",
1949-
success: true,
1950-
text: expect.stringContaining("Successfully discovered and connected to Chrome"),
1951-
}),
1952-
)
1953-
})
1954-
1955-
test("handles errors during browser discovery", async () => {
1956-
// Mock discoverChromeInstances to throw an error
1957-
const { discoverChromeInstances } = require("../../../services/browser/browserDiscovery")
1958-
discoverChromeInstances.mockImplementationOnce(() => {
1959-
throw new Error("Discovery error")
1960-
})
1961-
1962-
// Get the message handler
1963-
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
1964-
1965-
// Test browser discovery with error
1966-
await messageHandler({
1967-
type: "discoverBrowser",
1968-
})
1969-
1970-
// Verify postMessage was called with error result
1971-
expect(mockPostMessage).toHaveBeenCalledWith(
1972-
expect.objectContaining({
1973-
type: "browserConnectionResult",
1974-
success: false,
1975-
text: expect.stringContaining("Error discovering browser"),
1976-
}),
1977-
)
1978-
})
1979-
1980-
test("handles case when no browsers are discovered", async () => {
1981-
// Mock discoverChromeInstances to return null (no browsers found)
1982-
const { discoverChromeInstances } = require("../../../services/browser/browserDiscovery")
1983-
discoverChromeInstances.mockImplementationOnce(() => null)
1984-
1985-
// Get the message handler
1986-
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
1987-
1988-
// Test browser discovery with no browsers found
1989-
await messageHandler({
1990-
type: "discoverBrowser",
1991-
})
1992-
1993-
// Verify postMessage was called with failure result
1994-
expect(mockPostMessage).toHaveBeenCalledWith(
1995-
expect.objectContaining({
1996-
type: "browserConnectionResult",
1997-
success: false,
1998-
text: expect.stringContaining("No Chrome instances found"),
1999-
}),
2000-
)
2001-
})
20021934
})
20031935
})
20041936

@@ -2098,7 +2030,7 @@ describe("Project MCP Settings", () => {
20982030
await messageHandler({ type: "openProjectMcpSettings" })
20992031

21002032
// Verify error message was shown
2101-
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith("no_workspace")
2033+
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith("errors.no_workspace")
21022034
})
21032035

21042036
test.skip("handles openProjectMcpSettings file creation error", async () => {
@@ -2158,21 +2090,27 @@ describe.skip("ContextProxy integration", () => {
21582090
})
21592091

21602092
test("updateGlobalState uses contextProxy", async () => {
2161-
await provider.updateGlobalState("currentApiConfigName", "testValue")
2093+
await provider.setValue("currentApiConfigName", "testValue")
21622094
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith("currentApiConfigName", "testValue")
21632095
})
21642096

21652097
test("getGlobalState uses contextProxy", async () => {
21662098
mockContextProxy.getGlobalState.mockResolvedValueOnce("testValue")
2167-
const result = await provider.getGlobalState("currentApiConfigName")
2099+
const result = await provider.getValue("currentApiConfigName")
21682100
expect(mockContextProxy.getGlobalState).toHaveBeenCalledWith("currentApiConfigName")
21692101
expect(result).toBe("testValue")
21702102
})
21712103

2104+
test("storeSecret uses contextProxy", async () => {
2105+
await provider.setValue("apiKey", "test-secret")
2106+
expect(mockContextProxy.storeSecret).toHaveBeenCalledWith("apiKey", "test-secret")
2107+
})
2108+
21722109
test("contextProxy methods are available", () => {
21732110
// Verify the contextProxy has all the required methods
21742111
expect(mockContextProxy.getGlobalState).toBeDefined()
21752112
expect(mockContextProxy.updateGlobalState).toBeDefined()
2113+
expect(mockContextProxy.storeSecret).toBeDefined()
21762114
expect(mockContextProxy.setValue).toBeDefined()
21772115
expect(mockContextProxy.setValues).toBeDefined()
21782116
})

src/core/webview/webviewMessageHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
13351335
await provider.postStateToWebview()
13361336
break
13371337
}
1338+
13381339
case "checkpointDiffWeb": {
13391340
console.log("[webviewMessageHandler] Received checkpointDiffWeb message", message.payload)
13401341
const diffWebResult = checkoutDiffPayloadSchema.safeParse(message.payload)

0 commit comments

Comments
 (0)