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 mockWindow: { location?: any, localStorage?: any} = window
10 const { location } = mockWindow;
12 keepWebServiceUrl: 'http://localhost',
13 keepWebServiceInlineUrl: 'http://localhost-inline'
15 const redirectTo = 'c=acbd18db4cc2f85cedef654fccc4a4d8%2B3/foo';
16 const locationTemplate = {
32 afterAll((): void => {
33 mockWindow.location = location;
36 describe('storeRedirects', () => {
38 delete mockWindow.location;
39 mockWindow.location = {
41 href: `${location.href}?redirectToDownload=${redirectTo}`,
43 Object.defineProperty(mockWindow, 'localStorage', {
51 it('should store redirectTo in the session storage', () => {
56 expect(mockWindow.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', decodeURIComponent(redirectTo));
60 describe('handleRedirects', () => {
62 delete mockWindow.location;
63 mockWindow.location = {
65 href: `${location.href}?redirectToDownload=${redirectTo}`,
67 Object.defineProperty(mockWindow, 'localStorage', {
69 getItem: () => redirectTo,
70 removeItem: jest.fn(),
76 it('should redirect to page when it is present in session storage', () => {
78 handleRedirects("abcxyz", config);
81 expect(mockWindow.location.href).toBe(`${config.keepWebServiceUrl}${redirectTo}?api_token=abcxyz`);