import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { ToastModule } from 'ng2-toastr';
import {
AlertModule,
- BsDropdownModule,
+ BsDropdownModule, BsModalRef,
ModalModule,
TabsModule,
TooltipModule
} from 'ngx-bootstrap';
+import { Observable } from 'rxjs/Observable';
+import { RbdService } from '../../../shared/api/rbd.service';
import { ComponentsModule } from '../../../shared/components/components.module';
+import { NotificationService } from '../../../shared/services/notification.service';
import { SharedModule } from '../../../shared/shared.module';
import { RbdDetailsComponent } from '../rbd-details/rbd-details.component';
import { RbdSnapshotListComponent } from '../rbd-snapshot-list/rbd-snapshot-list.component';
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ describe('api delete request', () => {
+ let called;
+ let rbdService: RbdService;
+ let notificationService: NotificationService;
+
+ beforeEach(() => {
+ called = false;
+ rbdService = new RbdService(null);
+ notificationService = new NotificationService(null, null);
+ component = new RbdListComponent(rbdService, null, null, null, null, notificationService,
+ null, null);
+ spyOn(rbdService, 'delete').and.returnValue(Observable.throw({status: 500}));
+ spyOn(notificationService, 'notifyTask').and.stub();
+ component.modalRef = new BsModalRef();
+ component.modalRef.content = {
+ stopLoadingSpinner: () => called = true
+ };
+ });
+
+ it('should make sure that if the deletion fails stopLoadingSpinner is called',
+ <any>fakeAsync(() => {
+ expect(called).toBe(false);
+ component.deleteRbd('sth', 'test');
+ tick(500);
+ expect(called).toBe(true);
+ }));
+ });
});
import { RbdService } from '../../../shared/api/rbd.service';
import {
- DeleteConfirmationComponent
-} from '../../../shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
+ DeletionModalComponent
+} from '../../../shared/components/deletion-modal/deletion-modal.component';
import { CellTemplate } from '../../../shared/enum/cell-template.enum';
import { NotificationType } from '../../../shared/enum/notification-type.enum';
import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
this.modalRef.hide();
this.loadImages(null);
}).catch((resp) => {
+ this.modalRef.content.stopLoadingSpinner();
finishedTask.success = false;
finishedTask.exception = resp.error;
this.notificationService.notifyTask(finishedTask);
deleteRbdModal() {
const poolName = this.selection.first().pool_name;
const imageName = this.selection.first().name;
- this.modalRef = this.modalService.show(DeleteConfirmationComponent);
- this.modalRef.content.itemName = `${poolName}/${imageName}`;
- this.modalRef.content.onSubmit.subscribe(() => {
- this.deleteRbd(poolName, imageName);
+ this.modalRef = this.modalService.show(DeletionModalComponent);
+ this.modalRef.content.setUp({
+ metaType: 'RBD',
+ pattern: `${poolName}/${imageName}`,
+ deletionMethod: () => this.deleteRbd(poolName, imageName),
+ modalRef: this.modalRef
});
}
}
import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ToastModule } from 'ng2-toastr';
-import { ModalModule } from 'ngx-bootstrap';
+import { BsModalRef, ModalModule } from 'ngx-bootstrap';
+import { Observable } from 'rxjs/Observable';
import { ApiModule } from '../../../shared/api/api.module';
+import { RbdService } from '../../../shared/api/rbd.service';
import { ComponentsModule } from '../../../shared/components/components.module';
import { DataTableModule } from '../../../shared/datatable/datatable.module';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
+import { NotificationService } from '../../../shared/services/notification.service';
import { ServicesModule } from '../../../shared/services/services.module';
import { RbdSnapshotListComponent } from './rbd-snapshot-list.component';
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ describe('api delete request', () => {
+ let called;
+ let rbdService: RbdService;
+ let notificationService: NotificationService;
+
+ beforeEach(() => {
+ called = false;
+ rbdService = new RbdService(null);
+ notificationService = new NotificationService(null, null);
+ component = new RbdSnapshotListComponent(null, null, null, rbdService, null, null,
+ notificationService);
+ spyOn(rbdService, 'deleteSnapshot').and.returnValue(Observable.throw({status: 500}));
+ spyOn(notificationService, 'notifyTask').and.stub();
+ component.modalRef = new BsModalRef();
+ component.modalRef.content = {
+ stopLoadingSpinner: () => called = true
+ };
+ });
+
+ it('should call stopLoadingSpinner if the request fails', <any>fakeAsync(() => {
+ expect(called).toBe(false);
+ component._asyncTask('deleteSnapshot', 'rbd/snap/delete', 'someName');
+ tick(500);
+ expect(called).toBe(true);
+ }));
+ });
});
RbdService
} from '../../../shared/api/rbd.service';
import {
- DeleteConfirmationComponent
-} from '../../../shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
+ DeletionModalComponent
+} from '../../../shared/components/deletion-modal/deletion-modal.component';
import { CellTemplate } from '../../../shared/enum/cell-template.enum';
import { CdTableColumn } from '../../../shared/models/cd-table-column';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
});
}
- private asyncTask(task: string, taskName: string, snapshotName: string) {
+ _asyncTask(task: string, taskName: string, snapshotName: string) {
const finishedTask = new FinishedTask();
finishedTask.name = taskName;
finishedTask.metadata = {
});
})
.catch((resp) => {
- this.modalRef.hide();
+ this.modalRef.content.stopLoadingSpinner();
finishedTask.success = false;
finishedTask.exception = resp.error;
this.notificationService.notifyTask(finishedTask);
this.modalRef = this.modalService.show(RollbackConfirmationModalComponent);
this.modalRef.content.snapName = `${this.poolName}/${this.rbdName}@${snapshotName}`;
this.modalRef.content.onSubmit.subscribe((itemName: string) => {
- this.asyncTask('rollbackSnapshot', 'rbd/snap/rollback', snapshotName);
+ this._asyncTask('rollbackSnapshot', 'rbd/snap/rollback', snapshotName);
});
}
deleteSnapshotModal() {
const snapshotName = this.selection.selected[0].name;
- this.modalRef = this.modalService.show(DeleteConfirmationComponent);
- this.modalRef.content.itemName = snapshotName;
- this.modalRef.content.onSubmit.subscribe((itemName: string) => {
- this.asyncTask('deleteSnapshot', 'rbd/snap/delete', snapshotName);
+ this.modalRef = this.modalService.show(DeletionModalComponent);
+ this.modalRef.content.setUp({
+ metaType: 'RBD snapshot',
+ pattern: snapshotName,
+ deletionMethod: () => this._asyncTask('deleteSnapshot', 'rbd/snap/delete', snapshotName),
+ modalRef: this.modalRef
});
}
submit() {
this.onSubmit.next(this.snapName);
}
+
+ stopLoadingSpinner() {
+ this.rollbackForm.setErrors({'cdSubmitButton': true});
+ }
}
import { AlertModule, ModalModule, PopoverModule, TooltipModule } from 'ngx-bootstrap';
import { PipesModule } from '../pipes/pipes.module';
-import {
- DeleteConfirmationComponent
-} from './delete-confirmation-modal/delete-confirmation-modal.component';
import { DeletionModalComponent } from './deletion-modal/deletion-modal.component';
import { HelperComponent } from './helper/helper.component';
import { ModalComponent } from './modal/modal.component';
HelperComponent,
SubmitButtonComponent,
UsageBarComponent,
- DeleteConfirmationComponent,
ModalComponent,
DeletionModalComponent
],
- entryComponents: [
- DeletionModalComponent
- ],
providers: [],
exports: [
ViewCacheComponent,
HelperComponent,
SubmitButtonComponent,
UsageBarComponent,
- DeleteConfirmationComponent
],
entryComponents: [
- DeleteConfirmationComponent,
ModalComponent,
DeletionModalComponent
]
+++ /dev/null
-<div class="modal-header">
- <h4 class="modal-title pull-left">Delete</h4>
- <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
- <span aria-hidden="true">×</span>
- </button>
-</div>
-<form name="deleteForm"
- class="form-horizontal"
- #formDir="ngForm"
- [formGroup]="deleteForm"
- novalidate>
- <div class="modal-body">
- Are you sure you want to delete <strong>{{ itemName }}</strong>?
- </div>
- <div class="modal-footer">
- <div class="button-group text-right">
- <cd-submit-button [form]="deleteForm"
- (submitAction)="submit()">
- Delete
- </cd-submit-button>
- <button type="button" class="btn btn-sm btn-default" (click)="modalRef.hide()">Cancel</button>
- </div>
- </div>
-</form>
-
+++ /dev/null
-import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-import { ReactiveFormsModule } from '@angular/forms';
-
-import { ToastModule } from 'ng2-toastr';
-import { BsModalRef, BsModalService } from 'ngx-bootstrap';
-
-import { ApiModule } from '../../../shared/api/api.module';
-import { ServicesModule } from '../../../shared/services/services.module';
-import { SubmitButtonComponent } from '../submit-button/submit-button.component';
-import { DeleteConfirmationComponent } from './delete-confirmation-modal.component';
-
-describe('RbdSnapshotFormComponent', () => {
- let component: DeleteConfirmationComponent;
- let fixture: ComponentFixture<DeleteConfirmationComponent>;
-
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- imports: [
- ReactiveFormsModule,
- HttpClientTestingModule,
- ServicesModule,
- ApiModule,
- ToastModule.forRoot()
- ],
- declarations: [ DeleteConfirmationComponent, SubmitButtonComponent ],
- providers: [ BsModalRef, BsModalService ]
- })
- .compileComponents();
- }));
-
- beforeEach(() => {
- fixture = TestBed.createComponent(DeleteConfirmationComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
+++ /dev/null
-import { Component, OnInit } from '@angular/core';
-import { FormGroup } from '@angular/forms';
-
-import { BsModalRef } from 'ngx-bootstrap';
-import { Subject } from 'rxjs/Subject';
-
-@Component({
- selector: 'cd-delete-confirmation-modal',
- templateUrl: './delete-confirmation-modal.component.html',
- styleUrls: ['./delete-confirmation-modal.component.scss']
-})
-export class DeleteConfirmationComponent implements OnInit {
-
- itemName: string;
-
- deleteForm: FormGroup;
-
- public onSubmit: Subject<string>;
-
- constructor(public modalRef: BsModalRef) {
- this.createForm();
- }
-
- createForm() {
- this.deleteForm = new FormGroup({});
- }
-
- ngOnInit() {
- this.onSubmit = new Subject();
- }
-
- submit() {
- this.onSubmit.next(this.itemName);
- }
-}
} from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
-import { BsModalRef, BsModalService } from 'ngx-bootstrap';
+import { BsModalRef } from 'ngx-bootstrap';
import { Observable } from 'rxjs/Observable';
import { SubmitButtonComponent } from '../submit-button/submit-button.component';
}
stopLoadingSpinner() {
- this.submitButton.loading = false;
+ this.deletionForm.setErrors({'cdSubmitButton': true});
}
}