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';
|
import { BrowserHardRedirectService } from './browser-hard-redirect.service';
|
||||||
|
|
||||||
describe('BrowserHardRedirectService', () => {
|
describe('BrowserHardRedirectService', () => {
|
||||||
const origin = 'https://test-host.com:4000';
|
let origin: string;
|
||||||
const mockLocation = {
|
let mockLocation: Location;
|
||||||
|
let service: BrowserHardRedirectService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
origin = 'https://test-host.com:4000';
|
||||||
|
mockLocation = {
|
||||||
href: undefined,
|
href: undefined,
|
||||||
pathname: '/pathname',
|
pathname: '/pathname',
|
||||||
search: '/search',
|
search: '/search',
|
||||||
origin
|
origin,
|
||||||
|
replace: (url: string) => {
|
||||||
|
mockLocation.href = url;
|
||||||
|
}
|
||||||
} as Location;
|
} as Location;
|
||||||
|
spyOn(mockLocation, 'replace');
|
||||||
|
|
||||||
const service: BrowserHardRedirectService = new BrowserHardRedirectService(mockLocation);
|
service = new BrowserHardRedirectService(mockLocation);
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,8 +36,8 @@ describe('BrowserHardRedirectService', () => {
|
|||||||
service.redirect(redirect);
|
service.redirect(redirect);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the location', () => {
|
it('should call location.replace with the new url', () => {
|
||||||
expect(mockLocation.href).toEqual(redirect);
|
expect(mockLocation.replace).toHaveBeenCalledWith(redirect);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ export class BrowserHardRedirectService extends HardRedirectService {
|
|||||||
* @param url
|
* @param url
|
||||||
*/
|
*/
|
||||||
redirect(url: string) {
|
redirect(url: string) {
|
||||||
this.location.href = url;
|
this.location.replace(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user