11import { dbKeysMock } from '__tests__/_setup/mocks/samples' ;
2- import { renderHook , waitFor } from '__tests__/_setup/testing-utils' ;
2+ import { act , renderHook , waitFor } from '__tests__/_setup/testing-utils' ;
33import { useSearchForm } from 'app/hooks/useSearchForm' ;
44import { IAuthPropertiesStorageKeys } from 'app/util/auth' ;
55import { AuthType } from 'types/types' ;
66import { describe , expect , it } from 'vitest' ;
77
88describe ( 'useSearchForm' , ( ) => {
9- it ( 'renders and sets default table key on reset' , async ( ) => {
9+ it ( 'sets default table key on reset' , async ( ) => {
1010 sessionStorage . setItem ( IAuthPropertiesStorageKeys . jwt_bearerToken , 'token' ) ;
1111
1212 const { result } = renderHook ( ( ) => useSearchForm ( ) , { authType : AuthType . Jwt } ) ;
@@ -17,6 +17,60 @@ describe('useSearchForm', () => {
1717 } ) ;
1818 } ) ;
1919
20+ it ( 'sets NULL table key on reset' , async ( ) => {
21+ sessionStorage . setItem ( IAuthPropertiesStorageKeys . jwt_bearerToken , 'token' ) ;
22+
23+ const { result } = renderHook ( ( ) => useSearchForm ( ) , { authType : AuthType . Jwt } ) ;
24+
25+ await waitFor ( ( ) => {
26+ result . current . reset ( true ) ;
27+ expect ( result . current . getValues ( 'table' ) ) . toBe ( null ) ;
28+ } ) ;
29+ } ) ;
30+
31+ type Properties = Parameters < ReturnType < typeof useSearchForm > [ 'setValue' ] > [ '0' ] ;
32+ it . each ( [ {
33+ property : 'level' as Properties , resetResult : true ,
34+ } ,
35+ {
36+ property : 'search' as Properties , resetResult : true ,
37+ } ,
38+ {
39+ property : 'startDate' as Properties , resetResult : true ,
40+ } ,
41+ {
42+ property : 'endDate' as Properties , resetResult : true ,
43+ } ,
44+ {
45+ property : 'entriesPerPage' as Properties , resetResult : false
46+ } ,
47+ {
48+ property : 'page' as Properties , resetResult : false
49+ } ,
50+ {
51+ property : 'sortBy' as Properties , resetResult : false
52+ } ,
53+ {
54+ property : 'table' as Properties , resetResult : false
55+ } ,
56+ {
57+ property : 'sortOn' as Properties , resetResult : false
58+ }
59+ ] ) ( 'hints for refetch, returning $resetResult on reset, for property $property' , async ( { property, resetResult } : { property : Properties , resetResult : boolean } ) => {
60+ sessionStorage . setItem ( IAuthPropertiesStorageKeys . jwt_bearerToken , 'token' ) ;
61+
62+ const { result } = renderHook ( ( ) => useSearchForm ( ) , { authType : AuthType . Jwt } ) ;
63+
64+ act ( ( ) => {
65+ result . current . setValue ( property , 'test' )
66+ } )
67+
68+ act ( ( ) => {
69+ const shouldRefetch = result . current . reset ( ) ;
70+ expect ( shouldRefetch ) . toBe ( resetResult ) ;
71+ } )
72+ } ) ;
73+
2074 it ( 'renders and leaves default table key undefined, if internal query was not successful' , async ( ) => {
2175 sessionStorage . removeItem ( IAuthPropertiesStorageKeys . jwt_bearerToken ) ;
2276
0 commit comments