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}`
18 Object.defineProperty(window, 'sessionStorage', {
26 it('should store redirectTo in the session storage', () => {
31 expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
35 describe('handleRedirects', () => {
37 Object.defineProperty(window, 'location', {
43 Object.defineProperty(window, 'sessionStorage', {
45 getItem: () => redirectTo,
46 removeItem: jest.fn(),
52 it('should redirect to page when it is present in session storage', () => {
54 const token = 'testToken';
57 handleRedirects(token);
60 expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);