1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
5 import { ToastModule } from 'ng2-toastr';
6 import { BsModalRef, ModalModule } from 'ngx-bootstrap';
7 import { throwError as observableThrowError } from 'rxjs';
9 import { configureTestBed } from '../../../../testing/unit-test-helper';
10 import { ApiModule } from '../../../shared/api/api.module';
11 import { RbdService } from '../../../shared/api/rbd.service';
12 import { ComponentsModule } from '../../../shared/components/components.module';
13 import { DataTableModule } from '../../../shared/datatable/datatable.module';
14 import { Permissions } from '../../../shared/models/permissions';
15 import { PipesModule } from '../../../shared/pipes/pipes.module';
16 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
17 import { NotificationService } from '../../../shared/services/notification.service';
18 import { ServicesModule } from '../../../shared/services/services.module';
19 import { RbdSnapshotListComponent } from './rbd-snapshot-list.component';
21 describe('RbdSnapshotListComponent', () => {
22 let component: RbdSnapshotListComponent;
23 let fixture: ComponentFixture<RbdSnapshotListComponent>;
25 const fakeAuthStorageService = {
29 getPermissions: () => {
30 return new Permissions({ 'rbd-image': ['read', 'update', 'create', 'delete'] });
35 declarations: [RbdSnapshotListComponent],
39 ModalModule.forRoot(),
40 ToastModule.forRoot(),
43 HttpClientTestingModule,
47 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }]
51 fixture = TestBed.createComponent(RbdSnapshotListComponent);
52 component = fixture.componentInstance;
53 fixture.detectChanges();
56 it('should create', () => {
57 expect(component).toBeTruthy();
60 describe('api delete request', () => {
62 let rbdService: RbdService;
63 let notificationService: NotificationService;
64 let authStorageService: AuthStorageService;
68 rbdService = new RbdService(null);
69 notificationService = new NotificationService(null, null);
70 authStorageService = new AuthStorageService();
71 authStorageService.set('user', { 'rbd-image': ['create', 'read', 'update', 'delete'] });
72 component = new RbdSnapshotListComponent(
81 spyOn(rbdService, 'deleteSnapshot').and.returnValue(observableThrowError({ status: 500 }));
82 spyOn(notificationService, 'notifyTask').and.stub();
83 component.modalRef = new BsModalRef();
84 component.modalRef.content = {
85 stopLoadingSpinner: () => (called = true)
89 it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
90 expect(called).toBe(false);
91 component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
93 expect(called).toBe(true);