forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in task/dspace-cris-2023_02_x/DSC-2176 (pull request DSpace#2801)
[DSC-2176] prevent redirect issue while fetching signposting links Approved-by: Giuseppe Digilio
- Loading branch information
Showing
8 changed files
with
112 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/app/item-page/simple/link-resolver/signposting-links.resolver.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
import { SignpostingDataService } from '../../../core/data/signposting-data.service'; | ||
import { of } from 'rxjs'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { signpostingLinksResolver } from './signposting-links.resolver'; | ||
describe('signpostingLinksResolver', () => { | ||
let resolver: any; | ||
let route: ActivatedRouteSnapshot; | ||
let state = {}; | ||
let signpostingDataService: SignpostingDataService; | ||
const testUuid = '1234567890'; | ||
const mocklink = { | ||
href: 'http://test.org', | ||
rel: 'rel1', | ||
type: 'type1' | ||
}; | ||
const mocklink2 = { | ||
href: 'http://test2.org', | ||
rel: 'rel2', | ||
type: undefined | ||
}; | ||
const resolvedLinks = `<${mocklink.href}> ; rel="${mocklink.rel}" ; type="${mocklink.type}" , <${mocklink2.href}> ; rel="${mocklink2.rel}" `; | ||
const mockTag2 = { | ||
href: 'http://test2.org', | ||
rel: 'rel2', | ||
}; | ||
function init() { | ||
route = Object.assign(new ActivatedRouteSnapshot(), { | ||
params: { | ||
id: testUuid, | ||
}, | ||
}); | ||
signpostingDataService = jasmine.createSpyObj('signpostingDataService', { | ||
getLinks: of([mocklink, mocklink2]), | ||
setLinks: () => null, | ||
}); | ||
resolver = signpostingLinksResolver; | ||
} | ||
function initTestbed() { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{provide: RouterStateSnapshot, useValue: state}, | ||
{provide: ActivatedRouteSnapshot, useValue: route}, | ||
{provide: SignpostingDataService, useValue: signpostingDataService}, | ||
] | ||
}); | ||
} | ||
describe('when an item page is loaded', () => { | ||
beforeEach(() => { | ||
init(); | ||
initTestbed(); | ||
}); | ||
it('should retrieve links and set header and head tags', () => { | ||
TestBed.runInInjectionContext(() => { | ||
resolver(route, state).subscribe(() => { | ||
expect(signpostingDataService.getLinks).toHaveBeenCalledWith(testUuid); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
src/app/item-page/simple/link-resolver/signposting-links.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ActivatedRouteSnapshot, ResolveFn, RouterStateSnapshot } from '@angular/router'; | ||
import { SignpostingLink } from '../../../core/data/signposting-links.model'; | ||
import { Observable, of } from 'rxjs'; | ||
import { inject } from '@angular/core'; | ||
import { hasValue } from '../../../shared/empty.util'; | ||
import { SignpostingDataService } from '../../../core/data/signposting-data.service'; | ||
|
||
/** | ||
* Resolver to retrieve signposting links before an eventual redirect of any route guard | ||
* | ||
* @param route | ||
* @param state | ||
* @param signpostingDataService | ||
*/ | ||
export const signpostingLinksResolver: ResolveFn<Observable<SignpostingLink[]>> = ( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot, | ||
signpostingDataService: SignpostingDataService = inject(SignpostingDataService), | ||
): Observable<SignpostingLink[]> => { | ||
const uuid = route.params.id; | ||
if (!hasValue(uuid)) { | ||
return of([]); | ||
} | ||
return signpostingDataService.getLinks(uuid); | ||
}; |