@@ -53,6 +53,33 @@ describe('useDataViewFilters', () => {
5353 expect ( setSearchParams ) . toHaveBeenCalled ( ) ;
5454 } ) ;
5555
56+ it ( 'should sync with URL search params with non array value' , ( ) => {
57+ const searchParams = new URLSearchParams ( ) ;
58+ searchParams . set ( 'test' , 'foo' ) ;
59+ const setSearchParams = jest . fn ( ) ;
60+ const props : UseDataViewFiltersProps < { test : string } > = {
61+ initialFilters : { test : '' } ,
62+ searchParams,
63+ setSearchParams,
64+ } ;
65+ const { result } = renderHook ( ( ) => useDataViewFilters ( props ) ) ;
66+ expect ( result . current . filters ) . toEqual ( { test : 'foo' } ) ;
67+ } )
68+ it ( 'should sync with URL search params with array value' , ( ) => {
69+
70+ const searchParams = new URLSearchParams ( ) ;
71+ searchParams . append ( 'test' , 'foo' ) ;
72+ searchParams . append ( 'test' , 'bar' ) ;
73+ const setSearchParams = jest . fn ( ) ;
74+ const props : UseDataViewFiltersProps < { test : string [ ] } > = {
75+ initialFilters : { test : [ ] } ,
76+ searchParams,
77+ setSearchParams,
78+ } ;
79+ const { result } = renderHook ( ( ) => useDataViewFilters ( props ) ) ;
80+ expect ( result . current . filters ) . toEqual ( { test : [ 'foo' , 'bar' ] } ) ;
81+ } )
82+
5683 it ( 'should reset filters to default values when clearAllFilters is called' , ( ) => {
5784 const { result } = renderHook ( ( ) => useDataViewFilters ( { initialFilters } ) ) ;
5885 act ( ( ) => result . current . clearAllFilters ( ) ) ;
0 commit comments