]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
3689b2a18cbb86004af6135eb0e5616920701d26
[ceph.git] /
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { ToastModule } from 'ng2-toastr';
7 import { BsModalRef } from 'ngx-bootstrap/modal';
8
9 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
10 import { NotificationService } from '../../../shared/services/notification.service';
11 import { SharedModule } from '../../../shared/shared.module';
12 import { RbdTrashRestoreModalComponent } from './rbd-trash-restore-modal.component';
13
14 describe('RbdTrashRestoreModalComponent', () => {
15   let component: RbdTrashRestoreModalComponent;
16   let fixture: ComponentFixture<RbdTrashRestoreModalComponent>;
17
18   configureTestBed({
19     declarations: [RbdTrashRestoreModalComponent],
20     imports: [
21       ReactiveFormsModule,
22       HttpClientTestingModule,
23       ToastModule.forRoot(),
24       SharedModule,
25       RouterTestingModule
26     ],
27     providers: [BsModalRef, i18nProviders]
28   });
29
30   beforeEach(() => {
31     fixture = TestBed.createComponent(RbdTrashRestoreModalComponent);
32     component = fixture.componentInstance;
33     fixture.detectChanges();
34   });
35
36   it('should create', () => {
37     expect(component).toBeTruthy();
38   });
39
40   describe('should call restore', () => {
41     let httpTesting: HttpTestingController;
42     let notificationService: NotificationService;
43     let modalRef: BsModalRef;
44     let req;
45
46     beforeEach(() => {
47       httpTesting = TestBed.get(HttpTestingController);
48       notificationService = TestBed.get(NotificationService);
49       modalRef = TestBed.get(BsModalRef);
50
51       component.poolName = 'foo';
52       component.imageId = 'bar';
53
54       spyOn(modalRef, 'hide').and.stub();
55       spyOn(component.restoreForm, 'setErrors').and.stub();
56       spyOn(notificationService, 'show').and.stub();
57
58       component.restore();
59
60       req = httpTesting.expectOne('api/block/image/trash/foo/bar/restore');
61     });
62
63     it('with success', () => {
64       req.flush(null);
65       expect(component.restoreForm.setErrors).toHaveBeenCalledTimes(0);
66       expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
67     });
68
69     it('with failure', () => {
70       req.flush(null, { status: 500, statusText: 'failure' });
71       expect(component.restoreForm.setErrors).toHaveBeenCalledTimes(1);
72       expect(component.modalRef.hide).toHaveBeenCalledTimes(0);
73     });
74   });
75 });