Removed unnecessary fake services.
Signed-off-by: Stephan Müller <smueller@suse.com>
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(() => {
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';
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: [
TabsModule.forRoot(),
ProgressbarModule.forRoot(),
HttpClientTestingModule
- ],
- providers: [{ provide: RbdMirroringService, useValue: fakeService }]
+ ]
});
beforeEach(() => {
+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';
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(() => {
+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';
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,
RouterTestingModule,
BsDropdownModule.forRoot(),
ProgressbarModule.forRoot(),
- TabsModule.forRoot()
+ TabsModule.forRoot(),
+ HttpClientTestingModule
],
declarations: [CephfsDetailComponent, CephfsChartStubComponent, CephfsClientsStubComponent],
- providers: [{ provide: CephfsService, useValue: fakeFilesystemService }]
+ providers: [CephfsService]
});
beforeEach(() => {
+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';
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(() => {
+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';
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(() => {
+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';
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,
beforeEach(() => {
fixture = TestBed.createComponent(HealthComponent);
component = fixture.componentInstance;
-
- component.contentData = {
- health: {}
- };
-
fixture.detectChanges();
});
-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(() => {
-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';
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(() => {
-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(() => {
+import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TabsModule } from 'ngx-bootstrap/tabs';
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(() => {
+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';
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]
});
+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';
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(() => {
+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(() => {
-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(() => {
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';
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(() => {
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', () => {
});
it('should allow the user if loggedIn', () => {
+ spyOn(authStorageService, 'isLoggedIn').and.returnValue(true);
expect(service.canActivate(null, null)).toBe(true);
});
'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');
describe('ModuleStatusGuardService', () => {
let service: ModuleStatusGuardService;
+ let httpClient: HttpClient;
+ let router: Router;
+ let route: ActivatedRouteSnapshot;
@Component({ selector: 'cd-foo', template: '' })
class FooComponent {}
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 }],
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', () => {
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');
})
);
});
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 }
]
});
'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);
describe('TaskManagerService', () => {
let taskManagerService: TaskManagerService;
+ let called: boolean;
const summaryDataSource = new Subject();
const fakeService = {
configureTestBed({
providers: [TaskManagerService, { provide: SummaryService, useValue: fakeService }]
- });
+ }, true);
beforeEach(() => {
taskManagerService = TestBed.get(TaskManagerService);
+ called = false;
+ taskManagerService.subscribe('foo', {}, () => (called = true));
});
it('should be created', () => {
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([]);
})
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: {} }],