1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { Component, Input } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
4 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5 import { RouterTestingModule } from '@angular/router/testing';
7 import { ToastrModule } from 'ngx-toastr';
9 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { configureTestBed } from '~/testing/unit-test-helper';
12 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
13 import { CephfsVolumeFormComponent } from '../cephfs-form/cephfs-form.component';
14 import { ModalService } from '~/app/shared/services/modal.service';
15 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
16 import { CephfsListComponent } from './cephfs-list.component';
17 import { CephfsService } from '~/app/shared/api/cephfs.service';
19 @Component({ selector: 'cd-cephfs-tabs', template: '' })
20 class CephfsTabsStubComponent {
22 selection: CdTableSelection;
25 describe('CephfsListComponent', () => {
26 let component: CephfsListComponent;
27 let fixture: ComponentFixture<CephfsListComponent>;
28 let cephfsService: CephfsService;
32 BrowserAnimationsModule,
34 HttpClientTestingModule,
35 ToastrModule.forRoot(),
38 declarations: [CephfsListComponent, CephfsTabsStubComponent, CephfsVolumeFormComponent]
42 fixture = TestBed.createComponent(CephfsListComponent);
43 component = fixture.componentInstance;
44 cephfsService = TestBed.inject(CephfsService);
45 fixture.detectChanges();
48 it('should create', () => {
49 expect(component).toBeTruthy();
52 describe('volume deletion', () => {
53 let taskWrapper: TaskWrapperService;
56 const setSelectedVolume = (volName: string) =>
57 (component.selection.selected = [{ mdsmap: { fs_name: volName } }]);
59 const callDeletion = () => {
60 component.removeVolumeModal();
61 expect(modalRef).toBeTruthy();
62 const deletion: CriticalConfirmationModalComponent = modalRef && modalRef.componentInstance;
63 deletion.submitActionObservable();
66 const testVolumeDeletion = (volName: string) => {
67 setSelectedVolume(volName);
69 expect(cephfsService.remove).toHaveBeenCalledWith(volName);
70 expect(taskWrapper.wrapTaskAroundCall).toHaveBeenCalledWith({
72 name: 'cephfs/remove',
77 call: undefined // because of stub
82 spyOn(TestBed.inject(ModalService), 'show').and.callFake((deletionClass, initialState) => {
84 componentInstance: Object.assign(new deletionClass(), initialState)
88 spyOn(cephfsService, 'remove').and.stub();
89 taskWrapper = TestBed.inject(TaskWrapperService);
90 spyOn(taskWrapper, 'wrapTaskAroundCall').and.callThrough();
93 it('should delete cephfs volume', () => {
94 testVolumeDeletion('somevolumeName');