describe('redirect-to', () => {
const { location } = window;
- const redirectTo = 'http://localhost/test123';
+ const config: any = {
+ keepWebServiceUrl: 'http://localhost',
+ keepWebServiceInlineUrl: 'http://localhost-inline'
+ };
+ const redirectTo = '/test123';
const locationTemplate = {
hash: '',
hostname: '',
port: '80',
protocol: 'http',
search: '',
- reload: () => {},
- replace: () => {},
- assign: () => {},
+ reload: () => { },
+ replace: () => { },
+ assign: () => { },
ancestorOrigins: [],
href: '',
};
delete window.location;
window.location = {
...locationTemplate,
- href: `${location.href}?redirectTo=${redirectTo}`,
+ href: `${location.href}?redirectToDownload=${redirectTo}`,
} as any;
- Object.defineProperty(window, 'sessionStorage', {
+ Object.defineProperty(window, 'localStorage', {
value: {
setItem: jest.fn(),
},
storeRedirects();
// then
- expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
+ expect(window.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', redirectTo);
});
});
delete window.location;
window.location = {
...locationTemplate,
- href: `${location.href}?redirectTo=${redirectTo}`,
+ href: `${location.href}?redirectToDownload=${redirectTo}`,
} as any;;
- Object.defineProperty(window, 'sessionStorage', {
+ Object.defineProperty(window, 'localStorage', {
value: {
getItem: () => redirectTo,
removeItem: jest.fn(),
});
it('should redirect to page when it is present in session storage', () => {
- // given
- const token = 'testToken';
-
// when
- handleRedirects(token);
+ handleRedirects("abcxyz", config);
// then
- expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);
+ expect(window.location.href).toBe(`${config.keepWebServiceUrl}${redirectTo}?api_token=abcxyz`);
});
});
-});
\ No newline at end of file
+});