@@ -9,7 +9,7 @@ vi.mock("@/components/ui", () => ({
99 Slider : ( { value, onValueChange, "data-testid" : dataTestId , disabled } : any ) => (
1010 < input
1111 type = "range"
12- value = { value [ 0 ] }
12+ value = { value ?. [ 0 ] ?? 0 }
1313 onChange = { ( e ) => onValueChange ( [ parseFloat ( e . target . value ) ] ) }
1414 data-testid = { dataTestId }
1515 disabled = { disabled }
@@ -97,8 +97,9 @@ describe("ContextManagementSettings", () => {
9797 const checkbox = screen . getByTestId ( "include-diagnostic-messages-checkbox" )
9898 expect ( checkbox . querySelector ( "input" ) ) . not . toBeChecked ( )
9999
100- // Slider should not be rendered when diagnostics are disabled
101- expect ( screen . queryByTestId ( "max-diagnostic-messages-slider" ) ) . not . toBeInTheDocument ( )
100+ // Slider should still be rendered when diagnostics are disabled
101+ expect ( screen . getByTestId ( "max-diagnostic-messages-slider" ) ) . toBeInTheDocument ( )
102+ expect ( screen . getByText ( "50" ) ) . toBeInTheDocument ( )
102103 } )
103104
104105 it ( "calls setCachedStateField when include diagnostic messages checkbox is toggled" , async ( ) => {
@@ -125,15 +126,15 @@ describe("ContextManagementSettings", () => {
125126 } )
126127 } )
127128
128- it ( "hides slider when include diagnostic messages is unchecked" , ( ) => {
129+ it ( "keeps slider visible when include diagnostic messages is unchecked" , ( ) => {
129130 const { rerender } = render ( < ContextManagementSettings { ...defaultProps } includeDiagnosticMessages = { true } /> )
130131
131132 const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
132133 expect ( slider ) . toBeInTheDocument ( )
133134
134- // Update to disabled
135+ // Update to disabled - slider should still be visible
135136 rerender ( < ContextManagementSettings { ...defaultProps } includeDiagnosticMessages = { false } /> )
136- expect ( screen . queryByTestId ( "max-diagnostic-messages-slider" ) ) . not . toBeInTheDocument ( )
137+ expect ( screen . getByTestId ( "max-diagnostic-messages-slider" ) ) . toBeInTheDocument ( )
137138 } )
138139
139140 it ( "displays correct max diagnostic messages value" , ( ) => {
@@ -158,4 +159,110 @@ describe("ContextManagementSettings", () => {
158159 expect ( screen . getByTestId ( "show-rooignored-files-checkbox" ) ) . toBeInTheDocument ( )
159160 expect ( screen . getByTestId ( "auto-condense-context-checkbox" ) ) . toBeInTheDocument ( )
160161 } )
162+
163+ describe ( "Edge cases for maxDiagnosticMessages" , ( ) => {
164+ it ( "handles zero value correctly" , async ( ) => {
165+ const setCachedStateField = vi . fn ( )
166+ render (
167+ < ContextManagementSettings
168+ { ...defaultProps }
169+ maxDiagnosticMessages = { 0 }
170+ setCachedStateField = { setCachedStateField }
171+ /> ,
172+ )
173+
174+ expect ( screen . getByText ( "0" ) ) . toBeInTheDocument ( )
175+
176+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
177+ expect ( slider ) . toHaveValue ( "0" )
178+ } )
179+
180+ it ( "handles negative values by displaying them" , async ( ) => {
181+ const setCachedStateField = vi . fn ( )
182+ render (
183+ < ContextManagementSettings
184+ { ...defaultProps }
185+ maxDiagnosticMessages = { - 10 }
186+ setCachedStateField = { setCachedStateField }
187+ /> ,
188+ )
189+
190+ // Component displays the actual negative value in the text span
191+ expect ( screen . getByText ( "-10" ) ) . toBeInTheDocument ( )
192+
193+ // Note: The actual slider behavior with negative values depends on the implementation
194+ // In this case, we're just verifying the component renders without errors
195+ } )
196+
197+ it ( "handles very large numbers by capping at maximum" , async ( ) => {
198+ const setCachedStateField = vi . fn ( )
199+ const largeNumber = 1000
200+ render (
201+ < ContextManagementSettings
202+ { ...defaultProps }
203+ maxDiagnosticMessages = { largeNumber }
204+ setCachedStateField = { setCachedStateField }
205+ /> ,
206+ )
207+
208+ // Should display the actual value even if it exceeds slider max
209+ expect ( screen . getByText ( largeNumber . toString ( ) ) ) . toBeInTheDocument ( )
210+
211+ // Slider value would be capped at max (100)
212+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
213+ expect ( slider ) . toHaveValue ( "100" )
214+ } )
215+
216+ it ( "enforces maximum value constraint" , async ( ) => {
217+ const setCachedStateField = vi . fn ( )
218+ render ( < ContextManagementSettings { ...defaultProps } setCachedStateField = { setCachedStateField } /> )
219+
220+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
221+
222+ // Test that setting value above 100 gets capped
223+ fireEvent . change ( slider , { target : { value : "150" } } )
224+
225+ await waitFor ( ( ) => {
226+ // Should be capped at 100 (the slider's max)
227+ expect ( setCachedStateField ) . toHaveBeenCalledWith ( "maxDiagnosticMessages" , 100 )
228+ } )
229+ } )
230+
231+ it ( "handles boundary value at minimum (0)" , async ( ) => {
232+ const setCachedStateField = vi . fn ( )
233+ render ( < ContextManagementSettings { ...defaultProps } setCachedStateField = { setCachedStateField } /> )
234+
235+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
236+ fireEvent . change ( slider , { target : { value : "0" } } )
237+
238+ await waitFor ( ( ) => {
239+ expect ( setCachedStateField ) . toHaveBeenCalledWith ( "maxDiagnosticMessages" , 0 )
240+ } )
241+ } )
242+
243+ it ( "handles boundary value at maximum (100)" , async ( ) => {
244+ const setCachedStateField = vi . fn ( )
245+ render ( < ContextManagementSettings { ...defaultProps } setCachedStateField = { setCachedStateField } /> )
246+
247+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
248+ fireEvent . change ( slider , { target : { value : "100" } } )
249+
250+ await waitFor ( ( ) => {
251+ expect ( setCachedStateField ) . toHaveBeenCalledWith ( "maxDiagnosticMessages" , 100 )
252+ } )
253+ } )
254+
255+ it ( "handles decimal values by parsing as float" , async ( ) => {
256+ const setCachedStateField = vi . fn ( )
257+ render ( < ContextManagementSettings { ...defaultProps } setCachedStateField = { setCachedStateField } /> )
258+
259+ const slider = screen . getByTestId ( "max-diagnostic-messages-slider" )
260+ fireEvent . change ( slider , { target : { value : "50.7" } } )
261+
262+ await waitFor ( ( ) => {
263+ // The mock slider component parses as float
264+ expect ( setCachedStateField ) . toHaveBeenCalledWith ( "maxDiagnosticMessages" , 50.7 )
265+ } )
266+ } )
267+ } )
161268} )
0 commit comments