]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.spec.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cephfs / cephfs-list / cephfs-list.component.spec.ts
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';
6
7 import { ToastrModule } from 'ngx-toastr';
8
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';
18
19 @Component({ selector: 'cd-cephfs-tabs', template: '' })
20 class CephfsTabsStubComponent {
21 @Input()
22 selection: CdTableSelection;
23 }
24
25 describe('CephfsListComponent', () => {
26 let component: CephfsListComponent;
27 let fixture: ComponentFixture<CephfsListComponent>;
28 let cephfsService: CephfsService;
29
30 configureTestBed({
31 imports: [
32 BrowserAnimationsModule,
33 SharedModule,
34 HttpClientTestingModule,
35 ToastrModule.forRoot(),
36 RouterTestingModule
37 ],
38 declarations: [CephfsListComponent, CephfsTabsStubComponent, CephfsVolumeFormComponent]
39 });
40
41 beforeEach(() => {
42 fixture = TestBed.createComponent(CephfsListComponent);
43 component = fixture.componentInstance;
44 cephfsService = TestBed.inject(CephfsService);
45 fixture.detectChanges();
46 });
47
48 it('should create', () => {
49 expect(component).toBeTruthy();
50 });
51
52 describe('volume deletion', () => {
53 let taskWrapper: TaskWrapperService;
54 let modalRef: any;
55
56 const setSelectedVolume = (volName: string) =>
57 (component.selection.selected = [{ mdsmap: { fs_name: volName } }]);
58
59 const callDeletion = () => {
60 component.removeVolumeModal();
61 expect(modalRef).toBeTruthy();
62 const deletion: CriticalConfirmationModalComponent = modalRef && modalRef.componentInstance;
63 deletion.submitActionObservable();
64 };
65
66 const testVolumeDeletion = (volName: string) => {
67 setSelectedVolume(volName);
68 callDeletion();
69 expect(cephfsService.remove).toHaveBeenCalledWith(volName);
70 expect(taskWrapper.wrapTaskAroundCall).toHaveBeenCalledWith({
71 task: {
72 name: 'cephfs/remove',
73 metadata: {
74 volumeName: volName
75 }
76 },
77 call: undefined // because of stub
78 });
79 };
80
81 beforeEach(() => {
82 spyOn(TestBed.inject(ModalService), 'show').and.callFake((deletionClass, initialState) => {
83 modalRef = {
84 componentInstance: Object.assign(new deletionClass(), initialState)
85 };
86 return modalRef;
87 });
88 spyOn(cephfsService, 'remove').and.stub();
89 taskWrapper = TestBed.inject(TaskWrapperService);
90 spyOn(taskWrapper, 'wrapTaskAroundCall').and.callThrough();
91 });
92
93 it('should delete cephfs volume', () => {
94 testVolumeDeletion('somevolumeName');
95 });
96 });
97 });