]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
c17eace27f82676bcd247ebbae2e37f3b3c2698d
[ceph-ci.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3
4 import { ToastModule } from 'ng2-toastr';
5 import { BsModalRef, ModalModule } from 'ngx-bootstrap';
6 import { Observable } from 'rxjs/Observable';
7
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';
16
17 describe('RbdSnapshotListComponent', () => {
18   let component: RbdSnapshotListComponent;
19   let fixture: ComponentFixture<RbdSnapshotListComponent>;
20
21   beforeEach(async(() => {
22     TestBed.configureTestingModule({
23       declarations: [ RbdSnapshotListComponent ],
24       imports: [
25         DataTableModule,
26         ComponentsModule,
27         ModalModule.forRoot(),
28         ToastModule.forRoot(),
29         ServicesModule,
30         ApiModule,
31         HttpClientTestingModule
32       ],
33       providers: [ AuthStorageService ]
34     })
35     .compileComponents();
36   }));
37
38   beforeEach(() => {
39     fixture = TestBed.createComponent(RbdSnapshotListComponent);
40     component = fixture.componentInstance;
41     fixture.detectChanges();
42   });
43
44   it('should create', () => {
45     expect(component).toBeTruthy();
46   });
47
48   describe('api delete request', () => {
49     let called;
50     let rbdService: RbdService;
51     let notificationService: NotificationService;
52
53     beforeEach(() => {
54       called = false;
55       rbdService = new RbdService(null);
56       notificationService = new NotificationService(null, null);
57       component = new RbdSnapshotListComponent(null, null, null, rbdService, null, null,
58                                                notificationService);
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
64       };
65     });
66
67     it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
68       expect(called).toBe(false);
69       component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
70       tick(500);
71       expect(called).toBe(true);
72     }));
73   });
74 });