@@ -7,6 +7,10 @@ import * as Search from '@libs/actions/Search';
7
7
jest . mock ( '@libs/actions/Search' ) ;
8
8
jest . mock ( '@src/components/ConfirmedRoute.tsx' ) ;
9
9
10
+ afterEach ( ( ) => {
11
+ jest . clearAllMocks ( ) ;
12
+ } ) ;
13
+
10
14
describe ( 'useSearchHighlightAndScroll' , ( ) => {
11
15
it ( 'should trigger Search when transactionIDs list change' , ( ) => {
12
16
const initialProps : UseSearchHighlightAndScroll = {
@@ -189,4 +193,86 @@ describe('useSearchHighlightAndScroll', () => {
189
193
// Then Search will be triggerred.
190
194
expect ( Search . search ) . toHaveBeenCalled ( ) ;
191
195
} ) ;
196
+
197
+ it ( 'should trigger Search when report actions change' , ( ) => {
198
+ const initialProps : UseSearchHighlightAndScroll = {
199
+ searchResults : {
200
+ data : { personalDetailsList : { } } ,
201
+ search : {
202
+ columnsToShow : {
203
+ shouldShowCategoryColumn : true ,
204
+ shouldShowTagColumn : true ,
205
+ shouldShowTaxColumn : true ,
206
+ } ,
207
+ hasMoreResults : false ,
208
+ hasResults : true ,
209
+ offset : 0 ,
210
+ status : 'all' ,
211
+ type : 'expense' ,
212
+ isLoading : false ,
213
+ } ,
214
+ } ,
215
+ transactions : { } ,
216
+ previousTransactions : { } ,
217
+ reportActions : {
218
+ reportActions_209647397999267 : {
219
+ 1 : {
220
+ actionName : 'POLICYCHANGELOG_CORPORATE_UPGRADE' ,
221
+ reportActionID : '1' ,
222
+ created : '' ,
223
+ } ,
224
+ } ,
225
+ } ,
226
+ previousReportActions : {
227
+ reportActions_209647397999267 : {
228
+ 1 : {
229
+ actionName : 'POLICYCHANGELOG_CORPORATE_UPGRADE' ,
230
+ reportActionID : '1' ,
231
+ created : '' ,
232
+ } ,
233
+ } ,
234
+ } ,
235
+ queryJSON : {
236
+ type : 'expense' ,
237
+ status : 'all' ,
238
+ sortBy : 'date' ,
239
+ sortOrder : 'desc' ,
240
+ filters : { operator : 'and' , left : 'tag' , right : '' } ,
241
+ inputQuery : 'type:expense status:all sortBy:date sortOrder:desc' ,
242
+ flatFilters : [ ] ,
243
+ hash : 243428839 ,
244
+ recentSearchHash : 422547233 ,
245
+ } ,
246
+ offset : 0 ,
247
+ } ;
248
+
249
+ const changedProps : UseSearchHighlightAndScroll = {
250
+ ...initialProps ,
251
+ reportActions : {
252
+ reportActions_209647397999268 : {
253
+ 1 : {
254
+ actionName : 'POLICYCHANGELOG_CORPORATE_UPGRADE' ,
255
+ reportActionID : '1' ,
256
+ created : '' ,
257
+ } ,
258
+ 2 : {
259
+ actionName : 'ADDCOMMENT' ,
260
+ reportActionID : '2' ,
261
+ created : '' ,
262
+ } ,
263
+ } ,
264
+ } ,
265
+ } ;
266
+
267
+ const { rerender} = renderHook ( ( props : UseSearchHighlightAndScroll ) => useSearchHighlightAndScroll ( props ) , {
268
+ initialProps,
269
+ } ) ;
270
+ expect ( Search . search ) . not . toHaveBeenCalled ( ) ;
271
+
272
+ // When report actions change
273
+ rerender ( changedProps ) ;
274
+
275
+ // Then Search will be triggered
276
+ expect ( Search . search ) . toHaveBeenCalled ( ) ;
277
+ } ) ;
192
278
} ) ;
0 commit comments