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 { ApiModule } from '../../../shared/api/api.module';
10 import { RbdService } from '../../../shared/api/rbd.service';
11 import { ComponentsModule } from '../../../shared/components/components.module';
12 import { DataTableModule } from '../../../shared/datatable/datatable.module';
13 import { Permissions } from '../../../shared/models/permissions';
14 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
15 import { NotificationService } from '../../../shared/services/notification.service';
16 import { ServicesModule } from '../../../shared/services/services.module';
17 import { configureTestBed } from '../../../shared/unit-test-helper';
18 import { RbdSnapshotListComponent } from './rbd-snapshot-list.component';
20 describe('RbdSnapshotListComponent', () => {
21 let component: RbdSnapshotListComponent;
22 let fixture: ComponentFixture<RbdSnapshotListComponent>;
24 const fakeAuthStorageService = {
28 getPermissions: () => {
29 return new Permissions({ 'rbd-image': ['read', 'update', 'create', 'delete'] });
34 declarations: [RbdSnapshotListComponent],
38 ModalModule.forRoot(),
39 ToastModule.forRoot(),
42 HttpClientTestingModule,
45 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }]
49 fixture = TestBed.createComponent(RbdSnapshotListComponent);
50 component = fixture.componentInstance;
51 fixture.detectChanges();
54 it('should create', () => {
55 expect(component).toBeTruthy();
58 describe('api delete request', () => {
60 let rbdService: RbdService;
61 let notificationService: NotificationService;
62 let authStorageService: AuthStorageService;
66 rbdService = new RbdService(null);
67 notificationService = new NotificationService(null, null);
68 authStorageService = new AuthStorageService();
69 authStorageService.set('user', { 'rbd-image': ['create', 'read', 'update', 'delete'] });
70 component = new RbdSnapshotListComponent(
79 spyOn(rbdService, 'deleteSnapshot').and.returnValue(observableThrowError({ status: 500 }));
80 spyOn(notificationService, 'notifyTask').and.stub();
81 component.modalRef = new BsModalRef();
82 component.modalRef.content = {
83 stopLoadingSpinner: () => (called = true)
87 it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
88 expect(called).toBe(false);
89 component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
91 expect(called).toBe(true);