@@ -12,7 +12,10 @@ import {
1212} from '@angular/core/testing' ;
1313import { By } from '@angular/platform-browser' ;
1414import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
15- import { ActivatedRoute } from '@angular/router' ;
15+ import {
16+ ActivatedRoute ,
17+ convertToParamMap ,
18+ } from '@angular/router' ;
1619import { RouterTestingModule } from '@angular/router/testing' ;
1720import { APP_CONFIG } from '@dspace/config/app-config.interface' ;
1821import { SearchManager } from '@dspace/core/browse/search-manager' ;
@@ -188,6 +191,9 @@ const routeServiceStub = {
188191 getQueryParamsWithPrefix : ( ) => {
189192 return of ( null ) ;
190193 } ,
194+ getQueryParamMap : ( ) => {
195+ return of ( convertToParamMap ( { } ) ) ;
196+ } ,
191197 setParameter : ( key : any , value : any ) => {
192198 return ;
193199 } ,
@@ -207,6 +213,7 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar
207213 setSearchInstanceId : jasmine . createSpy ( 'setSearchInstanceId' ) ,
208214 } ) ;
209215 searchConfigurationServiceStub . getCurrentSearchInstanceParam = ( param : string ) => `${ paginationId } .${ param } ` ;
216+ searchConfigurationServiceStub . isLegacySearchParam = ( param : string ) => [ 'configuration' , 'scope' , 'query' , 'dsoType' , 'view' ] . includes ( param ) || param . startsWith ( 'f.' ) ;
210217
211218 searchConfigurationServiceStub . setSearchInstanceId . and . callFake ( ( pageId ) => {
212219 paginatedSearchOptions$ . next ( Object . assign ( paginatedSearchOptions$ . value , {
@@ -348,6 +355,63 @@ describe('SearchComponent', () => {
348355 expect ( comp . resultFound . emit ) . toHaveBeenCalledWith ( expectedResults ) ;
349356 } ) ) ;
350357
358+ describe ( 'migrateLegacySearchParams' , ( ) => {
359+ let navigateSpy : jasmine . Spy ;
360+
361+ beforeEach ( ( ) => {
362+ comp . platformId = 'browser' ;
363+ comp . searchInstanceId = paginationId ;
364+ navigateSpy = spyOn ( ( comp as any ) . router , 'navigate' ) ;
365+ } ) ;
366+
367+ it ( 'should replace legacy (unprefixed) search params with their prefixed equivalent' , ( ) => {
368+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
369+ query : 'cats' ,
370+ 'f.author' : 'Smith' ,
371+ } ) ) ) ;
372+
373+ ( comp as any ) . migrateLegacySearchParams ( ) ;
374+
375+ expect ( navigateSpy ) . toHaveBeenCalledWith ( [ ] , {
376+ queryParams : {
377+ query : null ,
378+ [ `${ paginationId } .query` ] : 'cats' ,
379+ 'f.author' : null ,
380+ [ `${ paginationId } .f.author` ] : 'Smith' ,
381+ } ,
382+ queryParamsHandling : 'merge' ,
383+ replaceUrl : true ,
384+ } ) ;
385+ } ) ;
386+
387+ it ( 'should not navigate when there are no legacy search params' , ( ) => {
388+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
389+ [ `${ paginationId } .query` ] : 'cats' ,
390+ } ) ) ) ;
391+
392+ ( comp as any ) . migrateLegacySearchParams ( ) ;
393+
394+ expect ( navigateSpy ) . not . toHaveBeenCalled ( ) ;
395+ } ) ;
396+
397+ it ( 'should drop the legacy param without overriding an existing prefixed param' , ( ) => {
398+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
399+ query : 'legacy' ,
400+ [ `${ paginationId } .query` ] : 'prefixed' ,
401+ } ) ) ) ;
402+
403+ ( comp as any ) . migrateLegacySearchParams ( ) ;
404+
405+ expect ( navigateSpy ) . toHaveBeenCalledWith ( [ ] , {
406+ queryParams : {
407+ query : null ,
408+ } ,
409+ queryParamsHandling : 'merge' ,
410+ replaceUrl : true ,
411+ } ) ;
412+ } ) ;
413+ } ) ;
414+
351415 describe ( 'when the open sidebar button is clicked in mobile view' , ( ) => {
352416
353417 beforeEach ( ( ) => {
0 commit comments