@@ -269,7 +269,11 @@ describe('Clear button functionality', () => {
269269
270270 vi . mocked ( usePathname ) . mockReturnValue ( '/search' )
271271
272- const items = [ { corpus : 'apple' } , { corpus : 'banana' } , { corpus : 'cherry' } ]
272+ const items = [
273+ { corpus : 'apple' , filename : 'apple.jpg' } ,
274+ { corpus : 'banana' , filename : 'banana.jpg' } ,
275+ { corpus : 'cherry' , filename : 'cherry.jpg' } ,
276+ ]
273277
274278 // Use a wrapper component to access the hook
275279 function TestComponent ( ) {
@@ -283,7 +287,7 @@ describe('Clear button functionality', () => {
283287 expect ( container . textContent ) . toMatch ( / f o r " a p p l e " / )
284288
285289 // Find the Clear button by title attribute
286- const clearButton = container . querySelector ( 'button[title="Clear search"]' ) as HTMLButtonElement
290+ const clearButton = container . querySelector ( 'button[title="Clear search and view adjacent photos "]' ) as HTMLButtonElement
287291
288292 // Mock the search params to return empty after clearing
289293 vi . mocked ( useSearchParams ) . mockReturnValue ( {
@@ -293,7 +297,7 @@ describe('Clear button functionality', () => {
293297 fireEvent . click ( clearButton )
294298
295299 // Verify router.replace was called
296- expect ( mockReplace ) . toHaveBeenCalledWith ( '/search' )
300+ expect ( mockReplace ) . toHaveBeenCalledWith ( '/search?select=apple.jpg ' )
297301
298302 // Check that the input field value is cleared
299303 await waitFor ( ( ) => {
@@ -323,21 +327,22 @@ describe('Clear button functionality', () => {
323327 vi . mocked ( usePathname ) . mockReturnValue ( '/gallery/photos' )
324328
325329 const items = [
326- { corpus : 'apple' } ,
327- { corpus : 'banana' } ,
328- { corpus : 'cherry' } ,
329- { corpus : 'banana split' } ,
330+ { corpus : 'apple' , filename : 'apple.jpg' } ,
331+ { corpus : 'banana' , filename : 'banana.jpg' } ,
332+ { corpus : 'cherry' , filename : 'cherry.jpg' } ,
333+ { corpus : 'banana split' , filename : 'banana-split.jpg' } ,
330334 ]
331335
332336 // Use a wrapper component to access the hook and set visible count
333337 function TestComponent ( ) {
334338 const search = useSearch ( { items, indexedKeywords : [ ] } )
335339
336- // Simulate setting visible count based on filtered results
337- const { filtered, setVisibleCount } = search
340+ // Simulate setting visible count and displayed items based on filtered results
341+ const { filtered, setVisibleCount, setDisplayedItems } = search
338342 React . useEffect ( ( ) => {
339343 setVisibleCount ( filtered . length )
340- } , [ filtered , setVisibleCount ] )
344+ setDisplayedItems ( filtered )
345+ } , [ filtered , setVisibleCount , setDisplayedItems ] )
341346
342347 return < div > { search . searchBox } </ div >
343348 }
@@ -353,7 +358,7 @@ describe('Clear button functionality', () => {
353358 expect ( container . textContent ) . toMatch ( / f o r " b a n " / )
354359
355360 // Find the Clear button
356- const clearButton = container . querySelector ( 'button[title="Clear search"]' ) as HTMLButtonElement
361+ const clearButton = container . querySelector ( 'button[title="Clear search and view adjacent photos "]' ) as HTMLButtonElement
357362
358363 // Mock the search params to return empty after clearing
359364 vi . mocked ( useSearchParams ) . mockReturnValue ( {
@@ -363,7 +368,7 @@ describe('Clear button functionality', () => {
363368 fireEvent . click ( clearButton )
364369
365370 // Verify URL was cleared (router.replace called with path only, no keyword)
366- expect ( mockReplace ) . toHaveBeenCalledWith ( '/gallery/photos' )
371+ expect ( mockReplace ) . toHaveBeenCalledWith ( '/gallery/photos?select=banana.jpg ' )
367372
368373 // Re-render to reflect the cleared state
369374 rerender ( < TestComponent /> )
0 commit comments