@@ -193,6 +193,89 @@ describe('usage-banner-state', () => {
193193 } )
194194 } )
195195
196+ describe ( 'auto top-up enabled behavior' , ( ) => {
197+ test ( 'does not auto-show for auto-top-up users above 0 credits' , ( ) => {
198+ // Even at low credits, auto-top-up users shouldn't see warnings
199+ const result = shouldAutoShowBanner ( false , true , 50 , null , true )
200+ expect ( result . shouldShow ) . toBe ( false )
201+ expect ( result . newWarningThreshold ) . toBe ( null )
202+ } )
203+
204+ test ( 'does not auto-show for auto-top-up users at any positive threshold' , ( ) => {
205+ // At 500 credits - would normally warn
206+ let result = shouldAutoShowBanner ( false , true , 499 , null , true )
207+ expect ( result . shouldShow ) . toBe ( false )
208+
209+ // At 100 credits - would normally warn
210+ result = shouldAutoShowBanner ( false , true , 99 , null , true )
211+ expect ( result . shouldShow ) . toBe ( false )
212+
213+ // Even at 1 credit
214+ result = shouldAutoShowBanner ( false , true , 1 , null , true )
215+ expect ( result . shouldShow ) . toBe ( false )
216+ } )
217+
218+ test ( 'DOES auto-show for auto-top-up users when truly out (0 credits)' , ( ) => {
219+ const result = shouldAutoShowBanner ( false , true , 0 , null , true )
220+ expect ( result . shouldShow ) . toBe ( true )
221+ expect ( result . newWarningThreshold ) . toBe ( 100 )
222+ } )
223+
224+ test ( 'DOES auto-show for auto-top-up users when in debt (negative credits)' , ( ) => {
225+ const result = shouldAutoShowBanner ( false , true , - 50 , null , true )
226+ expect ( result . shouldShow ) . toBe ( true )
227+ expect ( result . newWarningThreshold ) . toBe ( 100 )
228+ } )
229+
230+ test ( 'non-auto-top-up users still get warnings as normal' , ( ) => {
231+ // Without auto-top-up, should warn at low credits
232+ const result = shouldAutoShowBanner ( false , true , 50 , null , false )
233+ expect ( result . shouldShow ) . toBe ( true )
234+ expect ( result . newWarningThreshold ) . toBe ( 100 )
235+ } )
236+
237+ test ( 'defaults autoTopUpEnabled to false when omitted' , ( ) => {
238+ // When autoTopUpEnabled parameter is omitted, should behave like false
239+ const result = shouldAutoShowBanner ( false , true , 50 , null )
240+ expect ( result . shouldShow ) . toBe ( true )
241+ expect ( result . newWarningThreshold ) . toBe ( 100 )
242+ } )
243+ } )
244+
245+ describe ( 'combined scenarios' , ( ) => {
246+ test ( 'chain in progress takes precedence over auto-top-up status' , ( ) => {
247+ // Even with auto-top-up disabled and low credits, chain in progress blocks showing
248+ const result = shouldAutoShowBanner ( true , true , 50 , null , false )
249+ expect ( result . shouldShow ) . toBe ( false )
250+ } )
251+
252+ test ( 'unauthenticated takes precedence over auto-top-up status' , ( ) => {
253+ // Even with auto-top-up disabled and low credits, no auth token blocks showing
254+ const result = shouldAutoShowBanner ( false , false , 50 , null , false )
255+ expect ( result . shouldShow ) . toBe ( false )
256+ } )
257+
258+ test ( 'null balance takes precedence over auto-top-up status' , ( ) => {
259+ // Even with auto-top-up disabled, null balance blocks showing
260+ const result = shouldAutoShowBanner ( false , true , null , null , false )
261+ expect ( result . shouldShow ) . toBe ( false )
262+ } )
263+
264+ test ( 'auto-top-up user with previous warning threshold and now at 0 credits' , ( ) => {
265+ // Auto-top-up user who was previously warned at 500, now at 0 - should show
266+ const result = shouldAutoShowBanner ( false , true , 0 , 500 , true )
267+ expect ( result . shouldShow ) . toBe ( true )
268+ expect ( result . newWarningThreshold ) . toBe ( 100 )
269+ } )
270+
271+ test ( 'auto-top-up user with healthy balance clears warning state' , ( ) => {
272+ // Auto-top-up user who now has healthy balance should have cleared state
273+ const result = shouldAutoShowBanner ( false , true , 1500 , 100 , true )
274+ expect ( result . shouldShow ) . toBe ( false )
275+ expect ( result . newWarningThreshold ) . toBe ( null )
276+ } )
277+ } )
278+
196279 describe ( 'state reset behavior' , ( ) => {
197280 test ( 'clears warning state when credits return to healthy' , ( ) => {
198281 const result = shouldAutoShowBanner (
0 commit comments