mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
use location.replace to ensure the browser can track the redirect in its history
This commit is contained in:
@@ -2,17 +2,25 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { BrowserHardRedirectService } from './browser-hard-redirect.service';
|
||||
|
||||
describe('BrowserHardRedirectService', () => {
|
||||
const origin = 'https://test-host.com:4000';
|
||||
const mockLocation = {
|
||||
href: undefined,
|
||||
pathname: '/pathname',
|
||||
search: '/search',
|
||||
origin
|
||||
} as Location;
|
||||
|
||||
const service: BrowserHardRedirectService = new BrowserHardRedirectService(mockLocation);
|
||||
let origin: string;
|
||||
let mockLocation: Location;
|
||||
let service: BrowserHardRedirectService;
|
||||
|
||||
beforeEach(() => {
|
||||
origin = 'https://test-host.com:4000';
|
||||
mockLocation = {
|
||||
href: undefined,
|
||||
pathname: '/pathname',
|
||||
search: '/search',
|
||||
origin,
|
||||
replace: (url: string) => {
|
||||
mockLocation.href = url;
|
||||
}
|
||||
} as Location;
|
||||
spyOn(mockLocation, 'replace');
|
||||
|
||||
service = new BrowserHardRedirectService(mockLocation);
|
||||
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
@@ -28,8 +36,8 @@ describe('BrowserHardRedirectService', () => {
|
||||
service.redirect(redirect);
|
||||
});
|
||||
|
||||
it('should update the location', () => {
|
||||
expect(mockLocation.href).toEqual(redirect);
|
||||
it('should call location.replace with the new url', () => {
|
||||
expect(mockLocation.replace).toHaveBeenCalledWith(redirect);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -24,7 +24,7 @@ export class BrowserHardRedirectService extends HardRedirectService {
|
||||
* @param url
|
||||
*/
|
||||
redirect(url: string) {
|
||||
this.location.href = url;
|
||||
this.location.replace(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user