11import React from "react"
22import { render , screen } from "@testing-library/react"
3+
4+ import type { ProviderSettings , ModelInfo } from "@roo-code/types"
5+
36import { MaxOutputTokensControl } from "./MaxOutputTokensControl"
4- import { ApiConfiguration , ModelInfo } from "@roo/shared/api "
7+ import { Slider } from "@src/components/ui "
58
69// Mock ResizeObserver globally
710global . ResizeObserver = jest . fn ( ) . mockImplementation ( ( ) => ( {
@@ -11,33 +14,28 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
1114} ) )
1215// Static import of Slider removed again to avoid TS error for non-existent module
1316
14- // Mock i18n
15- jest . mock ( "react-i18next " , ( ) => ( {
16- useTranslation : ( ) => ( {
17+ // Mock i18n translation context
18+ jest . mock ( "@src/i18n/TranslationContext " , ( ) => ( {
19+ useAppTranslation : ( ) => ( {
1720 t : ( key : string ) => key ,
1821 } ) ,
1922} ) )
2023
21- // Use jest.doMock with { virtual: true } to mock a non-existent module.
22- // This mock factory will be used when '../Slider' is imported.
23- jest . mock ( "../ui/slider" , ( ) => ( {
24- __esModule : true ,
24+ // Mock UI components
25+ jest . mock ( "@src/components/ui" , ( ) => ( {
2526 Slider : jest . fn ( ( props ) => < div data-testid = "mock-slider" { ...props } /> ) ,
2627} ) )
2728
2829// Import the mocked Slider *after* jest.mock
2930// We need to refer to it for assertions and clearing.
30- // eslint-disable-next-line @typescript-eslint/no-var-requires
31- const MockedSlider = require ( "../ui/slider" ) . Slider as jest . Mock
31+ const MockedSlider = jest . mocked ( Slider )
3232
3333describe ( "MaxOutputTokensControl" , ( ) => {
3434 const mockSetApiConfigurationField = jest . fn ( )
35- const mockApiConfiguration : ApiConfiguration = {
35+ const mockApiConfiguration : ProviderSettings = {
3636 apiProvider : "openai" ,
37- openAiModelId : "test-model" ,
38- modelTemperature : 0.5 ,
37+ apiModelId : "test-model" ,
3938 modelMaxTokens : undefined ,
40- modelMaxThinkingTokens : undefined ,
4139 }
4240
4341 beforeEach ( ( ) => {
@@ -66,7 +64,7 @@ describe("MaxOutputTokensControl", () => {
6664 const modelInfo : Partial < ModelInfo > = {
6765 maxTokens : 16000 ,
6866 }
69- const apiConfigurationWithOverride : ApiConfiguration = {
67+ const apiConfigurationWithOverride : ProviderSettings = {
7068 ...mockApiConfiguration ,
7169 modelMaxTokens : 10000 , // Override the default maxTokens
7270 }
@@ -86,11 +84,11 @@ describe("MaxOutputTokensControl", () => {
8684 expect ( screen . getByText ( expectedValue . toString ( ) ) ) . toBeInTheDocument ( )
8785
8886 // Assert that the label is displayed (using the mocked translation key)
89- expect ( screen . getByText ( "providers.customModel. maxTokens.label " ) ) . toBeInTheDocument ( )
87+ expect ( screen . getByText ( "settings:thinkingBudget. maxTokens" ) ) . toBeInTheDocument ( )
9088 } )
9189
9290 // Make the test async to use dynamic import
93- it ( "should pass min={8192 } to the Slider component when rendered" , async ( ) => {
91+ it ( "should pass min={2048 } to the Slider component when rendered" , async ( ) => {
9492 // Dynamically import Slider; it will be the mocked version due to jest.doMock
9593 // Note: For this to work, the test function must be async and you await the import.
9694 // However, for prop checking on a mock function, we can directly use the
@@ -117,7 +115,7 @@ describe("MaxOutputTokensControl", () => {
117115 // This test is expected to fail because Slider is not yet used or not with this prop.
118116 expect ( MockedSlider ) . toHaveBeenCalledWith (
119117 expect . objectContaining ( {
120- min : 8192 ,
118+ min : 2048 ,
121119 } ) ,
122120 expect . anything ( ) , // Context for React components
123121 )
@@ -178,7 +176,7 @@ describe("MaxOutputTokensControl", () => {
178176 const modelInfo : Partial < ModelInfo > = {
179177 maxTokens : 32000 , // This should be ignored
180178 }
181- const apiConfigurationWithOverride : ApiConfiguration = {
179+ const apiConfigurationWithOverride : ProviderSettings = {
182180 ...mockApiConfiguration ,
183181 modelMaxTokens : 10000 ,
184182 }
@@ -203,7 +201,7 @@ describe("MaxOutputTokensControl", () => {
203201 const modelInfo : Partial < ModelInfo > = {
204202 maxTokens : 16000 , // This should be used
205203 }
206- const apiConfigurationWithoutOverride : ApiConfiguration = {
204+ const apiConfigurationWithoutOverride : ProviderSettings = {
207205 ...mockApiConfiguration ,
208206 modelMaxTokens : undefined ,
209207 }
@@ -242,7 +240,7 @@ describe("MaxOutputTokensControl", () => {
242240 // MockedSlider.mock.calls[0][0] gives us the props of the first render call.
243241 const sliderProps = MockedSlider . mock . calls [ 0 ] [ 0 ]
244242 const newValue = [ 20000 ]
245- sliderProps . onValueChange ( newValue )
243+ sliderProps . onValueChange ?. ( newValue )
246244
247245 // Assert that setApiConfigurationField was called with the correct arguments
248246 expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith ( "modelMaxTokens" , newValue [ 0 ] )
0 commit comments