From 0e3e2671f3277fb88b131aac929ef7e20dc3b413 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Tue, 5 Jun 2018 12:16:26 +0200 Subject: [PATCH] mgr/dashboard: Remove unnecessary fake services MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Removed unnecessary fake services. Signed-off-by: Stephan Müller --- .../frontend/src/app/app.component.spec.ts | 8 +- .../mirroring/mirroring.component.spec.ts | 13 +-- .../cephfs-clients.component.spec.ts | 24 ++---- .../cephfs-detail.component.spec.ts | 20 +---- .../cephfs-list/cephfs-list.component.spec.ts | 15 +--- .../configuration.component.spec.ts | 14 +--- .../dashboard/health/health.component.spec.ts | 24 +----- .../performance-counter.component.spec.ts | 29 ++----- ...able-performance-counter.component.spec.ts | 19 +---- .../rgw-bucket-list.component.spec.ts | 40 +++------- .../rgw-daemon-details.component.spec.ts | 18 ++--- .../rgw-user-list.component.spec.ts | 12 +-- .../core/auth/login/login.component.spec.ts | 7 +- .../core/auth/logout/logout.component.spec.ts | 9 +-- .../navigation/navigation.component.spec.ts | 29 +------ .../notifications.component.spec.ts | 7 +- .../services/auth-guard.service.spec.ts | 12 +-- .../module-status-guard.service.spec.ts | 80 +++++++------------ .../services/notification.service.spec.ts | 19 +++-- .../services/task-manager.service.spec.ts | 11 +-- 20 files changed, 113 insertions(+), 297 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/app.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/app.component.spec.ts index 442a046285296..9182e31bd7078 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/app.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/app.component.spec.ts @@ -12,17 +12,11 @@ describe('AppComponent', () => { let component: AppComponent; let fixture: ComponentFixture; - const fakeService = { - isLoggedIn: () => { - return true; - } - }; - configureTestBed({ imports: [RouterTestingModule, ToastModule.forRoot()], declarations: [AppComponent], schemas: [NO_ERRORS_SCHEMA], - providers: [{ provide: AuthStorageService, useValue: fakeService }] + providers: [AuthStorageService] }); beforeEach(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/mirroring.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/mirroring.component.spec.ts index 22070035f679a..0f4878e2b00fa 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/mirroring.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/mirroring.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.spec.ts index 5928c198412bb..31e65be2ae461 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-detail/cephfs-detail.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-detail/cephfs-detail.component.spec.ts index 2d84178b5e6c8..4f47f8f949da6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-detail/cephfs-detail.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-detail/cephfs-detail.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts index 9bcfb1794fa17..ca3e11451dfd4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.spec.ts index 9d97fd70b4b24..152819cf6f2fe 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts index 3c1525c3ba99d..14522ca553089 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts @@ -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; - 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(); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts index df7e91596f2a6..c732e74286c27 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/performance-counter/performance-counter.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts index ebcea6fcefc40..516d4127d8b24 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts index 2217ac132fac9..0e162944a6a85 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-details/rgw-daemon-details.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-details/rgw-daemon-details.component.spec.ts index 1aacea538b932..acf40e2d846d7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-details/rgw-daemon-details.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-details/rgw-daemon-details.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts index 8c6096d887fbd..0c84ee36915d6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts @@ -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; - 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] }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts index 7af7464a8ef08..feb6c87e03637 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts @@ -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; - const fakeService = {}; - configureTestBed({ - imports: [FormsModule, RouterTestingModule], + imports: [FormsModule, RouterTestingModule, HttpClientTestingModule], declarations: [LoginComponent], - providers: [{ provide: AuthService, useValue: fakeService }, AuthStorageService] + providers: [AuthService, AuthStorageService] }); beforeEach(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/logout/logout.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/logout/logout.component.spec.ts index be65f44ed1dc0..96a851b6d35f1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/logout/logout.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/logout/logout.component.spec.ts @@ -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; - const fakeService = {}; - configureTestBed({ - imports: [RouterTestingModule], - declarations: [LogoutComponent], - providers: [{ provide: AuthService, useValue: fakeService }] + imports: [RouterTestingModule, HttpClientTestingModule, AuthModule] }); beforeEach(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts index 64616df677268..71844c70095ec 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notifications/notifications.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notifications/notifications.component.spec.ts index 6b7f67c670307..b1e4419d5bcce 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notifications/notifications.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notifications/notifications.component.spec.ts @@ -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; - 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(() => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.spec.ts index 6c731455e945c..22cb4495ff6c0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.spec.ts @@ -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'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts index 1d71b328834f2..ddc8e32946a23 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts @@ -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'); }) ); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts index 3858a86bc728a..5eb346ac91e39 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts @@ -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); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts index 5181de0aa2f3e..a7b321a468127 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts @@ -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: {} }], -- 2.39.5