]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
03fe0a050f3dff6d5be0f32625caa671b4eff26b
[ceph.git] /
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';
4
5 import { ToastModule } from 'ng2-toastr';
6 import { BsModalRef, ModalModule } from 'ngx-bootstrap';
7 import { throwError as observableThrowError } from 'rxjs';
8
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';
19
20 describe('RbdSnapshotListComponent', () => {
21   let component: RbdSnapshotListComponent;
22   let fixture: ComponentFixture<RbdSnapshotListComponent>;
23
24   const fakeAuthStorageService = {
25     isLoggedIn: () => {
26       return true;
27     },
28     getPermissions: () => {
29       return new Permissions({ 'rbd-image': ['read', 'update', 'create', 'delete'] });
30     }
31   };
32
33   configureTestBed({
34     declarations: [RbdSnapshotListComponent],
35     imports: [
36       DataTableModule,
37       ComponentsModule,
38       ModalModule.forRoot(),
39       ToastModule.forRoot(),
40       ServicesModule,
41       ApiModule,
42       HttpClientTestingModule,
43       RouterTestingModule
44     ],
45     providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }]
46   });
47
48   beforeEach(() => {
49     fixture = TestBed.createComponent(RbdSnapshotListComponent);
50     component = fixture.componentInstance;
51     fixture.detectChanges();
52   });
53
54   it('should create', () => {
55     expect(component).toBeTruthy();
56   });
57
58   describe('api delete request', () => {
59     let called;
60     let rbdService: RbdService;
61     let notificationService: NotificationService;
62     let authStorageService: AuthStorageService;
63
64     beforeEach(() => {
65       called = false;
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(
71         authStorageService,
72         null,
73         null,
74         null,
75         rbdService,
76         null,
77         notificationService
78       );
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)
84       };
85     });
86
87     it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
88       expect(called).toBe(false);
89       component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
90       tick(500);
91       expect(called).toBe(true);
92     }));
93   });
94 });