|
1 | | -import React from "react" |
| 1 | +// npx jest webview-ui/src/context/__tests__/ExtensionStateContext.test.tsx |
| 2 | + |
2 | 3 | import { render, screen, act } from "@testing-library/react" |
3 | | -import { ExtensionStateContextProvider, useExtensionState } from "../ExtensionStateContext" |
| 4 | + |
| 5 | +import { ExtensionState } from "../../../../src/shared/ExtensionMessage" |
| 6 | +import { ExtensionStateContextProvider, useExtensionState, mergeExtensionState } from "../ExtensionStateContext" |
| 7 | +import { ExperimentId } from "../../../../src/shared/experiments" |
| 8 | +import { ApiConfiguration } from "../../../../src/shared/api" |
4 | 9 |
|
5 | 10 | // Test component that consumes the context |
6 | 11 | const TestComponent = () => { |
@@ -63,3 +68,43 @@ describe("ExtensionStateContext", () => { |
63 | 68 | consoleSpy.mockRestore() |
64 | 69 | }) |
65 | 70 | }) |
| 71 | + |
| 72 | +describe("mergeExtensionState", () => { |
| 73 | + it("should correctly merge extension states", () => { |
| 74 | + const baseState: ExtensionState = { |
| 75 | + version: "", |
| 76 | + mcpEnabled: false, |
| 77 | + enableMcpServerCreation: false, |
| 78 | + clineMessages: [], |
| 79 | + taskHistory: [], |
| 80 | + shouldShowAnnouncement: false, |
| 81 | + enableCheckpoints: true, |
| 82 | + preferredLanguage: "English", |
| 83 | + writeDelayMs: 1000, |
| 84 | + requestDelaySeconds: 5, |
| 85 | + rateLimitSeconds: 0, |
| 86 | + mode: "default", |
| 87 | + experiments: {} as Record<ExperimentId, boolean>, |
| 88 | + customModes: [], |
| 89 | + maxOpenTabsContext: 20, |
| 90 | + apiConfiguration: { providerId: "openrouter" } as ApiConfiguration, |
| 91 | + } |
| 92 | + |
| 93 | + const prevState: ExtensionState = { |
| 94 | + ...baseState, |
| 95 | + apiConfiguration: { modelMaxTokens: 1234, modelMaxThinkingTokens: 123 }, |
| 96 | + } |
| 97 | + const newState: ExtensionState = { |
| 98 | + ...baseState, |
| 99 | + apiConfiguration: { modelMaxThinkingTokens: 456, modelTemperature: 0.3 }, |
| 100 | + } |
| 101 | + |
| 102 | + const result = mergeExtensionState(prevState, newState) |
| 103 | + |
| 104 | + expect(result.apiConfiguration).toEqual({ |
| 105 | + modelMaxTokens: 1234, |
| 106 | + modelMaxThinkingTokens: 456, |
| 107 | + modelTemperature: 0.3, |
| 108 | + }) |
| 109 | + }) |
| 110 | +}) |
0 commit comments