Skip to content

Commit 4743b99

Browse files
committed
test: add corresponding tests for sticky modes setting
1 parent d487f18 commit 4743b99

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ describe("ClineProvider", () => {
416416
showRooIgnoredFiles: true,
417417
renderContext: "sidebar",
418418
maxReadFileLine: 500,
419+
stickyModesEnabled: true,
419420
}
420421

421422
const message: ExtensionMessage = {
@@ -538,6 +539,36 @@ describe("ClineProvider", () => {
538539
expect(mockPostMessage).toHaveBeenCalled()
539540
})
540541

542+
test("stickyModesEnabled defaults to true when not set", async () => {
543+
// Mock globalState.get to return undefined for stickyModesEnabled
544+
;(mockContext.globalState.get as jest.Mock).mockImplementation((key: string) => {
545+
if (key === "stickyModesEnabled") {
546+
return undefined
547+
}
548+
return null
549+
})
550+
551+
const state = await provider.getState()
552+
expect(state.stickyModesEnabled).toBe(true)
553+
})
554+
555+
test("handles stickyModesEnabled message", async () => {
556+
await provider.resolveWebviewView(mockWebviewView)
557+
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
558+
559+
// Test setting to false
560+
await messageHandler({ type: "stickyModesEnabled", bool: false })
561+
expect(updateGlobalStateSpy).toHaveBeenCalledWith("stickyModesEnabled", false)
562+
expect(mockContext.globalState.update).toHaveBeenCalledWith("stickyModesEnabled", false)
563+
expect(mockPostMessage).toHaveBeenCalled()
564+
565+
// Test setting to true
566+
await messageHandler({ type: "stickyModesEnabled", bool: true })
567+
expect(updateGlobalStateSpy).toHaveBeenCalledWith("stickyModesEnabled", true)
568+
expect(mockContext.globalState.update).toHaveBeenCalledWith("stickyModesEnabled", true)
569+
expect(mockPostMessage).toHaveBeenCalled()
570+
})
571+
541572
test("updates sound utility when sound setting changes", async () => {
542573
await provider.resolveWebviewView(mockWebviewView)
543574

@@ -1603,6 +1634,45 @@ describe("ClineProvider", () => {
16031634
// Verify state was posted to webview
16041635
expect(mockPostMessage).toHaveBeenCalledWith(expect.objectContaining({ type: "state" }))
16051636
})
1637+
1638+
test("does NOT load/save config when stickyModesEnabled is false", async () => {
1639+
// Mock globalState to return stickyModesEnabled: false
1640+
mockContext.globalState.get = jest.fn((key: string) => {
1641+
if (key === "stickyModesEnabled") return false
1642+
if (key === "mode") return "code" // Start in some mode
1643+
return undefined
1644+
})
1645+
1646+
// Re-initialize provider with updated mock context
1647+
provider = new ClineProvider(mockContext, mockOutputChannel)
1648+
await provider.resolveWebviewView(mockWebviewView)
1649+
1650+
const mockProviderSettingsManager = {
1651+
getModeConfigId: jest.fn(),
1652+
listConfig: jest.fn().mockResolvedValue([]), // Still need to list configs
1653+
loadConfig: jest.fn(),
1654+
setModeConfig: jest.fn(),
1655+
}
1656+
;(provider as any).providerSettingsManager = mockProviderSettingsManager
1657+
1658+
// Switch to architect mode
1659+
await provider.handleModeSwitch("architect")
1660+
1661+
// Verify mode was updated
1662+
expect(mockContext.globalState.update).toHaveBeenCalledWith("mode", "architect")
1663+
1664+
// Verify config loading/saving methods were NOT called
1665+
expect(mockProviderSettingsManager.getModeConfigId).not.toHaveBeenCalled()
1666+
expect(mockProviderSettingsManager.loadConfig).not.toHaveBeenCalled()
1667+
expect(mockProviderSettingsManager.setModeConfig).not.toHaveBeenCalled()
1668+
1669+
// Verify listConfig and updateGlobalState("listApiConfigMeta", ...) were still called
1670+
expect(mockProviderSettingsManager.listConfig).toHaveBeenCalled()
1671+
expect(mockContext.globalState.update).toHaveBeenCalledWith("listApiConfigMeta", [])
1672+
1673+
// Verify state was posted to webview
1674+
expect(mockPostMessage).toHaveBeenCalledWith(expect.objectContaining({ type: "state" }))
1675+
})
16061676
})
16071677

16081678
describe("updateCustomMode", () => {

0 commit comments

Comments
 (0)