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';
11 afterAll((): void => {
12 window.location = location;
15 describe('storeRedirects', () => {
17 delete window.location;
19 href: `${location.href}?redirectTo=${redirectTo}`,
21 Object.defineProperty(window, 'sessionStorage', {
29 it('should store redirectTo in the session storage', () => {
34 expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
38 describe('handleRedirects', () => {
40 delete window.location;
42 href: `${location.href}?redirectTo=${redirectTo}`,
44 Object.defineProperty(window, 'sessionStorage', {
46 getItem: () => redirectTo,
47 removeItem: jest.fn(),
53 it('should redirect to page when it is present in session storage', () => {
55 const token = 'testToken';
58 handleRedirects(token);
61 expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);