]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Remove unnecessary fake services 22473/head
authorStephan Müller <smueller@suse.com>
Tue, 5 Jun 2018 10:16:26 +0000 (12:16 +0200)
committerStephan Müller <smueller@suse.com>
Fri, 15 Jun 2018 13:13:49 +0000 (15:13 +0200)
Removed unnecessary fake services.

Signed-off-by: Stephan Müller <smueller@suse.com>
20 files changed:
src/pybind/mgr/dashboard/frontend/src/app/app.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/mirroring.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-detail/cephfs-detail.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-details/rgw-daemon-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/logout/logout.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notifications/notifications.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
src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts

index 442a046285296168b41e394c9388cb1fe414c757..9182e31bd707803b6c627a7ec376b6808fcd3b8a 100644 (file)
@@ -12,17 +12,11 @@ describe('AppComponent', () => {
   let component: AppComponent;
   let fixture: ComponentFixture<AppComponent>;
 
-  const fakeService = {
-    isLoggedIn: () => {
-      return true;
-    }
-  };
-
   configureTestBed({
     imports: [RouterTestingModule, ToastModule.forRoot()],
     declarations: [AppComponent],
     schemas: [NO_ERRORS_SCHEMA],
-    providers: [{ provide: AuthStorageService, useValue: fakeService }]
+    providers: [AuthStorageService]
   });
 
   beforeEach(() => {
index 22070035f679a43fbc5bca8dea5b640f31e6c193..0f4878e2b00fac9818f45404f78951d62222379d 100644 (file)
@@ -3,9 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { BsDropdownModule, TabsModule } from 'ngx-bootstrap';
 import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
-import { Observable } from 'rxjs';
 
-import { RbdMirroringService } from '../../../shared/api/rbd-mirroring.service';
 import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
 import { MirrorHealthColorPipe } from '../mirror-health-color.pipe';
@@ -15,14 +13,6 @@ describe('MirroringComponent', () => {
   let component: MirroringComponent;
   let fixture: ComponentFixture<MirroringComponent>;
 
-  const fakeService = {
-    get: (service_type: string, service_id: string) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    }
-  };
-
   configureTestBed({
     declarations: [MirroringComponent, MirrorHealthColorPipe],
     imports: [
@@ -31,8 +21,7 @@ describe('MirroringComponent', () => {
       TabsModule.forRoot(),
       ProgressbarModule.forRoot(),
       HttpClientTestingModule
-    ],
-    providers: [{ provide: RbdMirroringService, useValue: fakeService }]
+    ]
   });
 
   beforeEach(() => {
index 5928c198412bb86dc586938a161ffec7e0d7c745..31e65be2ae4617e3b52abd28be486f064be37117 100644 (file)
@@ -1,8 +1,8 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
 import { BsDropdownModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs';
 
 import { CephfsService } from '../../../shared/api/cephfs.service';
 import { SharedModule } from '../../../shared/shared.module';
@@ -13,23 +13,15 @@ describe('CephfsClientsComponent', () => {
   let component: CephfsClientsComponent;
   let fixture: ComponentFixture<CephfsClientsComponent>;
 
-  const fakeFilesystemService = {
-    getCephfs: (id) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    },
-    getClients: (id) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    }
-  };
-
   configureTestBed({
-    imports: [RouterTestingModule, BsDropdownModule.forRoot(), SharedModule],
+    imports: [
+      RouterTestingModule,
+      BsDropdownModule.forRoot(),
+      SharedModule,
+      HttpClientTestingModule
+    ],
     declarations: [CephfsClientsComponent],
-    providers: [{ provide: CephfsService, useValue: fakeFilesystemService }]
+    providers: [CephfsService]
   });
 
   beforeEach(() => {
index 2d84178b5e6c821bbb726e95e4a3daff1cfec1a4..4f47f8f949da6b9575fc8237a4f54f00bf088d38 100644 (file)
@@ -1,10 +1,10 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { Component, Input } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
 import { ChartsModule } from 'ng2-charts/ng2-charts';
 import { BsDropdownModule, ProgressbarModule, TabsModule } from 'ngx-bootstrap';
-import { Observable } from 'rxjs';
 
 import { CephfsService } from '../../../shared/api/cephfs.service';
 import { SharedModule } from '../../../shared/shared.module';
@@ -25,19 +25,6 @@ describe('CephfsDetailComponent', () => {
   let component: CephfsDetailComponent;
   let fixture: ComponentFixture<CephfsDetailComponent>;
 
-  const fakeFilesystemService = {
-    getCephfs: (id) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    },
-    getMdsCounters: (id) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    }
-  };
-
   configureTestBed({
     imports: [
       SharedModule,
@@ -45,10 +32,11 @@ describe('CephfsDetailComponent', () => {
       RouterTestingModule,
       BsDropdownModule.forRoot(),
       ProgressbarModule.forRoot(),
-      TabsModule.forRoot()
+      TabsModule.forRoot(),
+      HttpClientTestingModule
     ],
     declarations: [CephfsDetailComponent, CephfsChartStubComponent, CephfsClientsStubComponent],
-    providers: [{ provide: CephfsService, useValue: fakeFilesystemService }]
+    providers: [CephfsService]
   });
 
   beforeEach(() => {
index 9bcfb1794fa175da1ca070d7aa848994d3608c28..ca3e11451dfd4bad373e8228255c7c0e44432756 100644 (file)
@@ -1,8 +1,7 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { Component, Input } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
-import { Observable } from 'rxjs';
-
 import { CephfsService } from '../../../shared/api/cephfs.service';
 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
 import { SharedModule } from '../../../shared/shared.module';
@@ -18,18 +17,10 @@ describe('CephfsListComponent', () => {
   let component: CephfsListComponent;
   let fixture: ComponentFixture<CephfsListComponent>;
 
-  const fakeService = {
-    get: (service_type: string, service_id: string) => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    }
-  };
-
   configureTestBed({
-    imports: [SharedModule],
+    imports: [SharedModule, HttpClientTestingModule],
     declarations: [CephfsListComponent, CephfsDetailStubComponent],
-    providers: [{ provide: CephfsService, useValue: fakeService }]
+    providers: [CephfsService]
   });
 
   beforeEach(() => {
index 9d97fd70b4b242f9aeaaac3c94e5d4bdc28d346d..152819cf6f2feaae2a756195d38718e323858c31 100644 (file)
@@ -1,8 +1,8 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { FormsModule } from '@angular/forms';
 
 import { TabsModule } from 'ngx-bootstrap/tabs/tabs.module';
-import { Observable } from 'rxjs';
 
 import { ConfigurationService } from '../../../shared/api/configuration.service';
 import { SharedModule } from '../../../shared/shared.module';
@@ -13,18 +13,10 @@ describe('ConfigurationComponent', () => {
   let component: ConfigurationComponent;
   let fixture: ComponentFixture<ConfigurationComponent>;
 
-  const fakeService = {
-    getConfigData: () => {
-      return Observable.create((observer) => {
-        return () => console.log('disposed');
-      });
-    }
-  };
-
   configureTestBed({
     declarations: [ConfigurationComponent],
-    providers: [{ provide: ConfigurationService, useValue: fakeService }],
-    imports: [SharedModule, FormsModule, TabsModule.forRoot()]
+    providers: [ConfigurationService],
+    imports: [SharedModule, FormsModule, TabsModule.forRoot(), HttpClientTestingModule]
   });
 
   beforeEach(() => {
index 3c1525c3ba99d2d36d824f7efc4c5e7b2de0dd7e..14522ca553089b89f2d2de53a30f91534383abdc 100644 (file)
@@ -1,8 +1,7 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { NO_ERRORS_SCHEMA } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
-import { of as observableOf } from 'rxjs';
-
 import { DashboardService } from '../../../shared/api/dashboard.service';
 import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
@@ -19,21 +18,9 @@ describe('HealthComponent', () => {
   let component: HealthComponent;
   let fixture: ComponentFixture<HealthComponent>;
 
-  const fakeService = {
-    getHealth: () => {
-      return observableOf({
-        health: {},
-        df: {
-          stats: {}
-        },
-        pools: []
-      });
-    }
-  };
-
   configureTestBed({
-    providers: [{ provide: DashboardService, useValue: fakeService }],
-    imports: [SharedModule],
+    providers: [DashboardService],
+    imports: [SharedModule, HttpClientTestingModule],
     declarations: [
       HealthComponent,
       MonSummaryPipe,
@@ -50,11 +37,6 @@ describe('HealthComponent', () => {
   beforeEach(() => {
     fixture = TestBed.createComponent(HealthComponent);
     component = fixture.componentInstance;
-
-    component.contentData = {
-      health: {}
-    };
-
     fixture.detectChanges();
   });
 
index df7e91596f2a63ef40ce169e90b3f3e7140fc0f3..c732e74286c27006b5fb0ac7e3ec821d1145513c 100644 (file)
@@ -1,38 +1,19 @@
-import { Component, Input } from '@angular/core';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { PerformanceCounterService } from '../../../shared/api/performance-counter.service';
+import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
+import { TablePerformanceCounterComponent } from '../table-performance-counter/table-performance-counter.component';
 import { PerformanceCounterComponent } from './performance-counter.component';
 
-@Component({ selector: 'cd-table-performance-counter', template: '' })
-class TablePerformanceCounterStubComponent {
-  @Input() serviceType: string;
-  @Input() serviceId: string;
-}
-
 describe('PerformanceCounterComponent', () => {
   let component: PerformanceCounterComponent;
   let fixture: ComponentFixture<PerformanceCounterComponent>;
 
-  const fakeService = {
-    get: (service_type: string, service_id: string) => {
-      return new Promise(function(resolve, reject) {
-        return [];
-      });
-    },
-    list: () => {
-      return new Promise(function(resolve, reject) {
-        return {};
-      });
-    }
-  };
-
   configureTestBed({
-    declarations: [PerformanceCounterComponent, TablePerformanceCounterStubComponent],
-    imports: [RouterTestingModule],
-    providers: [{ provide: PerformanceCounterService, useValue: fakeService }]
+    declarations: [PerformanceCounterComponent, TablePerformanceCounterComponent],
+    imports: [RouterTestingModule, SharedModule, HttpClientTestingModule]
   });
 
   beforeEach(() => {
index ebcea6fcefc40570c1aa23062f799352d0a204e3..516d4127d8b2464747a259377294f4d0ba59fc3c 100644 (file)
@@ -1,10 +1,7 @@
-import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
-import { PerformanceCounterService } from '../../../shared/api/performance-counter.service';
-import { TableComponent } from '../../../shared/datatable/table/table.component';
-import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
-import { FormatterService } from '../../../shared/services/formatter.service';
+import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
 import { TablePerformanceCounterComponent } from './table-performance-counter.component';
 
@@ -12,17 +9,9 @@ describe('TablePerformanceCounterComponent', () => {
   let component: TablePerformanceCounterComponent;
   let fixture: ComponentFixture<TablePerformanceCounterComponent>;
 
-  const fakeService = {};
-
   configureTestBed({
-    declarations: [TablePerformanceCounterComponent, TableComponent, DimlessPipe],
-    imports: [],
-    schemas: [NO_ERRORS_SCHEMA],
-    providers: [
-      { provide: PerformanceCounterService, useValue: fakeService },
-      DimlessPipe,
-      FormatterService
-    ]
+    declarations: [TablePerformanceCounterComponent],
+    imports: [SharedModule, HttpClientTestingModule]
   });
 
   beforeEach(() => {
index 2217ac132fac9cfc2b47db3f69bfd66f6e20cdfd..0e162944a6a855adb08443828b7cd321a15d7246 100644 (file)
@@ -1,43 +1,29 @@
-import { Component, Input } from '@angular/core';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { ModalModule } from 'ngx-bootstrap';
+import { ModalModule, TabsModule } from 'ngx-bootstrap';
 
 import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
-import { CdTableColumn } from '../../../shared/models/cd-table-column';
-import { CdTableSelection } from '../../../shared/models/cd-table-selection';
+import { SharedModule } from '../../../shared/shared.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
+import { RgwBucketDetailsComponent } from '../rgw-bucket-details/rgw-bucket-details.component';
 import { RgwBucketListComponent } from './rgw-bucket-list.component';
 
-@Component({ selector: 'cd-rgw-bucket-details', template: '' })
-class RgwBucketDetailsStubComponent {
-  @Input() selection: CdTableSelection;
-}
-
-@Component({ selector: 'cd-table', template: '' })
-class TableStubComponent {
-  @Input() data: any[];
-  @Input() columns: CdTableColumn[];
-  @Input() autoReload: any = 5000;
-}
-
 describe('RgwBucketListComponent', () => {
   let component: RgwBucketListComponent;
   let fixture: ComponentFixture<RgwBucketListComponent>;
 
-  const fakeRgwBucketService = {
-    list: () => {
-      return new Promise(function(resolve) {
-        resolve([]);
-      });
-    }
-  };
-
   configureTestBed({
-    declarations: [RgwBucketListComponent, RgwBucketDetailsStubComponent, TableStubComponent],
-    imports: [RouterTestingModule, ModalModule.forRoot()],
-    providers: [{ provide: RgwBucketService, useValue: fakeRgwBucketService }]
+    declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
+    imports: [
+      RouterTestingModule,
+      ModalModule.forRoot(),
+      SharedModule,
+      TabsModule.forRoot(),
+      HttpClientTestingModule
+    ],
+    providers: [RgwBucketService]
   });
 
   beforeEach(() => {
index 1aacea538b932268b8b3f3777baf581a63819701..acf40e2d846d79a80fb145809201c76638e69a5f 100644 (file)
@@ -1,3 +1,4 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { TabsModule } from 'ngx-bootstrap/tabs';
@@ -13,18 +14,15 @@ describe('RgwDaemonDetailsComponent', () => {
   let component: RgwDaemonDetailsComponent;
   let fixture: ComponentFixture<RgwDaemonDetailsComponent>;
 
-  const fakeRgwDaemonService = {
-    get: (id: string) => {
-      return new Promise(function(resolve) {
-        resolve([]);
-      });
-    }
-  };
-
   configureTestBed({
     declarations: [RgwDaemonDetailsComponent],
-    imports: [SharedModule, PerformanceCounterModule, TabsModule.forRoot()],
-    providers: [{ provide: RgwDaemonService, useValue: fakeRgwDaemonService }]
+    imports: [
+      SharedModule,
+      PerformanceCounterModule,
+      TabsModule.forRoot(),
+      HttpClientTestingModule
+    ],
+    providers: [RgwDaemonService]
   });
 
   beforeEach(() => {
index 8c6096d887fbda4ea5974aa42efb3fd469c3c382..0c84ee36915d65262d2fe90e917dca4f8317f965 100644 (file)
@@ -1,8 +1,9 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { NO_ERRORS_SCHEMA } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { BsModalService } from 'ngx-bootstrap';
+import { ModalModule } from 'ngx-bootstrap';
 
 import { RgwUserService } from '../../../shared/api/rgw-user.service';
 import { configureTestBed } from '../../../shared/unit-test-helper';
@@ -12,15 +13,10 @@ describe('RgwUserListComponent', () => {
   let component: RgwUserListComponent;
   let fixture: ComponentFixture<RgwUserListComponent>;
 
-  const fakeService = {};
-
   configureTestBed({
     declarations: [RgwUserListComponent],
-    imports: [RouterTestingModule],
-    providers: [
-      { provide: RgwUserService, useValue: fakeService },
-      { provide: BsModalService, useValue: fakeService }
-    ],
+    imports: [RouterTestingModule, HttpClientTestingModule, ModalModule.forRoot()],
+    providers: [RgwUserService],
     schemas: [NO_ERRORS_SCHEMA]
   });
 
index 7af7464a8ef08a2ab80707e62aca2475c03137c2..feb6c87e03637162d9f07c411a703c400952af61 100644 (file)
@@ -1,3 +1,4 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { FormsModule } from '@angular/forms';
 import { RouterTestingModule } from '@angular/router/testing';
@@ -11,12 +12,10 @@ describe('LoginComponent', () => {
   let component: LoginComponent;
   let fixture: ComponentFixture<LoginComponent>;
 
-  const fakeService = {};
-
   configureTestBed({
-    imports: [FormsModule, RouterTestingModule],
+    imports: [FormsModule, RouterTestingModule, HttpClientTestingModule],
     declarations: [LoginComponent],
-    providers: [{ provide: AuthService, useValue: fakeService }, AuthStorageService]
+    providers: [AuthService, AuthStorageService]
   });
 
   beforeEach(() => {
index be65f44ed1dc0dde23ce170a8cd5b0eb93c5ce86..96a851b6d35f1f595b0436a66be28043c86dc914 100644 (file)
@@ -1,20 +1,17 @@
+import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { AuthService } from '../../../shared/api/auth.service';
 import { configureTestBed } from '../../../shared/unit-test-helper';
+import { AuthModule } from '../auth.module';
 import { LogoutComponent } from './logout.component';
 
 describe('LogoutComponent', () => {
   let component: LogoutComponent;
   let fixture: ComponentFixture<LogoutComponent>;
 
-  const fakeService = {};
-
   configureTestBed({
-    imports: [RouterTestingModule],
-    declarations: [LogoutComponent],
-    providers: [{ provide: AuthService, useValue: fakeService }]
+    imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
   });
 
   beforeEach(() => {
index 64616df677268432f56611f0a2f5fa5698ec2352..71844c70095ec0dd1acb5f6aa737d016a130b9d4 100644 (file)
@@ -1,40 +1,15 @@
-import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { RouterTestingModule } from '@angular/router/testing';
 
-import { CollapseModule, PopoverModule } from 'ngx-bootstrap';
-
-import { NotificationService } from '../../../shared/services/notification.service';
-import { SharedModule } from '../../../shared/shared.module';
+import { AppModule } from '../../../app.module';
 import { configureTestBed } from '../../../shared/unit-test-helper';
-import { LogoutComponent } from '../../auth/logout/logout.component';
-import { DashboardHelpComponent } from '../dashboard-help/dashboard-help.component';
-import { NotificationsComponent } from '../notifications/notifications.component';
-import { TaskManagerComponent } from '../task-manager/task-manager.component';
 import { NavigationComponent } from './navigation.component';
 
 describe('NavigationComponent', () => {
   let component: NavigationComponent;
   let fixture: ComponentFixture<NavigationComponent>;
 
-  const fakeService = new NotificationService(null, null);
-
   configureTestBed({
-    imports: [
-      SharedModule,
-      RouterTestingModule,
-      HttpClientTestingModule,
-      CollapseModule.forRoot(),
-      PopoverModule.forRoot()
-    ],
-    declarations: [
-      NavigationComponent,
-      NotificationsComponent,
-      LogoutComponent,
-      TaskManagerComponent,
-      DashboardHelpComponent
-    ],
-    providers: [{ provide: NotificationService, useValue: fakeService }]
+    imports: [AppModule]
   });
 
   beforeEach(() => {
index 6b7f67c670307382f42701301dfe6020c26bf845..b1e4419d5bcce4e8d1eaf382c2398c22c25dd78a 100644 (file)
@@ -1,5 +1,6 @@
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 
+import { ToastModule } from 'ng2-toastr';
 import { PopoverModule } from 'ngx-bootstrap/popover';
 
 import { NotificationService } from '../../../shared/services/notification.service';
@@ -11,12 +12,10 @@ describe('NotificationsComponent', () => {
   let component: NotificationsComponent;
   let fixture: ComponentFixture<NotificationsComponent>;
 
-  const fakeService = new NotificationService(null, null);
-
   configureTestBed({
-    imports: [PopoverModule.forRoot(), SharedModule],
+    imports: [PopoverModule.forRoot(), SharedModule, ToastModule.forRoot()],
     declarations: [NotificationsComponent],
-    providers: [{ provide: NotificationService, useValue: fakeService }]
+    providers: [NotificationService]
   });
 
   beforeEach(() => {
index 6c731455e945cf08c898c8a419842443df8a12fc..22cb4495ff6c0e778b226de9228ddd6636c528b0 100644 (file)
@@ -9,24 +9,22 @@ import { AuthStorageService } from './auth-storage.service';
 
 describe('AuthGuardService', () => {
   let service: AuthGuardService;
+  let authStorageService: AuthStorageService;
 
   @Component({ selector: 'cd-login', template: '' })
   class LoginComponent {}
 
   const routes: Routes = [{ path: 'login', component: LoginComponent }];
 
-  const fakeService = {
-    isLoggedIn: () => true
-  };
-
   configureTestBed({
     imports: [RouterTestingModule.withRoutes(routes)],
-    providers: [AuthGuardService, { provide: AuthStorageService, useValue: fakeService }],
+    providers: [AuthGuardService, AuthStorageService],
     declarations: [LoginComponent]
   });
 
   beforeEach(() => {
     service = TestBed.get(AuthGuardService);
+    authStorageService = TestBed.get(AuthStorageService);
   });
 
   it('should be created', () => {
@@ -34,6 +32,7 @@ describe('AuthGuardService', () => {
   });
 
   it('should allow the user if loggedIn', () => {
+    spyOn(authStorageService, 'isLoggedIn').and.returnValue(true);
     expect(service.canActivate(null, null)).toBe(true);
   });
 
@@ -41,9 +40,6 @@ describe('AuthGuardService', () => {
     'should prevent user if not loggedIn and redirect to login page',
     fakeAsync(() => {
       const router = TestBed.get(Router);
-      const authStorageService = TestBed.get(AuthStorageService);
-      spyOn(authStorageService, 'isLoggedIn').and.returnValue(false);
-
       expect(service.canActivate(null, null)).toBe(false);
       tick();
       expect(router.url).toBe('/login');
index 1d71b328834f270ef8b576f6f0ec7628a9e3d6fa..ddc8e32946a23351808238945cadaf9d128e4cd2 100644 (file)
@@ -11,6 +11,9 @@ import { ModuleStatusGuardService } from './module-status-guard.service';
 
 describe('ModuleStatusGuardService', () => {
   let service: ModuleStatusGuardService;
+  let httpClient: HttpClient;
+  let router: Router;
+  let route: ActivatedRouteSnapshot;
 
   @Component({ selector: 'cd-foo', template: '' })
   class FooComponent {}
@@ -21,6 +24,18 @@ describe('ModuleStatusGuardService', () => {
 
   const routes: Routes = [{ path: '**', component: FooComponent }];
 
+  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;
+    });
+
+    tick();
+    expect(result).toBe(activateResult);
+    expect(router.url).toBe(urlResult);
+  };
+
   configureTestBed({
     imports: [RouterTestingModule.withRoutes(routes)],
     providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
@@ -29,6 +44,15 @@ describe('ModuleStatusGuardService', () => {
 
   beforeEach(() => {
     service = TestBed.get(ModuleStatusGuardService);
+    httpClient = TestBed.get(HttpClient);
+    router = TestBed.get(Router);
+    route = new ActivatedRouteSnapshot();
+    route.data = {
+      moduleStatusGuardConfig: {
+        apiPath: 'bar',
+        redirectTo: '/foo'
+      }
+    };
   });
 
   it('should be created', () => {
@@ -38,70 +62,22 @@ describe('ModuleStatusGuardService', () => {
   it(
     'should test canActivate with status available',
     fakeAsync(() => {
-      let result = false;
-      const route = new ActivatedRouteSnapshot();
-      route.data = {
-        moduleStatusGuardConfig: {
-          apiPath: 'bar',
-          redirectTo: 'foo'
-        }
-      };
-      const httpClient = TestBed.get(HttpClient);
-      spyOn(httpClient, 'get').and.returnValue(observableOf({ available: true, message: 'foo' }));
-      service.canActivate(route, null).subscribe((resp) => {
-        result = resp;
-      });
-
-      tick();
-      expect(result).toBe(true);
+      route.data.moduleStatusGuardConfig.redirectTo = 'foo';
+      testCanActivate({ available: true, message: 'foo' }, true, '/');
     })
   );
 
   it(
     'should test canActivateChild with status unavailable',
     fakeAsync(() => {
-      let result = true;
-      const route = new ActivatedRouteSnapshot();
-      route.data = {
-        moduleStatusGuardConfig: {
-          apiPath: 'bar',
-          redirectTo: '/foo'
-        }
-      };
-      const httpClient = TestBed.get(HttpClient);
-      const router = TestBed.get(Router);
-      spyOn(httpClient, 'get').and.returnValue(observableOf({ available: false, message: null }));
-      service.canActivateChild(route, null).subscribe((resp) => {
-        result = resp;
-      });
-
-      tick();
-      expect(result).toBe(false);
-      expect(router.url).toBe('/foo/');
+      testCanActivate({ available: false, message: null }, false, '/foo/');
     })
   );
 
   it(
     'should test canActivateChild with status unavailable',
     fakeAsync(() => {
-      let result = true;
-      const route = new ActivatedRouteSnapshot();
-      route.data = {
-        moduleStatusGuardConfig: {
-          apiPath: 'bar',
-          redirectTo: '/foo'
-        }
-      };
-      const httpClient = TestBed.get(HttpClient);
-      const router = TestBed.get(Router);
-      spyOn(httpClient, 'get').and.returnValue(observableOf(null));
-      service.canActivateChild(route, null).subscribe((resp) => {
-        result = resp;
-      });
-
-      tick();
-      expect(result).toBe(false);
-      expect(router.url).toBe('/foo');
+      testCanActivate(null, false, '/foo');
     })
   );
 });
index 3858a86bc728af1d3c9c9a39f1eca4934a5ce5b5..5eb346ac91e393f27378d766b8df4637a1125184 100644 (file)
@@ -11,22 +11,17 @@ import { TaskManagerMessageService } from './task-manager-message.service';
 
 describe('NotificationService', () => {
   let notificationService: NotificationService;
-  const fakeService = {
-    // ToastsManager
+  const toastFakeService = {
     error: () => true,
     info: () => true,
-    success: () => true,
-    // TaskManagerMessageService
-    getDescription: () => true,
-    getErrorMessage: () => true,
-    getSuccessMessage: () => true
+    success: () => true
   };
 
   configureTestBed({
     providers: [
       NotificationService,
-      { provide: TaskManagerMessageService, useValue: fakeService },
-      { provide: ToastsManager, useValue: fakeService }
+      TaskManagerMessageService,
+      { provide: ToastsManager, useValue: toastFakeService }
     ]
   });
 
@@ -124,7 +119,11 @@ describe('NotificationService', () => {
     'should show a error task notification',
     fakeAsync(() => {
       const task = _.assign(new FinishedTask(), {
-        success: false
+        success: false,
+        metadata: 'failed',
+        exception: {
+          code: 404
+        }
       });
       notificationService.notifyTask(task);
       tick(100);
index 5181de0aa2f3ec8a7709384a3f5b082703b49baf..a7b321a468127ae7a93e53d86483401bab895bfa 100644 (file)
@@ -9,6 +9,7 @@ import { TaskManagerService } from './task-manager.service';
 
 describe('TaskManagerService', () => {
   let taskManagerService: TaskManagerService;
+  let called: boolean;
 
   const summaryDataSource = new Subject();
   const fakeService = {
@@ -28,10 +29,12 @@ describe('TaskManagerService', () => {
 
   configureTestBed({
     providers: [TaskManagerService, { provide: SummaryService, useValue: fakeService }]
-  });
+  }, true);
 
   beforeEach(() => {
     taskManagerService = TestBed.get(TaskManagerService);
+    called = false;
+    taskManagerService.subscribe('foo', {}, () => (called = true));
   });
 
   it('should be created', () => {
@@ -41,13 +44,9 @@ describe('TaskManagerService', () => {
   it(
     'should subscribe and be notified when task is finished',
     fakeAsync(() => {
-      let called = false;
-      taskManagerService.subscribe('foo', {}, () => (called = true));
       expect(taskManagerService.subscriptions.length).toBe(1);
-
       summaryDataSource.next(summary);
       tick();
-
       expect(called).toEqual(true);
       expect(taskManagerService.subscriptions).toEqual([]);
     })
@@ -56,8 +55,6 @@ describe('TaskManagerService', () => {
   it(
     'should subscribe and process executing taks',
     fakeAsync(() => {
-      let called = false;
-      taskManagerService.subscribe('foo', {}, () => (called = true));
       const original_subscriptions = _.cloneDeep(taskManagerService.subscriptions);
       _.assign(summary, {
         executing_tasks: [{ name: 'foo', metadata: {} }],