1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { RouterTestingModule } from '@angular/router/testing';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
7 import { ToastrModule } from 'ngx-toastr';
8 import { of } from 'rxjs';
15 } from '../../../../testing/unit-test-helper';
16 import { NfsService } from '../../../shared/api/nfs.service';
17 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
18 import { ExecutingTask } from '../../../shared/models/executing-task';
19 import { SummaryService } from '../../../shared/services/summary.service';
20 import { TaskListService } from '../../../shared/services/task-list.service';
21 import { SharedModule } from '../../../shared/shared.module';
22 import { NfsDetailsComponent } from '../nfs-details/nfs-details.component';
23 import { NfsListComponent } from './nfs-list.component';
25 describe('NfsListComponent', () => {
26 let component: NfsListComponent;
27 let fixture: ComponentFixture<NfsListComponent>;
28 let summaryService: SummaryService;
29 let nfsService: NfsService;
30 let httpTesting: HttpTestingController;
32 const refresh = (data: object) => {
33 summaryService['summaryDataSource'].next(data);
38 declarations: [NfsListComponent, NfsDetailsComponent],
40 BrowserAnimationsModule,
41 HttpClientTestingModule,
44 ToastrModule.forRoot(),
47 providers: [TaskListService, i18nProviders]
53 fixture = TestBed.createComponent(NfsListComponent);
54 component = fixture.componentInstance;
55 summaryService = TestBed.get(SummaryService);
56 nfsService = TestBed.get(NfsService);
57 httpTesting = TestBed.get(HttpTestingController);
60 it('should create', () => {
61 expect(component).toBeTruthy();
64 describe('after ngOnInit', () => {
66 fixture.detectChanges();
67 spyOn(nfsService, 'list').and.callThrough();
68 httpTesting.expectOne('api/nfs-ganesha/daemon').flush([]);
75 it('should load exports on init', () => {
77 httpTesting.expectOne('api/nfs-ganesha/export');
78 expect(nfsService.list).toHaveBeenCalled();
81 it('should not load images on init because no data', () => {
83 expect(nfsService.list).not.toHaveBeenCalled();
86 it('should call error function on init when summary service fails', () => {
87 spyOn(component.table, 'reset');
88 summaryService['summaryDataSource'].error(undefined);
89 expect(component.table.reset).toHaveBeenCalled();
93 describe('handling of executing tasks', () => {
96 const addExport = (export_id: string) => {
99 path: 'path_' + export_id,
100 fsal: 'fsal_' + export_id,
101 cluster_id: 'cluster_' + export_id
106 const addTask = (name: string, export_id: string) => {
107 const task = new ExecutingTask();
112 path: 'path_' + export_id,
113 fsal: 'fsal_' + export_id,
114 cluster_id: 'cluster_' + export_id
119 cluster_id: 'cluster_' + export_id,
124 summaryService.addRunningTask(task);
132 component.exports = exports;
133 refresh({ executing_tasks: [], finished_tasks: [] });
134 spyOn(nfsService, 'list').and.callFake(() => of(exports));
135 fixture.detectChanges();
137 const req = httpTesting.expectOne('api/nfs-ganesha/daemon');
141 it('should gets all exports without tasks', () => {
142 expect(component.exports.length).toBe(3);
143 expect(component.exports.every((expo) => !expo.cdExecuting)).toBeTruthy();
146 it('should add a new export from a task', fakeAsync(() => {
147 addTask('nfs/create', 'd');
149 expect(component.exports.length).toBe(4);
150 expectItemTasks(component.exports[0], undefined);
151 expectItemTasks(component.exports[1], undefined);
152 expectItemTasks(component.exports[2], undefined);
153 expectItemTasks(component.exports[3], 'Creating');
156 it('should show when an existing export is being modified', () => {
157 addTask('nfs/edit', 'a');
158 addTask('nfs/delete', 'b');
159 expect(component.exports.length).toBe(3);
160 expectItemTasks(component.exports[0], 'Updating');
161 expectItemTasks(component.exports[1], 'Deleting');
165 it('should test all TableActions combinations', () => {
166 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
167 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
168 component.tableActions
171 expect(tableActions).toEqual({
172 'create,update,delete': {
173 actions: ['Create', 'Edit', 'Delete'],
174 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
177 actions: ['Create', 'Edit'],
178 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
181 actions: ['Create', 'Delete'],
182 primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
186 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
189 actions: ['Edit', 'Delete'],
190 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
194 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
198 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
202 primary: { multiple: '', executing: '', single: '', no: '' }