Skip to content

Commit 7120572

Browse files
committed
test(webview): expect registered viewStates persistence in parallel writes
1 parent 728f21e commit 7120572

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

src/core/webview/__tests__/ClineProvider.parallelMode.spec.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,20 @@ describe("ClineProvider - Parallel Mode Support", () => {
10231023
})
10241024

10251025
describe("parallel mode writes", () => {
1026-
it("should persist mode switches to the stable view-local state key", async () => {
1026+
it("should persist mode switches to registered durable viewStates", async () => {
10271027
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
10281028
await (provider as any).setViewStateId("stable-sidebar-mode")
10291029
const contextProxySpy = vi.spyOn(provider.contextProxy, "setValue")
10301030

10311031
await provider.handleModeSwitch("architect")
10321032

1033-
expect(contextProxySpy).toHaveBeenCalledWith("__view_state_stable-sidebar-mode_mode", "architect")
1033+
expect(contextProxySpy).toHaveBeenCalledWith(
1034+
"viewStates",
1035+
expect.objectContaining({
1036+
"stable-sidebar-mode": expect.objectContaining({ mode: "architect" }),
1037+
}),
1038+
)
1039+
expect(contextProxySpy).not.toHaveBeenCalledWith("__view_state_stable-sidebar-mode_mode", expect.anything())
10341040
const state = await provider.getState()
10351041
expect(state.mode).toBe("architect")
10361042

@@ -1055,8 +1061,12 @@ describe("ClineProvider - Parallel Mode Support", () => {
10551061
const state2 = await provider2.getState()
10561062
expect(state1.mode).toBe("architect")
10571063
expect(state2.mode).toBe("debugger")
1058-
expect(provider1.contextProxy.getValue("__view_state_stable-sidebar-mode-a_mode" as any)).toBe("architect")
1059-
expect(provider2.contextProxy.getValue("__view_state_stable-editor-mode-b_mode" as any)).toBe("debugger")
1064+
expect(provider1.contextProxy.getValue("viewStates" as any)).toMatchObject({
1065+
"stable-sidebar-mode-a": { mode: "architect" },
1066+
})
1067+
expect(provider2.contextProxy.getValue("viewStates" as any)).toMatchObject({
1068+
"stable-editor-mode-b": { mode: "debugger" },
1069+
})
10601070

10611071
await provider1.dispose()
10621072
await provider2.dispose()
@@ -1083,12 +1093,12 @@ describe("ClineProvider - Parallel Mode Support", () => {
10831093
const state = await provider.getState()
10841094
expect(state.currentApiConfigName).toBe("profile-a")
10851095
expect(state.apiConfiguration).toMatchObject(providerSettings)
1086-
expect(
1087-
provider.contextProxy.getValue("__view_state_stable-sidebar-profile_currentApiConfigName" as any),
1088-
).toBe("profile-a")
1089-
expect(
1090-
provider.contextProxy.getValue("__view_state_stable-sidebar-profile_apiConfiguration" as any),
1091-
).toMatchObject(providerSettings)
1096+
expect(provider.contextProxy.getValue("viewStates" as any)).toMatchObject({
1097+
"stable-sidebar-profile": { currentApiConfigName: "profile-a" },
1098+
})
1099+
expect(provider.contextProxy.getValue("viewStates" as any)["stable-sidebar-profile"]).not.toMatchObject(
1100+
providerSettings,
1101+
)
10921102

10931103
await provider.dispose()
10941104
})
@@ -1110,12 +1120,12 @@ describe("ClineProvider - Parallel Mode Support", () => {
11101120
const state = await provider.getState()
11111121
expect(state.currentApiConfigName).toBe("profile-b")
11121122
expect(state.apiConfiguration).toMatchObject(providerSettings)
1113-
expect(
1114-
provider.contextProxy.getValue("__view_state_stable-sidebar-upsert_currentApiConfigName" as any),
1115-
).toBe("profile-b")
1116-
expect(
1117-
provider.contextProxy.getValue("__view_state_stable-sidebar-upsert_apiConfiguration" as any),
1118-
).toMatchObject(providerSettings)
1123+
expect(provider.contextProxy.getValue("viewStates" as any)).toMatchObject({
1124+
"stable-sidebar-upsert": { currentApiConfigName: "profile-b" },
1125+
})
1126+
expect(provider.contextProxy.getValue("viewStates" as any)["stable-sidebar-upsert"]).not.toMatchObject(
1127+
providerSettings,
1128+
)
11191129

11201130
await provider.dispose()
11211131
})
@@ -1140,9 +1150,9 @@ describe("ClineProvider - Parallel Mode Support", () => {
11401150

11411151
const state = await provider.getState()
11421152
expect(state.currentApiConfigName).toBe("profile-b")
1143-
expect(
1144-
provider.contextProxy.getValue("__view_state_stable-delete-profile_currentApiConfigName" as any),
1145-
).toBe("profile-b")
1153+
expect(provider.contextProxy.getValue("viewStates" as any)).toMatchObject({
1154+
"stable-delete-profile": { currentApiConfigName: "profile-b" },
1155+
})
11461156

11471157
await provider.dispose()
11481158
})

0 commit comments

Comments
 (0)