]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Remove unit tests warnings
authorTiago Melo <tmelo@suse.com>
Mon, 5 Nov 2018 10:59:13 +0000 (10:59 +0000)
committerTiago Melo <tmelo@suse.com>
Tue, 6 Nov 2018 11:12:26 +0000 (11:12 +0000)
Recent Angular update is causing a warning to be shown when you call
"router.navigate" outside an angular zone.

This is not affecting the code itself, just the unit tests.

Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/breadcrumbs/breadcrumbs.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts

index bfc86a7766c60d224faae289141c44ff4e53767b..f593d268ec85d2ef0eaee80894b31d38bb75d16c 100644 (file)
@@ -65,7 +65,9 @@ describe('BreadcrumbsComponent', () => {
   });
 
   it('should run postProcess and split the breadcrumbs when navigating to hosts', fakeAsync(() => {
-    router.navigateByUrl('/hosts');
+    fixture.ngZone.run(() => {
+      router.navigateByUrl('/hosts');
+    });
     tick();
     expect(component.crumbs).toEqual([
       { path: null, text: 'Cluster' },
@@ -74,7 +76,9 @@ describe('BreadcrumbsComponent', () => {
   }));
 
   it('should display empty breadcrumb when navigating to perf_counters from unknown path', fakeAsync(() => {
-    router.navigateByUrl('/perf_counters');
+    fixture.ngZone.run(() => {
+      router.navigateByUrl('/perf_counters');
+    });
     tick();
     expect(component.crumbs).toEqual([
       { path: null, text: 'Cluster' },
@@ -84,7 +88,9 @@ describe('BreadcrumbsComponent', () => {
   }));
 
   it('should display Monitor breadcrumb when navigating to perf_counters from Monitors', fakeAsync(() => {
-    router.navigate(['/perf_counters'], { queryParams: { fromLink: '/monitor' } });
+    fixture.ngZone.run(() => {
+      router.navigate(['/perf_counters'], { queryParams: { fromLink: '/monitor' } });
+    });
     tick();
     expect(component.crumbs).toEqual([
       { path: null, text: 'Cluster' },
@@ -94,7 +100,9 @@ describe('BreadcrumbsComponent', () => {
   }));
 
   it('should display Hosts breadcrumb when navigating to perf_counters from Hosts', fakeAsync(() => {
-    router.navigate(['/perf_counters'], { queryParams: { fromLink: '/hosts' } });
+    fixture.ngZone.run(() => {
+      router.navigate(['/perf_counters'], { queryParams: { fromLink: '/hosts' } });
+    });
     tick();
     expect(component.crumbs).toEqual([
       { path: null, text: 'Cluster' },
@@ -104,7 +112,9 @@ describe('BreadcrumbsComponent', () => {
   }));
 
   it('should show all 3 breadcrumbs when navigating to RBD Add', fakeAsync(() => {
-    router.navigateByUrl('/block/rbd/add');
+    fixture.ngZone.run(() => {
+      router.navigateByUrl('/block/rbd/add');
+    });
     tick();
     expect(component.crumbs).toEqual([
       { path: null, text: 'Block' },
index ff1012191122db4b62267de1a2d79be9b4c85ea8..bf8c71c34d8323b98c9536a0d4ab1b5ff2ab178b 100644 (file)
@@ -1,4 +1,4 @@
-import { Component } from '@angular/core';
+import { Component, NgZone } from '@angular/core';
 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
 import { Router, Routes } from '@angular/router';
 import { RouterTestingModule } from '@angular/router/testing';
@@ -10,6 +10,7 @@ import { AuthStorageService } from './auth-storage.service';
 describe('AuthGuardService', () => {
   let service: AuthGuardService;
   let authStorageService: AuthStorageService;
+  let ngZone: NgZone;
 
   @Component({ selector: 'cd-login', template: '' })
   class LoginComponent {}
@@ -25,6 +26,7 @@ describe('AuthGuardService', () => {
   beforeEach(() => {
     service = TestBed.get(AuthGuardService);
     authStorageService = TestBed.get(AuthStorageService);
+    ngZone = TestBed.get(NgZone);
   });
 
   it('should be created', () => {
@@ -38,7 +40,9 @@ describe('AuthGuardService', () => {
 
   it('should prevent user if not loggedIn and redirect to login page', fakeAsync(() => {
     const router = TestBed.get(Router);
-    expect(service.canActivate(null, null)).toBe(false);
+    ngZone.run(() => {
+      expect(service.canActivate(null, null)).toBe(false);
+    });
     tick();
     expect(router.url).toBe('/login');
   }));
index a4d5eb8f4118ab9122331225bd320257ed7a8f72..112a194f12a22b9d6b3653c77f71f6799fc53f94 100644 (file)
@@ -1,5 +1,5 @@
 import { HttpClient } from '@angular/common/http';
-import { Component } from '@angular/core';
+import { Component, NgZone } from '@angular/core';
 import { fakeAsync, TestBed, tick } from '@angular/core/testing';
 import { ActivatedRouteSnapshot, Router, Routes } from '@angular/router';
 import { RouterTestingModule } from '@angular/router/testing';
@@ -14,6 +14,7 @@ describe('ModuleStatusGuardService', () => {
   let httpClient: HttpClient;
   let router: Router;
   let route: ActivatedRouteSnapshot;
+  let ngZone: NgZone;
 
   @Component({ selector: 'cd-foo', template: '' })
   class FooComponent {}
@@ -27,8 +28,10 @@ describe('ModuleStatusGuardService', () => {
   const testCanActivate = (getResult: {}, activateResult: boolean, urlResult: string) => {
     let result: boolean;
     spyOn(httpClient, 'get').and.returnValue(observableOf(getResult));
-    service.canActivateChild(route, null).subscribe((resp) => {
-      result = resp;
+    ngZone.run(() => {
+      service.canActivateChild(route, null).subscribe((resp) => {
+        result = resp;
+      });
     });
 
     tick();
@@ -56,6 +59,7 @@ describe('ModuleStatusGuardService', () => {
         redirectTo: '/foo'
       }
     };
+    ngZone = TestBed.get(NgZone);
   });
 
   it('should be created', () => {