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;
9 const redirectTo = 'http://localhost/test123';
10 const locationTemplate = {
26 afterAll((): void => {
27 window.location = location;
30 describe('storeRedirects', () => {
32 delete window.location;
35 href: `${location.href}?redirectTo=${redirectTo}`,
37 Object.defineProperty(window, 'sessionStorage', {
45 it('should store redirectTo in the session storage', () => {
50 expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
54 describe('handleRedirects', () => {
56 delete window.location;
59 href: `${location.href}?redirectTo=${redirectTo}`,
61 Object.defineProperty(window, 'sessionStorage', {
63 getItem: () => redirectTo,
64 removeItem: jest.fn(),
70 it('should redirect to page when it is present in session storage', () => {
72 const token = 'testToken';
75 handleRedirects(token);
78 expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);