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