Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / common / redirect-to.test.ts
index eed5b4c8e12005d168a2e07ea179ea5d58d5c3c7..adb52f4b0ce494167170c02390433a4ba82dec9f 100644 (file)
@@ -6,7 +6,26 @@ import { storeRedirects, handleRedirects } from './redirect-to';
 
 describe('redirect-to', () => {
     const { location } = window;
-    const redirectTo = 'http://localhost/test123';
+    const config: any = {
+        keepWebServiceUrl: 'http://localhost',
+        keepWebServiceInlineUrl: 'http://localhost-inline'
+    };
+    const redirectTo = 'c=acbd18db4cc2f85cedef654fccc4a4d8%2B3/foo';
+    const locationTemplate = {
+        hash: '',
+        hostname: '',
+        origin: '',
+        host: '',
+        pathname: '',
+        port: '80',
+        protocol: 'http',
+        search: '',
+        reload: () => { },
+        replace: () => { },
+        assign: () => { },
+        ancestorOrigins: [],
+        href: '',
+    };
 
     afterAll((): void => {
         window.location = location;
@@ -16,9 +35,10 @@ describe('redirect-to', () => {
         beforeEach(() => {
             delete window.location;
             window.location = {
-                href: `${location.href}?redirectTo=${redirectTo}`,
+                ...locationTemplate,
+                href: `${location.href}?redirectToDownload=${redirectTo}`,
             } as any;
-            Object.defineProperty(window, 'sessionStorage', {
+            Object.defineProperty(window, 'localStorage', {
                 value: {
                     setItem: jest.fn(),
                 },
@@ -31,7 +51,7 @@ describe('redirect-to', () => {
             storeRedirects();
 
             // then
-            expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
+            expect(window.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', decodeURIComponent(redirectTo));
         });
     });
 
@@ -39,9 +59,10 @@ describe('redirect-to', () => {
         beforeEach(() => {
             delete window.location;
             window.location = {
-                href: `${location.href}?redirectTo=${redirectTo}`,
-            } as any;
-            Object.defineProperty(window, 'sessionStorage', {
+                ...locationTemplate,
+                href: `${location.href}?redirectToDownload=${redirectTo}`,
+            } as any;;
+            Object.defineProperty(window, 'localStorage', {
                 value: {
                     getItem: () => redirectTo,
                     removeItem: jest.fn(),
@@ -51,14 +72,11 @@ describe('redirect-to', () => {
         });
 
         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
+});