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