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: '',
+ origin: '',
+ host: '',
+ pathname: '',
+ port: '80',
+ protocol: 'http',
+ search: '',
+ reload: () => { },
+ replace: () => { },
+ assign: () => { },
+ ancestorOrigins: [],
+ href: '',
+ };
afterAll((): void => {
window.location = location;
beforeEach(() => {
delete window.location;
window.location = {
- href: `${location.href}?redirectTo=${redirectTo}`,
- };
- Object.defineProperty(window, 'sessionStorage', {
+ ...locationTemplate,
+ href: `${location.href}?redirectToDownload=${redirectTo}`,
+ } as any;
+ Object.defineProperty(window, 'localStorage', {
value: {
setItem: jest.fn(),
},
storeRedirects();
// then
- expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
+ expect(window.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', redirectTo);
});
});
beforeEach(() => {
delete window.location;
window.location = {
- href: `${location.href}?redirectTo=${redirectTo}`,
- };
- Object.defineProperty(window, 'sessionStorage', {
+ ...locationTemplate,
+ href: `${location.href}?redirectToDownload=${redirectTo}`,
+ } as any;;
+ 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
+});