1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
4 import { ToastModule } from 'ng2-toastr';
5 import { BsModalRef, ModalModule } from 'ngx-bootstrap';
6 import { Observable } from 'rxjs/Observable';
8 import { ApiModule } from '../../../shared/api/api.module';
9 import { RbdService } from '../../../shared/api/rbd.service';
10 import { ComponentsModule } from '../../../shared/components/components.module';
11 import { DataTableModule } from '../../../shared/datatable/datatable.module';
12 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
13 import { NotificationService } from '../../../shared/services/notification.service';
14 import { ServicesModule } from '../../../shared/services/services.module';
15 import { RbdSnapshotListComponent } from './rbd-snapshot-list.component';
17 describe('RbdSnapshotListComponent', () => {
18 let component: RbdSnapshotListComponent;
19 let fixture: ComponentFixture<RbdSnapshotListComponent>;
21 beforeEach(async(() => {
22 TestBed.configureTestingModule({
23 declarations: [ RbdSnapshotListComponent ],
27 ModalModule.forRoot(),
28 ToastModule.forRoot(),
31 HttpClientTestingModule
33 providers: [ AuthStorageService ]
39 fixture = TestBed.createComponent(RbdSnapshotListComponent);
40 component = fixture.componentInstance;
41 fixture.detectChanges();
44 it('should create', () => {
45 expect(component).toBeTruthy();
48 describe('api delete request', () => {
50 let rbdService: RbdService;
51 let notificationService: NotificationService;
55 rbdService = new RbdService(null);
56 notificationService = new NotificationService(null, null);
57 component = new RbdSnapshotListComponent(null, null, null, rbdService, null, null,
59 spyOn(rbdService, 'deleteSnapshot').and.returnValue(Observable.throw({status: 500}));
60 spyOn(notificationService, 'notifyTask').and.stub();
61 component.modalRef = new BsModalRef();
62 component.modalRef.content = {
63 stopLoadingSpinner: () => called = true
67 it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
68 expect(called).toBe(false);
69 component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
71 expect(called).toBe(true);