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 redirectTo = 'http://localhost/test123';
10 describe('storeRedirects', () => {
12 Object.defineProperty(window, 'location', {
14 href: `${window.location.href}?redirectTo=${redirectTo}`
17 Object.defineProperty(window, 'sessionStorage', {
25 it('should store redirectTo in the session storage', () => {
30 expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
34 describe('handleRedirects', () => {
36 Object.defineProperty(window, 'location', {
41 Object.defineProperty(window, 'sessionStorage', {
43 getItem: () => redirectTo,
44 removeItem: jest.fn(),
50 it('should redirect to page when it is present in session storage', () => {
52 const token = 'testToken';
55 handleRedirects(token);
58 expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);