@@ -305,27 +305,50 @@ describe('usePerpsMarketListView', () => {
305305 } ) ;
306306 } ) ;
307307
308- it ( 'defaultSortOptionId overrides the saved sort preference ' , ( ) => {
308+ it ( 'defaultSortOptionId overrides the saved sort option and resets direction to default ' , ( ) => {
309309 let selectorCallCount = 0 ;
310310 mockUseSelector . mockImplementation ( ( ) => {
311311 selectorCallCount ++ ;
312312 if ( selectorCallCount % 2 === 1 ) {
313313 return [ 'BTC' ] ;
314314 }
315- // Saved preference is volume/desc
316- return { optionId : 'volume' , direction : 'desc ' } ;
315+ // Saved preference is volume/asc — user had it sorted ascending
316+ return { optionId : 'volume' , direction : 'asc ' } ;
317317 } ) ;
318318
319319 renderHook ( ( ) =>
320320 usePerpsMarketListView ( { defaultSortOptionId : 'priceChange' } ) ,
321321 ) ;
322322
323+ // Option overridden → direction must reset to default (desc), not carry 'asc'
323324 expect ( mockUsePerpsSorting ) . toHaveBeenCalledWith ( {
324325 initialOptionId : 'priceChange' ,
325326 initialDirection : 'desc' ,
326327 } ) ;
327328 } ) ;
328329
330+ it ( 'preserves saved direction when defaultSortOptionId matches the saved option' , ( ) => {
331+ let selectorCallCount = 0 ;
332+ mockUseSelector . mockImplementation ( ( ) => {
333+ selectorCallCount ++ ;
334+ if ( selectorCallCount % 2 === 1 ) {
335+ return [ 'BTC' ] ;
336+ }
337+ // Saved preference is priceChange/asc
338+ return { optionId : 'priceChange' , direction : 'asc' } ;
339+ } ) ;
340+
341+ renderHook ( ( ) =>
342+ usePerpsMarketListView ( { defaultSortOptionId : 'priceChange' } ) ,
343+ ) ;
344+
345+ // Same option — carry the saved direction, don't reset
346+ expect ( mockUsePerpsSorting ) . toHaveBeenCalledWith ( {
347+ initialOptionId : 'priceChange' ,
348+ initialDirection : 'asc' ,
349+ } ) ;
350+ } ) ;
351+
329352 it ( 'falls back to saved sort preference when defaultSortOptionId is not provided' , ( ) => {
330353 let selectorCallCount = 0 ;
331354 mockUseSelector . mockImplementation ( ( ) => {
0 commit comments