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 // PDH is immaterial; for explanation: md5+sizehint of manifest (replace
16 // <LF> with linefeed char)
17 // `. d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo\040-\040%27?a=b<LF>`
18 // ie. empty file with filename 'foo - %27?a=b'
19 const underlyingPath = '/c=6b1c735de6ae0f2e60cd75d7de36476f+61/foo - %27?a=b';
20 const redirectToParamInput = '/c=6b1c735de6ae0f2e60cd75d7de36476f%2B61/foo%20-%20%2527?a=b';
21 const locationTemplate = {
37 afterAll((): void => {
38 mockWindow.location = location;
41 describe('storeRedirects', () => {
43 delete mockWindow.location;
44 mockWindow.location = {
46 href: `${location.href}?redirectToDownload=${redirectToParamInput}`,
48 Object.defineProperty(mockWindow, 'localStorage', {
56 it('should store decoded target path in the local storage', () => {
61 expect(mockWindow.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', underlyingPath);
65 describe('handleRedirects', () => {
67 delete mockWindow.location;
68 mockWindow.location = {
70 href: `${location.href}?redirectToDownload=${redirectToParamInput}`,
72 Object.defineProperty(mockWindow, 'localStorage', {
74 getItem: () => underlyingPath,
75 removeItem: jest.fn(),
81 it('should redirect to page when it is present in local storage', () => {
83 handleRedirects("abcxyz", config);
86 let navTarget = new URL(mockWindow.location.href);
87 expect(navTarget.origin).toBe(config.keepWebServiceUrl);
88 expect(decodeURIComponent(navTarget.pathname)).toBe(underlyingPath);
89 expect(navTarget.search).toBe('?api_token=abcxyz');