2 HttpClientTestingModule,
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';
10 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
11 import { ToastrModule } from 'ngx-toastr';
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';
18 describe('RbdTrashRestoreModalComponent', () => {
19 let component: RbdTrashRestoreModalComponent;
20 let fixture: ComponentFixture<RbdTrashRestoreModalComponent>;
23 declarations: [RbdTrashRestoreModalComponent],
26 HttpClientTestingModule,
27 ToastrModule.forRoot(),
31 providers: [NgbActiveModal, i18nProviders]
35 fixture = TestBed.createComponent(RbdTrashRestoreModalComponent);
36 component = fixture.componentInstance;
37 fixture.detectChanges();
40 it('should create', () => {
41 expect(component).toBeTruthy();
44 describe('should call restore', () => {
45 let httpTesting: HttpTestingController;
46 let notificationService: NotificationService;
47 let activeModal: NgbActiveModal;
51 httpTesting = TestBed.inject(HttpTestingController);
52 notificationService = TestBed.inject(NotificationService);
53 activeModal = TestBed.inject(NgbActiveModal);
55 component.poolName = 'foo';
56 component.imageName = 'bar';
57 component.imageId = '113cb6963793';
60 spyOn(activeModal, 'close').and.stub();
61 spyOn(component.restoreForm, 'setErrors').and.stub();
62 spyOn(notificationService, 'show').and.stub();
66 req = httpTesting.expectOne('api/block/image/trash/foo%2F113cb6963793/restore');
69 it('with success', () => {
71 expect(component.restoreForm.setErrors).toHaveBeenCalledTimes(0);
72 expect(component.activeModal.close).toHaveBeenCalledTimes(1);
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);