Make login/logout tests compatible with jsdom
authorDaniel Kos <daniel.kos@contractors.roche.com>
Wed, 6 Jun 2018 19:05:34 +0000 (21:05 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Wed, 6 Jun 2018 19:05:34 +0000 (21:05 +0200)
Feature #13563

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>:

src/services/auth-service/auth-service.ts
src/store/auth/auth-reducer.test.ts
yarn.lock

index 9e75c72a9fa54f8fa27a2f33c657506823d04556..4b213fb06cb727f62bf5c7e02326d56c077d350d 100644 (file)
@@ -47,11 +47,11 @@ export default class AuthService {
 
     public login() {
         const currentUrl = `${window.location.protocol}//${window.location.host}/token`;
-        window.location.href = `${API_HOST}/login?return_to=${currentUrl}`;
+        window.location.assign(`${API_HOST}/login?return_to=${currentUrl}`);
     }
 
     public logout() {
         const currentUrl = `${window.location.protocol}//${window.location.host}`;
-        window.location.href = `${API_HOST}/logout?return_to=${currentUrl}`;
+        window.location.assign(`${API_HOST}/logout?return_to=${currentUrl}`);
     }
 }
index 9290f57d6bcf281851e4d11cd48662d8dabc4389..f2e20baa8971c93f2b036f2a762697e4f7fc7161 100644 (file)
@@ -12,7 +12,7 @@ import {
 } from "../../services/auth-service/auth-service";
 import { API_HOST } from "../../common/server-api";
 
-require('jest-localstorage-mock');
+import 'jest-localstorage-mock';
 
 describe('auth-reducer', () => {
     beforeAll(() => {
@@ -84,34 +84,18 @@ describe('auth-reducer', () => {
 
     it('should fire external url to login', () => {
         const initialState = undefined;
-
-        const location = {
-            href: 'http://localhost:3000',
-            protocol: 'http:',
-            host: 'localhost:3000'
-        };
-
-        global['window'] = { location };
-
+        window.location.assign = jest.fn();
         authReducer(initialState, actions.LOGIN());
-        expect(window.location.href).toBe(
-            `${API_HOST}/login?return_to=${location.protocol}//${location.host}/token`
+        expect(window.location.assign).toBeCalledWith(
+            `${API_HOST}/login?return_to=${window.location.protocol}//${window.location.host}/token`
         );
     });
 
     it('should fire external url to logout', () => {
         const initialState = undefined;
-
-        const location = {
-            href: 'http://localhost:3000',
-            protocol: 'http:',
-            host: 'localhost:3000'
-        };
-
-        global['window'] = { location };
-
+        window.location.assign = jest.fn();
         authReducer(initialState, actions.LOGOUT());
-        expect(window.location.href).toBe(
+        expect(window.location.assign).toBeCalledWith(
             `${API_HOST}/logout?return_to=${location.protocol}//${location.host}`
         );
     });
index 17549e01dbd103de463b6cf7b5fec27b85bfa1b1..7b9820bb5807c253e3aa0f5c2c5539f9d0053d6d 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -4003,7 +4003,7 @@ jest-leak-detector@^22.4.0:
   dependencies:
     pretty-format "^22.4.3"
 
-jest-localstorage-mock@^2.2.0:
+jest-localstorage-mock@2.2.0:
   version "2.2.0"
   resolved "https://registry.yarnpkg.com/jest-localstorage-mock/-/jest-localstorage-mock-2.2.0.tgz#ce9a9de01dfdde2ad8aa08adf73acc7e5cc394cf"