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';
6 import { ToastModule } from 'ng2-toastr';
7 import { BsModalRef } from 'ngx-bootstrap/modal';
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';
14 describe('RbdTrashRestoreModalComponent', () => {
15 let component: RbdTrashRestoreModalComponent;
16 let fixture: ComponentFixture<RbdTrashRestoreModalComponent>;
19 declarations: [RbdTrashRestoreModalComponent],
22 HttpClientTestingModule,
23 ToastModule.forRoot(),
27 providers: [BsModalRef, i18nProviders]
31 fixture = TestBed.createComponent(RbdTrashRestoreModalComponent);
32 component = fixture.componentInstance;
33 fixture.detectChanges();
36 it('should create', () => {
37 expect(component).toBeTruthy();
40 describe('should call restore', () => {
41 let httpTesting: HttpTestingController;
42 let notificationService: NotificationService;
43 let modalRef: BsModalRef;
47 httpTesting = TestBed.get(HttpTestingController);
48 notificationService = TestBed.get(NotificationService);
49 modalRef = TestBed.get(BsModalRef);
51 component.poolName = 'foo';
52 component.imageId = 'bar';
54 spyOn(modalRef, 'hide').and.stub();
55 spyOn(component.restoreForm, 'setErrors').and.stub();
56 spyOn(notificationService, 'show').and.stub();
60 req = httpTesting.expectOne('api/block/image/trash/foo/bar/restore');
63 it('with success', () => {
65 expect(component.restoreForm.setErrors).toHaveBeenCalledTimes(0);
66 expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
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);