X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f15181b0b69599cc33385d4af2f1a60de087882b..84b0571030831cdd14fbbf36658cafee52face30:/src/common/redirect-to.test.ts diff --git a/src/common/redirect-to.test.ts b/src/common/redirect-to.test.ts index 24eaada851..0168fd803f 100644 --- a/src/common/redirect-to.test.ts +++ b/src/common/redirect-to.test.ts @@ -5,16 +5,40 @@ import { storeRedirects, handleRedirects } from './redirect-to'; describe('redirect-to', () => { - const redirectTo = 'http://localhost/test123'; + const { location } = window; + 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; + }); describe('storeRedirects', () => { beforeEach(() => { - Object.defineProperty(window, 'location', { - value: { - href: `${window.location.href}?redirectTo=${redirectTo}` - } - }); - Object.defineProperty(window, 'sessionStorage', { + delete window.location; + window.location = { + ...locationTemplate, + href: `${location.href}?redirectToDownload=${redirectTo}`, + } as any; + Object.defineProperty(window, 'localStorage', { value: { setItem: jest.fn(), }, @@ -27,18 +51,18 @@ describe('redirect-to', () => { storeRedirects(); // then - expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo); + expect(window.localStorage.setItem).toHaveBeenCalledWith('redirectToDownload', redirectTo); }); }); describe('handleRedirects', () => { beforeEach(() => { - Object.defineProperty(window, 'location', { - value: { - href: '' - } - }); - Object.defineProperty(window, 'sessionStorage', { + delete window.location; + window.location = { + ...locationTemplate, + href: `${location.href}?redirectToDownload=${redirectTo}`, + } as any;; + Object.defineProperty(window, 'localStorage', { value: { getItem: () => redirectTo, removeItem: jest.fn(), @@ -48,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 +});