@@ -425,12 +425,13 @@ describe('SearchQueryUtils', () => {
425425 } ) ;
426426
427427 describe ( 'limit option' , ( ) => {
428- test ( 'includes limit in query string when provided' , ( ) => {
428+ test ( 'includes limit in query string when provided in form values ' , ( ) => {
429429 const filterValues : Partial < SearchAdvancedFiltersForm > = {
430430 type : 'expense' ,
431+ limit : '10' ,
431432 } ;
432433
433- const result = buildQueryStringFromFilterFormValues ( filterValues , { limit : 10 } ) ;
434+ const result = buildQueryStringFromFilterFormValues ( filterValues ) ;
434435
435436 expect ( result ) . toEqual ( 'type:expense limit:10' ) ;
436437 } ) ;
@@ -439,9 +440,10 @@ describe('SearchQueryUtils', () => {
439440 const filterValues : Partial < SearchAdvancedFiltersForm > = {
440441 type : 'expense' ,
441442 merchant : 'Amazon' ,
443+ limit : '25' ,
442444 } ;
443445
444- const result = buildQueryStringFromFilterFormValues ( filterValues , { sortBy : 'amount' , sortOrder : 'asc' , limit : 25 } ) ;
446+ const result = buildQueryStringFromFilterFormValues ( filterValues , { sortBy : 'amount' , sortOrder : 'asc' } ) ;
445447
446448 expect ( result ) . toEqual ( 'sortBy:amount sortOrder:asc type:expense merchant:Amazon limit:25' ) ;
447449 } ) ;
@@ -462,7 +464,7 @@ describe('SearchQueryUtils', () => {
462464 limit : '' ,
463465 } ;
464466
465- const result = buildQueryStringFromFilterFormValues ( filterValues , { limit : 10 } ) ;
467+ const result = buildQueryStringFromFilterFormValues ( filterValues ) ;
466468
467469 expect ( result ) . not . toContain ( 'limit:' ) ;
468470 } ) ;
@@ -530,15 +532,23 @@ describe('SearchQueryUtils', () => {
530532 expect ( keywordFilter ?. filters . at ( 0 ) ?. value ) . toBe ( 'hello' ) ;
531533 } ) ;
532534
533- test ( 'form limit takes priority over options limit ' , ( ) => {
535+ test ( 'limit only comes from form values, not options ' , ( ) => {
534536 const filterValues : Partial < SearchAdvancedFiltersForm > = {
535537 type : 'expense' ,
536538 limit : '30' ,
537539 } ;
538540
539- const result = buildQueryStringFromFilterFormValues ( filterValues , { limit : 10 } ) ;
541+ const result = buildQueryStringFromFilterFormValues ( filterValues ) ;
540542 expect ( result ) . toContain ( 'limit:30' ) ;
541- expect ( result ) . not . toContain ( 'limit:10' ) ;
543+ } ) ;
544+
545+ test ( 'omits limit when form has no limit key (reset filters scenario)' , ( ) => {
546+ const filterValues : Partial < SearchAdvancedFiltersForm > = {
547+ type : 'expense' ,
548+ } ;
549+
550+ const result = buildQueryStringFromFilterFormValues ( filterValues , { sortBy : 'date' , sortOrder : 'desc' } ) ;
551+ expect ( result ) . not . toContain ( 'limit' ) ;
542552 } ) ;
543553 } ) ;
544554
0 commit comments