]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.spec.ts
bump version to 15.2.1-pve1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / nfs / nfs-list / nfs-list.component.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
4
5 import { TabsModule } from 'ngx-bootstrap/tabs';
6 import { ToastrModule } from 'ngx-toastr';
7 import { BehaviorSubject, of } from 'rxjs';
8
9 import {
10 configureTestBed,
11 expectItemTasks,
12 i18nProviders,
13 PermissionHelper
14 } from '../../../../testing/unit-test-helper';
15 import { NfsService } from '../../../shared/api/nfs.service';
16 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
17 import { ExecutingTask } from '../../../shared/models/executing-task';
18 import { SummaryService } from '../../../shared/services/summary.service';
19 import { TaskListService } from '../../../shared/services/task-list.service';
20 import { SharedModule } from '../../../shared/shared.module';
21 import { NfsDetailsComponent } from '../nfs-details/nfs-details.component';
22 import { NfsListComponent } from './nfs-list.component';
23
24 describe('NfsListComponent', () => {
25 let component: NfsListComponent;
26 let fixture: ComponentFixture<NfsListComponent>;
27 let summaryService: SummaryService;
28 let nfsService: NfsService;
29 let httpTesting: HttpTestingController;
30
31 const refresh = (data: object) => {
32 summaryService['summaryDataSource'].next(data);
33 };
34
35 configureTestBed(
36 {
37 declarations: [NfsListComponent, NfsDetailsComponent],
38 imports: [
39 HttpClientTestingModule,
40 RouterTestingModule,
41 SharedModule,
42 ToastrModule.forRoot(),
43 TabsModule.forRoot()
44 ],
45 providers: [TaskListService, i18nProviders]
46 },
47 true
48 );
49
50 beforeEach(() => {
51 fixture = TestBed.createComponent(NfsListComponent);
52 component = fixture.componentInstance;
53 summaryService = TestBed.get(SummaryService);
54 nfsService = TestBed.get(NfsService);
55 httpTesting = TestBed.get(HttpTestingController);
56
57 // this is needed because summaryService isn't being reset after each test.
58 summaryService['summaryDataSource'] = new BehaviorSubject(null);
59 summaryService['summaryData$'] = summaryService['summaryDataSource'].asObservable();
60 });
61
62 it('should create', () => {
63 expect(component).toBeTruthy();
64 });
65
66 describe('after ngOnInit', () => {
67 beforeEach(() => {
68 fixture.detectChanges();
69 spyOn(nfsService, 'list').and.callThrough();
70 httpTesting.expectOne('api/nfs-ganesha/daemon').flush([]);
71 httpTesting.expectOne('api/summary');
72 });
73
74 afterEach(() => {
75 httpTesting.verify();
76 });
77
78 it('should load exports on init', () => {
79 refresh({});
80 httpTesting.expectOne('api/nfs-ganesha/export');
81 expect(nfsService.list).toHaveBeenCalled();
82 });
83
84 it('should not load images on init because no data', () => {
85 refresh(undefined);
86 expect(nfsService.list).not.toHaveBeenCalled();
87 });
88
89 it('should call error function on init when summary service fails', () => {
90 spyOn(component.table, 'reset');
91 summaryService['summaryDataSource'].error(undefined);
92 expect(component.table.reset).toHaveBeenCalled();
93 });
94 });
95
96 describe('handling of executing tasks', () => {
97 let exports: any[];
98
99 const addExport = (export_id: string) => {
100 const model = {
101 export_id: export_id,
102 path: 'path_' + export_id,
103 fsal: 'fsal_' + export_id,
104 cluster_id: 'cluster_' + export_id
105 };
106 exports.push(model);
107 };
108
109 const addTask = (name: string, export_id: string) => {
110 const task = new ExecutingTask();
111 task.name = name;
112 switch (task.name) {
113 case 'nfs/create':
114 task.metadata = {
115 path: 'path_' + export_id,
116 fsal: 'fsal_' + export_id,
117 cluster_id: 'cluster_' + export_id
118 };
119 break;
120 default:
121 task.metadata = {
122 cluster_id: 'cluster_' + export_id,
123 export_id: export_id
124 };
125 break;
126 }
127 summaryService.addRunningTask(task);
128 };
129
130 beforeEach(() => {
131 exports = [];
132 addExport('a');
133 addExport('b');
134 addExport('c');
135 component.exports = exports;
136 refresh({ executing_tasks: [], finished_tasks: [] });
137 spyOn(nfsService, 'list').and.callFake(() => of(exports));
138 fixture.detectChanges();
139
140 const req = httpTesting.expectOne('api/nfs-ganesha/daemon');
141 req.flush([]);
142 });
143
144 it('should gets all exports without tasks', () => {
145 expect(component.exports.length).toBe(3);
146 expect(component.exports.every((expo) => !expo.cdExecuting)).toBeTruthy();
147 });
148
149 it('should add a new export from a task', fakeAsync(() => {
150 addTask('nfs/create', 'd');
151 tick();
152 expect(component.exports.length).toBe(4);
153 expectItemTasks(component.exports[0], undefined);
154 expectItemTasks(component.exports[1], undefined);
155 expectItemTasks(component.exports[2], undefined);
156 expectItemTasks(component.exports[3], 'Creating');
157 }));
158
159 it('should show when an existing export is being modified', () => {
160 addTask('nfs/edit', 'a');
161 addTask('nfs/delete', 'b');
162 expect(component.exports.length).toBe(3);
163 expectItemTasks(component.exports[0], 'Updating');
164 expectItemTasks(component.exports[1], 'Deleting');
165 });
166 });
167
168 it('should test all TableActions combinations', () => {
169 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
170 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
171 component.tableActions
172 );
173
174 expect(tableActions).toEqual({
175 'create,update,delete': {
176 actions: ['Create', 'Edit', 'Delete'],
177 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
178 },
179 'create,update': {
180 actions: ['Create', 'Edit'],
181 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
182 },
183 'create,delete': {
184 actions: ['Create', 'Delete'],
185 primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
186 },
187 create: {
188 actions: ['Create'],
189 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
190 },
191 'update,delete': {
192 actions: ['Edit', 'Delete'],
193 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
194 },
195 update: {
196 actions: ['Edit'],
197 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
198 },
199 delete: {
200 actions: ['Delete'],
201 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
202 },
203 'no-permissions': {
204 actions: [],
205 primary: { multiple: '', executing: '', single: '', no: '' }
206 }
207 });
208 });
209 });