@@ -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 { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap' ;
1821import { Store } from '@ngrx/store' ;
@@ -184,6 +187,9 @@ const routeServiceStub = {
184187 getQueryParamsWithPrefix : ( ) => {
185188 return of ( null ) ;
186189 } ,
190+ getQueryParamMap : ( ) => {
191+ return of ( convertToParamMap ( { } ) ) ;
192+ } ,
187193 setParameter : ( key : any , value : any ) => {
188194 return ;
189195 } ,
@@ -203,6 +209,7 @@ export function configureSearchComponentTestingModule(compType, additionalDeclar
203209 setSearchInstanceId : jasmine . createSpy ( 'setSearchInstanceId' ) ,
204210 } ) ;
205211 searchConfigurationServiceStub . getCurrentSearchInstanceParam = ( param : string ) => `${ paginationId } .${ param } ` ;
212+ searchConfigurationServiceStub . isLegacySearchParam = ( param : string ) => [ 'configuration' , 'scope' , 'query' , 'dsoType' , 'view' ] . includes ( param ) || param . startsWith ( 'f.' ) ;
206213
207214 searchConfigurationServiceStub . setSearchInstanceId . and . callFake ( ( pageId ) => {
208215 paginatedSearchOptions$ . next ( Object . assign ( paginatedSearchOptions$ . value , {
@@ -343,6 +350,63 @@ describe('SearchComponent', () => {
343350 expect ( comp . resultFound . emit ) . toHaveBeenCalledWith ( expectedResults ) ;
344351 } ) ) ;
345352
353+ describe ( 'migrateLegacySearchParams' , ( ) => {
354+ let navigateSpy : jasmine . Spy ;
355+
356+ beforeEach ( ( ) => {
357+ comp . platformId = 'browser' ;
358+ comp . searchInstanceId = paginationId ;
359+ navigateSpy = spyOn ( ( comp as any ) . router , 'navigate' ) ;
360+ } ) ;
361+
362+ it ( 'should replace legacy (unprefixed) search params with their prefixed equivalent' , ( ) => {
363+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
364+ query : 'cats' ,
365+ 'f.author' : 'Smith' ,
366+ } ) ) ) ;
367+
368+ ( comp as any ) . migrateLegacySearchParams ( ) ;
369+
370+ expect ( navigateSpy ) . toHaveBeenCalledWith ( [ ] , {
371+ queryParams : {
372+ query : null ,
373+ [ `${ paginationId } .query` ] : 'cats' ,
374+ 'f.author' : null ,
375+ [ `${ paginationId } .f.author` ] : 'Smith' ,
376+ } ,
377+ queryParamsHandling : 'merge' ,
378+ replaceUrl : true ,
379+ } ) ;
380+ } ) ;
381+
382+ it ( 'should not navigate when there are no legacy search params' , ( ) => {
383+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
384+ [ `${ paginationId } .query` ] : 'cats' ,
385+ } ) ) ) ;
386+
387+ ( comp as any ) . migrateLegacySearchParams ( ) ;
388+
389+ expect ( navigateSpy ) . not . toHaveBeenCalled ( ) ;
390+ } ) ;
391+
392+ it ( 'should drop the legacy param without overriding an existing prefixed param' , ( ) => {
393+ spyOn ( ( comp as any ) . routeService , 'getQueryParamMap' ) . and . returnValue ( of ( convertToParamMap ( {
394+ query : 'legacy' ,
395+ [ `${ paginationId } .query` ] : 'prefixed' ,
396+ } ) ) ) ;
397+
398+ ( comp as any ) . migrateLegacySearchParams ( ) ;
399+
400+ expect ( navigateSpy ) . toHaveBeenCalledWith ( [ ] , {
401+ queryParams : {
402+ query : null ,
403+ } ,
404+ queryParamsHandling : 'merge' ,
405+ replaceUrl : true ,
406+ } ) ;
407+ } ) ;
408+ } ) ;
409+
346410 describe ( 'when the open sidebar button is clicked in mobile view' , ( ) => {
347411
348412 beforeEach ( ( ) => {
0 commit comments