@@ -340,6 +340,67 @@ test.describe('Search Plugin Tests', () => {
340340 await expect ( resultsHeadingElm ) . toHaveText ( 'EmptyContent' ) ;
341341 } ) ;
342342
343+ test ( 'does not restore deleted sections after rebuilding an expired cache' , async ( {
344+ page,
345+ } ) => {
346+ const options = {
347+ config : {
348+ search : { paths : [ '/' ] , namespace : 'cache-refresh' , maxAge : - 1 } ,
349+ } ,
350+ markdown : { homepage : '# Obsolete\n\nretiredkeyword' } ,
351+ scriptURLs : [ '/dist/plugins/search.js' ] ,
352+ } ;
353+ const searchField = page . locator ( 'input[type=search]' ) ;
354+ const results = page . locator ( '.results-panel .title' ) ;
355+
356+ await docsifyInit ( options ) ;
357+ await searchField . fill ( 'retiredkeyword' ) ;
358+ await expect ( results ) . toHaveText ( 'Obsolete' ) ;
359+
360+ options . config . search . maxAge = 60000 ;
361+ options . markdown . homepage = '# Current\n\ncurrentkeyword' ;
362+ await docsifyInit ( options ) ;
363+ await searchField . fill ( 'currentkeyword' ) ;
364+ await expect ( results ) . toHaveText ( 'Current' ) ;
365+ await searchField . fill ( 'retiredkeyword' ) ;
366+ await expect ( page . getByText ( 'No Results!' , { exact : true } ) ) . toBeVisible ( ) ;
367+
368+ await docsifyInit ( options ) ;
369+ await searchField . fill ( 'currentkeyword' ) ;
370+ await expect ( results ) . toHaveText ( 'Current' ) ;
371+ await searchField . fill ( 'retiredkeyword' ) ;
372+ await expect ( page . getByText ( 'No Results!' , { exact : true } ) ) . toBeVisible ( ) ;
373+ } ) ;
374+
375+ test ( 'preserves another namespace when saving a search index' , async ( {
376+ page,
377+ } ) => {
378+ const otherSite = {
379+ config : { search : { paths : [ '/' ] , namespace : 'other-site' } } ,
380+ markdown : { homepage : '# Other site\n\nprotectedkeyword' } ,
381+ scriptURLs : [ '/dist/plugins/search.js' ] ,
382+ } ;
383+ const searchField = page . locator ( 'input[type=search]' ) ;
384+ const results = page . locator ( '.results-panel .title' ) ;
385+
386+ await docsifyInit ( otherSite ) ;
387+ await searchField . fill ( 'protectedkeyword' ) ;
388+ await expect ( results ) . toHaveText ( 'Other site' ) ;
389+
390+ await docsifyInit ( {
391+ config : { search : { paths : [ '/' ] , namespace : 'current-site' } } ,
392+ markdown : { homepage : '# Current site\n\ncurrentkeyword' } ,
393+ scriptURLs : [ '/dist/plugins/search.js' ] ,
394+ } ) ;
395+ await searchField . fill ( 'currentkeyword' ) ;
396+ await expect ( results ) . toHaveText ( 'Current site' ) ;
397+
398+ otherSite . markdown . homepage = '# Changed\n\nchangedkeyword' ;
399+ await docsifyInit ( otherSite ) ;
400+ await searchField . fill ( 'protectedkeyword' ) ;
401+ await expect ( results ) . toHaveText ( 'Other site' ) ;
402+ } ) ;
403+
343404 test ( 'keeps saving index when one auto path request fails with cached records' , async ( {
344405 page,
345406 } ) => {
0 commit comments