1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { storeRedirects, handleRedirects } from './redirect-to';
7 describe('redirect-to', () => {
8 const { location } = window;
10 keepWebServiceUrl: 'http://localhost',
11 keepWebServiceInlineUrl: 'http://localhost-inline'
13 const redirectTo = '/test123';
14 const locationTemplate = {
30 afterAll((): void => {
31 window.location = location;
34 describe('storeRedirects', () => {
36 delete window.location;
39 href: `${location.href}?redirectToDownload=${redirectTo}`,
41 Object.defineProperty(window, 'localStorage', {
49 it('should store redirectTo in the session storage', () => {
54 expect(window.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', redirectTo);
58 describe('handleRedirects', () => {
60 delete window.location;
63 href: `${location.href}?redirectToDownload=${redirectTo}`,
65 Object.defineProperty(window, 'localStorage', {
67 getItem: () => redirectTo,
68 removeItem: jest.fn(),
74 it('should redirect to page when it is present in session storage', () => {
76 handleRedirects("abcxyz", config);
79 expect(window.location.href).toBe(`${config.keepWebServiceUrl}${redirectTo}?api_token=abcxyz`);