@@ -315,30 +315,29 @@ describe('UnifiedSearchController', () => {
315315 expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk' , 'deck' ] )
316316 } )
317317
318- it ( 'keeps reveal positions across a refined query' , async ( ) => {
318+ it ( 'restarts the reveal order from priority on a new query' , async ( ) => {
319319 const first = mockProviders ( [ 'files' , 'talk' ] )
320320
321321 const searchController = new UnifiedSearchController ( )
322322 searchController . search ( 'old' , [ 'files' , 'talk' ] )
323323
324- // talk gets on screen first, so the session order is talk before files.
324+ // talk got on screen first, so this query renders talk above files.
325325 first . talk . resolve ( [ 'Old talk' ] )
326326 await vi . advanceTimersByTimeAsync ( REVEAL_INTERVAL_MS )
327327 first . files . resolve ( [ 'Old files' ] )
328328 await vi . advanceTimersByTimeAsync ( 0 )
329329 expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk' , 'files' ] )
330330
331- // Refining must not re-sort what is already on screen back to priority order.
332- // Both categories stay rendered throughout (stale-while-revalidate), so moving
333- // them would be a displacement with identical content.
331+ // A new query hides everything: the results are about to be different, so there is
332+ // nothing on screen to protect and the next paint starts from priority order again.
334333 const second = mockProviders ( [ 'files' , 'talk' ] )
335334 searchController . search ( 'new' , [ 'files' , 'talk' ] )
336- expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk' , 'files' ] )
335+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ ] )
337336
338337 second . files . resolve ( [ 'New files' ] )
339338 second . talk . resolve ( [ 'New talk' ] )
340339 await vi . advanceTimersByTimeAsync ( 0 )
341- expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk ' , 'files ' ] )
340+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'files ' , 'talk ' ] )
342341 } )
343342
344343 it ( 'releases a slot when a category loses its results, and appends it again if it returns' , async ( ) => {
@@ -360,17 +359,17 @@ describe('UnifiedSearchController', () => {
360359 await vi . advanceTimersByTimeAsync ( 0 )
361360 expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk' ] )
362361
363- // It has results again on the next query , so it comes back as a fresh reveal:
364- // at the end, not back at its old priority slot .
362+ // The next query is a clean slate , so it comes back in preferred order rather than
363+ // staying demoted for the rest of the session .
365364 const third = mockProviders ( [ 'files' , 'talk' ] )
366365 searchController . search ( 'c' , [ 'files' , 'talk' ] )
367366 third . files . resolve ( [ 'Files c' ] )
368367 third . talk . resolve ( [ 'Talk c' ] )
369368 await vi . advanceTimersByTimeAsync ( 0 )
370- expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk ' , 'files ' ] )
369+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'files ' , 'talk ' ] )
371370 } )
372371
373- it ( 're-appends a category that left the search entirely instead of reclaiming its old slot ' , async ( ) => {
372+ it ( 'recovers preferred order after a provider filter round trip ' , async ( ) => {
374373 const first = mockProviders ( [ 'files' , 'talk' ] )
375374
376375 const searchController = new UnifiedSearchController ( )
@@ -380,24 +379,22 @@ describe('UnifiedSearchController', () => {
380379 await vi . advanceTimersByTimeAsync ( 0 )
381380 expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'files' , 'talk' ] )
382381
383- // A provider filter narrows the search: files leaves the category list altogether,
384- // which is a different exit from losing its results (that one goes through
385- // syncRevealOrder; this one goes through the prune in search()).
382+ // A provider filter narrows the search: files leaves the category list altogether.
386383 const second = mockProviders ( [ 'talk' ] )
387384 searchController . search ( 'foo' , [ 'talk' ] )
388385 second . talk . resolve ( [ 'Talk result' ] )
389386 await vi . advanceTimersByTimeAsync ( 0 )
390387 expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk' ] )
391388
392- // The filter comes off. talk never left the screen , so files has to come back below
393- // it: reclaiming slot 0 would shove a rendered group down .
389+ // The filter comes off. Each search stands on its own , so files is back on top
390+ // instead of being stuck below talk until the popover closes .
394391 const third = mockProviders ( [ 'files' , 'talk' ] )
395392 searchController . search ( 'foo' , [ 'files' , 'talk' ] )
396393 third . files . resolve ( [ 'Files result' ] )
397394 third . talk . resolve ( [ 'Talk result' ] )
398395 await vi . advanceTimersByTimeAsync ( 0 )
399396
400- expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'talk ' , 'files ' ] )
397+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'files ' , 'talk ' ] )
401398 } )
402399
403400 it ( 'never hands out a category the snapshot cannot index, part-way through a search' , async ( ) => {
@@ -443,41 +440,39 @@ describe('UnifiedSearchController', () => {
443440 first . talk . resolve ( [ 'Talk result' ] )
444441 await vi . advanceTimersByTimeAsync ( 0 )
445442
446- // A narrower search replaces the first. The dropped categories must
447- // not linger in the snapshot, nor in the display order: the view maps the
448- // order straight onto the snapshot and would hit a missing category.
443+ // A narrower search replaces the first. The dropped categories must not linger in
444+ // the snapshot, and nothing from the previous query stays on screen.
449445 mockProviders ( [ 'files' ] )
450446 searchController . search ( 'second' , [ 'files' ] )
451447
452448 expect ( searchController . getSnapshot ( ) ) . toEqual ( {
453- files : { status : ' loading' , entries : [ 'Files result' ] , cursor : null , hasMore : false , loadMoreFailed : false } ,
449+ files : loading ,
454450 } )
455- expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ 'files' ] )
451+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ ] )
456452 } )
457453 } )
458454
459- describe ( 'stale-while-revalidate ' , ( ) => {
460- it ( 'keeps the previous results visible while a refetch is in flight ' , async ( ) => {
455+ describe ( 'changing the query ' , ( ) => {
456+ it ( 'drops the previous results as soon as the query changes ' , async ( ) => {
461457 const first = mockProviders ( [ 'files' ] )
462458
463459 const searchController = new UnifiedSearchController ( )
464460 searchController . search ( 'old' , [ 'files' ] )
465461 first . files . resolve ( [ 'Old result' ] )
466462 await vi . advanceTimersByTimeAsync ( 0 )
467463
468- // A refined query starts a new search. The prior entries must stay on screen
469- // (status loading, entries kept) so the panel does not flash empty mid-request .
464+ // The new query is about to return different results, so keeping the old ones up
465+ // would only let them shift under the user once the real ones land. Hide, then show .
470466 const second = mockProviders ( [ 'files' ] )
471467 searchController . search ( 'new' , [ 'files' ] )
472468 expect ( searchController . getSnapshot ( ) . files ) . toEqual ( {
473469 status : 'loading' ,
474- entries : [ 'Old result' ] ,
470+ entries : [ ] ,
475471 cursor : null ,
476472 hasMore : false ,
477473 loadMoreFailed : false ,
478474 } )
479475
480- // The fresh page replaces them once it lands.
481476 second . files . resolve ( [ 'New result' ] )
482477 await vi . advanceTimersByTimeAsync ( 0 )
483478 expect ( searchController . getSnapshot ( ) . files ) . toEqual ( {
@@ -489,7 +484,7 @@ describe('UnifiedSearchController', () => {
489484 } )
490485 } )
491486
492- it ( 'settles a refetched category that carried results straight to loaded, never blocked ' , async ( ) => {
487+ it ( 'puts every category back through the ordered reveal on a new query ' , async ( ) => {
493488 const first = mockProviders ( [ 'files' , 'talk' ] )
494489
495490 const searchController = new UnifiedSearchController ( )
@@ -499,23 +494,15 @@ describe('UnifiedSearchController', () => {
499494 first . talk . resolve ( [ 'Old talk' ] )
500495 await vi . advanceTimersByTimeAsync ( 0 )
501496
502- // Refine. talk (lower priority) comes back before files this time. It already had
503- // results, so it must not drop into blocked (which excludes it from the rendered
504- // set and blinks it off screen); it stays visible by settling straight to loaded.
497+ // Refine. talk comes back first this time. Nothing is on screen to protect any more,
498+ // so it takes its turn in the queue again instead of skipping the reveal.
505499 const second = mockProviders ( [ 'files' , 'talk' ] )
506500 searchController . search ( 'new' , [ 'files' , 'talk' ] )
507501 second . talk . resolve ( [ 'New talk' ] )
508502 await vi . advanceTimersByTimeAsync ( 0 )
509503
510- expect ( searchController . getSnapshot ( ) . talk . status ) . toBe ( 'loaded' )
511- // files is still fetching; its stale page stays up meanwhile.
512- expect ( searchController . getSnapshot ( ) . files ) . toEqual ( {
513- status : 'loading' ,
514- entries : [ 'Old files' ] ,
515- cursor : null ,
516- hasMore : false ,
517- loadMoreFailed : false ,
518- } )
504+ expect ( searchController . getSnapshot ( ) . talk . status ) . toBe ( 'blocked' )
505+ expect ( searchController . getRevealOrder ( ) ) . toEqual ( [ ] )
519506 } )
520507 } )
521508
@@ -1070,10 +1057,8 @@ describe('UnifiedSearchController', () => {
10701057 const searchController = new UnifiedSearchController ( )
10711058 searchController . search ( 'first' , [ 'files' , 'talk' ] )
10721059
1073- // The first search spends its window on talk, then stands the timer down. talk
1074- // comes back empty so it carries no stale results into the second search, which
1075- // would otherwise settle it straight to loaded and never block it.
1076- first . talk . resolve ( [ ] )
1060+ // The first search spends its window on talk, then stands the timer down.
1061+ first . talk . resolve ( [ 'First talk' ] )
10771062 await vi . advanceTimersByTimeAsync ( REVEAL_INTERVAL_MS )
10781063 expect ( searchController . getSnapshot ( ) . talk . status ) . toBe ( 'loaded' )
10791064 expect ( vi . getTimerCount ( ) ) . toBe ( 0 )
0 commit comments